Fill in the video mode with the correct screen format
This commit is contained in:
parent
a410db1ae6
commit
25101525df
4 changed files with 120 additions and 104 deletions
|
@ -99,13 +99,9 @@ public class SDLActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// C functions we call
|
// C functions we call
|
||||||
public static native void nativeInit();
|
public static native void nativeInit();
|
||||||
public static native void nativeQuit();
|
public static native void nativeQuit();
|
||||||
public static native void nativeSetScreenSize(int width, int height);
|
|
||||||
public static native void onNativeKeyDown(int keycode);
|
public static native void onNativeKeyDown(int keycode);
|
||||||
public static native void onNativeKeyUp(int keycode);
|
public static native void onNativeKeyUp(int keycode);
|
||||||
public static native void onNativeTouch(int action, float x,
|
public static native void onNativeTouch(int action, float x,
|
||||||
|
@ -114,7 +110,6 @@ public class SDLActivity extends Activity {
|
||||||
public static native void onNativeAccel(float x, float y, float z);
|
public static native void onNativeAccel(float x, float y, float z);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Java functions called from C
|
//Java functions called from C
|
||||||
private static void createGLContext() {
|
private static void createGLContext() {
|
||||||
mSurface.initEGL();
|
mSurface.initEGL();
|
||||||
|
@ -164,10 +159,8 @@ public class SDLActivity extends Activity {
|
||||||
/**
|
/**
|
||||||
Simple nativeInit() runnable
|
Simple nativeInit() runnable
|
||||||
*/
|
*/
|
||||||
class SDLRunner implements Runnable{
|
class SDLMain implements Runnable {
|
||||||
public void run() {
|
public void run() {
|
||||||
//SDLActivity.initAudio();
|
|
||||||
|
|
||||||
// Runs SDL_main()
|
// Runs SDL_main()
|
||||||
SDLActivity.nativeInit();
|
SDLActivity.nativeInit();
|
||||||
|
|
||||||
|
@ -212,40 +205,77 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
|
|
||||||
// Called when we have a valid drawing surface
|
// Called when we have a valid drawing surface
|
||||||
public void surfaceCreated(SurfaceHolder holder) {
|
public void surfaceCreated(SurfaceHolder holder) {
|
||||||
Log.v("SDL","Surface created");
|
|
||||||
|
|
||||||
int width = getWidth();
|
|
||||||
int height = getHeight();
|
|
||||||
|
|
||||||
//Set the width and height variables in C before we start SDL so we have
|
|
||||||
//it available on init
|
|
||||||
SDLActivity.nativeSetScreenSize(width, height);
|
|
||||||
|
|
||||||
//Now start up the C app thread
|
|
||||||
mSDLThread = new Thread(new SDLRunner(), "SDLThread");
|
|
||||||
mSDLThread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when we lose the surface
|
// Called when we lose the surface
|
||||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||||
Log.v("SDL","Surface destroyed");
|
|
||||||
|
|
||||||
|
// Send a quit message to the application
|
||||||
SDLActivity.nativeQuit();
|
SDLActivity.nativeQuit();
|
||||||
|
|
||||||
// Now wait for the SDL thread to quit
|
// Now wait for the SDL thread to quit
|
||||||
|
if (mSDLThread != null) {
|
||||||
try {
|
try {
|
||||||
mSDLThread.wait();
|
mSDLThread.wait();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.v("SDL","Problem stopping thread: " + e);
|
Log.v("SDL","Problem stopping thread: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Called when the surface is resized
|
// Called when the surface is resized
|
||||||
public void surfaceChanged(SurfaceHolder holder, int format,
|
public void surfaceChanged(SurfaceHolder holder,
|
||||||
int width, int height) {
|
int format, int width, int height) {
|
||||||
Log.v("SDL","Surface resized");
|
Log.v("SDL","Surface resized");
|
||||||
|
|
||||||
|
int sdlFormat = 0;
|
||||||
|
switch (format) {
|
||||||
|
case PixelFormat.A_8:
|
||||||
|
Log.v("SDL","pixel format A_8");
|
||||||
|
break;
|
||||||
|
case PixelFormat.LA_88:
|
||||||
|
Log.v("SDL","pixel format LA_88");
|
||||||
|
break;
|
||||||
|
case PixelFormat.L_8:
|
||||||
|
Log.v("SDL","pixel format L_8");
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGBA_4444:
|
||||||
|
Log.v("SDL","pixel format RGBA_4444");
|
||||||
|
sdlFormat = 0x85421002; // Doesn't have an SDL constant...
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGBA_5551:
|
||||||
|
Log.v("SDL","pixel format RGBA_5551");
|
||||||
|
sdlFormat = 0x85441002; // Doesn't have an SDL constant...
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGBA_8888:
|
||||||
|
Log.v("SDL","pixel format RGBA_8888");
|
||||||
|
sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGBX_8888:
|
||||||
|
Log.v("SDL","pixel format RGBX_8888");
|
||||||
|
sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGB_332:
|
||||||
|
Log.v("SDL","pixel format RGB_332");
|
||||||
|
sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGB_565:
|
||||||
|
Log.v("SDL","pixel format RGB_565");
|
||||||
|
sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565
|
||||||
|
break;
|
||||||
|
case PixelFormat.RGB_888:
|
||||||
|
Log.v("SDL","pixel format RGB_888");
|
||||||
|
// Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
|
||||||
|
sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888
|
||||||
|
break;
|
||||||
|
}
|
||||||
SDLActivity.onNativeResize(width, height, format);
|
SDLActivity.onNativeResize(width, height, format);
|
||||||
|
|
||||||
|
// Now start up the C app thread
|
||||||
|
if (mSDLThread == null) {
|
||||||
|
mSDLThread = new Thread(new SDLMain(), "SDLThread");
|
||||||
|
mSDLThread.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//unused
|
//unused
|
||||||
|
@ -284,14 +314,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
mEGLDisplay = dpy;
|
mEGLDisplay = dpy;
|
||||||
mEGLSurface = surface;
|
mEGLSurface = surface;
|
||||||
|
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.v("SDL", e + "");
|
Log.v("SDL", e + "");
|
||||||
for(StackTraceElement s : e.getStackTrace()){
|
for(StackTraceElement s : e.getStackTrace()){
|
||||||
Log.v("SDL", s.toString());
|
Log.v("SDL", s.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.v("SDL","Done making!");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -299,7 +327,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
// EGL buffer flip
|
// EGL buffer flip
|
||||||
public void flipEGL() {
|
public void flipEGL() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
EGL10 egl = (EGL10)EGLContext.getEGL();
|
EGL10 egl = (EGL10)EGLContext.getEGL();
|
||||||
GL10 gl = (GL10)mEGLContext.getGL();
|
GL10 gl = (GL10)mEGLContext.getGL();
|
||||||
|
|
||||||
|
@ -314,15 +341,12 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.v("SDL", "flipEGL(): " + e);
|
Log.v("SDL", "flipEGL(): " + e);
|
||||||
|
|
||||||
for(StackTraceElement s : e.getStackTrace()){
|
for(StackTraceElement s : e.getStackTrace()){
|
||||||
Log.v("SDL", s.toString());
|
Log.v("SDL", s.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Key events
|
// Key events
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event){
|
public boolean onKey(View v, int keyCode, KeyEvent event){
|
||||||
|
|
||||||
|
@ -330,7 +354,6 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
SDLActivity.onNativeKeyDown(keyCode);
|
SDLActivity.onNativeKeyDown(keyCode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (event.getAction() == KeyEvent.ACTION_UP) {
|
else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
SDLActivity.onNativeKeyUp(keyCode);
|
SDLActivity.onNativeKeyUp(keyCode);
|
||||||
return true;
|
return true;
|
||||||
|
@ -377,7 +400,5 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "events/SDL_events_c.h"
|
#include "events/SDL_events_c.h"
|
||||||
#include "video/android/SDL_androidkeyboard.h"
|
#include "video/android/SDL_androidkeyboard.h"
|
||||||
|
#include "video/android/SDL_androidvideo.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
@ -49,9 +50,6 @@ jmethodID midFlipBuffers;
|
||||||
jmethodID midEnableFeature;
|
jmethodID midEnableFeature;
|
||||||
jmethodID midUpdateAudio;
|
jmethodID midUpdateAudio;
|
||||||
|
|
||||||
extern "C" void Android_SetScreenResolution(int width, int height);
|
|
||||||
extern "C" int SDL_SendQuit();
|
|
||||||
|
|
||||||
//If we're not the active app, don't try to render
|
//If we're not the active app, don't try to render
|
||||||
bool bRenderingEnabled = false;
|
bool bRenderingEnabled = false;
|
||||||
|
|
||||||
|
@ -145,21 +143,12 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeQuit( JNIEnv* env,
|
||||||
SDL_SendQuit();
|
SDL_SendQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Screen size
|
|
||||||
extern "C" void Java_org_libsdl_app_SDLActivity_nativeSetScreenSize(
|
|
||||||
JNIEnv* env, jobject obj, jint width, jint height)
|
|
||||||
{
|
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL",
|
|
||||||
"SDL: Set screen size on init: %d/%d\n", width, height);
|
|
||||||
Android_SetScreenResolution(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resize
|
// Resize
|
||||||
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
|
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeResize(
|
||||||
JNIEnv* env, jobject obj, jint width,
|
JNIEnv* env, jobject obj, jint width,
|
||||||
jint height, jint format)
|
jint height, jint format)
|
||||||
{
|
{
|
||||||
/* FIXME: What is the relationship between this and the window? */
|
Android_SetScreenResolution(width, height, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
|
extern "C" void Java_org_libsdl_app_SDLActivity_onNativeAccel(
|
||||||
|
@ -229,3 +218,5 @@ extern "C" void Android_UpdateAudioBuffer(unsigned char *buf, int len)
|
||||||
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n");
|
__android_log_print(ANDROID_LOG_INFO, "SDL", "SDL: invoked\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -57,9 +57,10 @@ extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
|
||||||
|
|
||||||
|
|
||||||
// These are filled in with real values in Android_SetScreenResolution on
|
// These are filled in with real values in Android_SetScreenResolution on
|
||||||
//init (before SDL_Main())
|
// init (before SDL_main())
|
||||||
static int iScreenWidth = 320;
|
static Uint32 iScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
|
||||||
static int iScreenHeight = 240;
|
static int iScreenWidth = 0;
|
||||||
|
static int iScreenHeight = 0;
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -122,8 +123,7 @@ Android_VideoInit(_THIS)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
|
|
||||||
/* Use a fake 32-bpp desktop mode */
|
mode.format = iScreenFormat;
|
||||||
mode.format = SDL_PIXELFORMAT_BGR888;
|
|
||||||
mode.w = iScreenWidth;
|
mode.w = iScreenWidth;
|
||||||
mode.h = iScreenHeight;
|
mode.h = iScreenHeight;
|
||||||
mode.refresh_rate = 0;
|
mode.refresh_rate = 0;
|
||||||
|
@ -146,11 +146,12 @@ Android_VideoQuit(_THIS)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
void Android_SetScreenResolution(int width, int height){
|
Android_SetScreenResolution(int width, int height, Uint32 format)
|
||||||
|
{
|
||||||
iScreenWidth = width;
|
iScreenWidth = width;
|
||||||
iScreenHeight = height;
|
iScreenHeight = height;
|
||||||
|
iScreenFormat = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
|
|
||||||
#include "../SDL_sysvideo.h"
|
#include "../SDL_sysvideo.h"
|
||||||
|
|
||||||
#endif /* _SDL_ndsvideo_h */
|
/* Called by the JNI layer when the screen changes size or format */
|
||||||
|
extern void Android_SetScreenResolution(int width, int height, Uint32 format);
|
||||||
|
|
||||||
|
#endif /* _SDL_androidvideo_h */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue