diff --git a/project/java/GLSurfaceView_SDL.java b/project/java/GLSurfaceView_SDL.java index d53a90f2c..9a1df2a74 100644 --- a/project/java/GLSurfaceView_SDL.java +++ b/project/java/GLSurfaceView_SDL.java @@ -517,6 +517,8 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call */ public static interface SwapBuffersCallback { public boolean SwapBuffers(); + public void ResetVideoSurface(); + public void onWindowResize(int width, int height); } public static abstract class Renderer { @@ -574,7 +576,11 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call public abstract void onSurfaceChanged(GL10 gl, int width, int height); /** Called when screen size changes */ - public abstract void onWindowResize(int width, int height); + public void onWindowResize(int width, int height) + { + if( mSwapBuffersCallback != null ) + mSwapBuffersCallback.onWindowResize(width, height); + } /** * Called to draw the current frame. @@ -598,6 +604,11 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call return mSwapBuffersCallback.SwapBuffers(); return false; } + + public void ResetVideoSurface() { + if( mSwapBuffersCallback != null ) + mSwapBuffersCallback.ResetVideoSurface(); + } public void setSwapBuffersCallback( SwapBuffersCallback c ) { mSwapBuffersCallback = c; @@ -1029,30 +1040,21 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call sEglSemaphore.release(); } + /* You need to call SwapBuffers() after this function */ + public void ResetVideoSurface() { + mResetVideoSurface = true; + } + public boolean SwapBuffers() { boolean tellRendererSurfaceCreated = false; boolean tellRendererSurfaceChanged = false; - /* - * This is our main activity thread's loop, we go until - * asked to quit. - */ - - /* - * Update the asynchronous state (window size) - */ - while(true) { // Loop until we're re-created GL context and successfully called swap() + while(true) { // Loop until we're re-created GL context and successfully called swap() int w, h; boolean changed = false; synchronized (this) { - /* - Runnable r; - while ((r = getEvent()) != null) { - r.run(); - } - */ if (mPaused) { mRenderer.onSurfaceDestroyed(); mEglHelper.finish(); @@ -1106,15 +1108,16 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call * Once we're done with GL, we need to call swapBuffers() * to instruct the system to display the rendered frame */ - if( mEglHelper.swap() ) + if( !mResetVideoSurface && mEglHelper.swap() ) return true; // We've lost GL context - recreate it + mResetVideoSurface = false; mRenderer.onSurfaceDestroyed(); mEglHelper.finish(); mNeedStart = true; if( Globals.NonBlockingSwapBuffers ) return false; - } + } } private boolean needToWait() { @@ -1254,6 +1257,7 @@ public class GLSurfaceView_SDL extends SurfaceView implements SurfaceHolder.Call private EglHelper mEglHelper; private GL10 mGL = null; private boolean mNeedStart = false; + private boolean mResetVideoSurface = false; } static class LogWriter extends Writer { diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 99ce8fe3c..39aed6468 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -1282,7 +1282,10 @@ public class MainActivity extends Activity Globals.AutoDetectOrientation = true; if( Globals.AutoDetectOrientation ) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); + if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2 ) + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER); + else + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER); return; } if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD ) diff --git a/project/java/Video.java b/project/java/Video.java index 53115008c..5d374cf2c 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -615,7 +615,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer { public void run() { - // Samsung multiwindow will swap screen dimensionswhen unlocking the lockscreen, sleep a while so we won't use these temporary values + // Samsung multiwindow will swap screen dimensions when unlocking the lockscreen, sleep a while so we won't use these temporary values try{ Thread.sleep(2000); } catch (InterruptedException e) {} @@ -627,29 +627,33 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer ww = topView.getWidth() - topView.getWidth() % 2; hh = topView.getHeight() - topView.getHeight() % 2; } - if (mWidth != 0 && mHeight != 0 && ( - Math.abs(mWidth - ww) > mWidth / 10 || - Math.abs(mHeight - hh) > mHeight / 10)) + + Display display = context.getWindowManager().getDefaultDisplay(); + + if (mWidth != 0 && mHeight != 0 && (mWidth != ww || mHeight != hh)) { - Log.w("SDL", "libSDL: DemoRenderer.onWindowResize(): screen size changed from " + mWidth + "x" + mHeight + " to " + ww + "x" + hh + " - restarting application"); - Intent intent = new Intent(context, RestartMainActivity.class); - intent.putExtra(RestartMainActivity.ACTIVITY_AUTODETECT_SCREEN_ORIENTATION, true); - context.startActivity(intent); - try{ - Thread.sleep(1000); - } catch (InterruptedException e) {} - System.exit(0); + Log.w("SDL", "libSDL: DemoRenderer.onWindowResize(): screen size changed from " + mWidth + "x" + mHeight + " to " + ww + "x" + hh); + if (Globals.SwVideoMode && + (Math.abs(display.getWidth() - ww) > display.getWidth() / 10 || + Math.abs(display.getHeight() - hh) > display.getHeight() / 10)) + { + Log.i("SDL", "Multiwindow detected - enabling screen orientation autodetection"); + Globals.AutoDetectOrientation = true; + context.setScreenOrientation(); + DemoRenderer.super.ResetVideoSurface(); + DemoRenderer.super.onWindowResize(ww, hh); + } } if (mWidth == 0 && mHeight == 0) { - Display getOrient = context.getWindowManager().getDefaultDisplay(); - if ((ww > hh) != (getOrient.getWidth() > getOrient.getHeight())) + if ((ww > hh) != (display.getWidth() > display.getHeight())) { - Log.i("SDL", "Multiwindow detected - app window size " + ww + "x" + hh + " but display dimensions are " + getOrient.getWidth() + "x" + getOrient.getHeight()); + Log.i("SDL", "Multiwindow detected - app window size " + ww + "x" + hh + " but display dimensions are " + display.getWidth() + "x" + display.getHeight()); Globals.AutoDetectOrientation = true; - Globals.HorizontalOrientation = (ww > hh); } } + if (Globals.AutoDetectOrientation && (ww > hh) != (mWidth > mHeight)) + Globals.HorizontalOrientation = (ww > hh); } }).start(); } @@ -665,7 +669,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer public void onDrawFrame(GL10 gl) { mGl = gl; - DrawLogo(mGl); SwapBuffers(); nativeInitJavaCallbacks(); @@ -715,7 +718,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer if(mGlContextLost) { mGlContextLost = false; Settings.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics - DrawLogo(mGl); super.SwapBuffers(); } @@ -912,62 +914,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer value <<= 1; return value; } - public void DrawLogo(GL10 gl) - { - /* - // TODO: this not quite works, as it seems - BitmapDrawable bmp = null; - try - { - bmp = new BitmapDrawable(context.getAssets().open("logo.png")); - } - catch(Exception e) - { - bmp = new BitmapDrawable(context.getResources().openRawResource(R.drawable.publisherlogo)); - } - int width = bmp.getBitmap().getWidth(); - int height = bmp.getBitmap().getHeight(); - ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * width * height); - //byteBuffer.order(ByteOrder.BIG_ENDIAN); - bmp.getBitmap().copyPixelsToBuffer(byteBuffer); - byteBuffer.position(0); - - gl.glViewport(0, 0, mWidth, mHeight); - gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); - gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000); - gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1); - gl.glEnable(GL10.GL_TEXTURE_2D); - int textureName = -1; - int mTextureNameWorkspace[] = new int[1]; - int mCropWorkspace[] = new int[4]; - gl.glGenTextures(1, mTextureNameWorkspace, 0); - textureName = mTextureNameWorkspace[0]; - gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName); - gl.glActiveTexture(textureName); - gl.glClientActiveTexture(textureName); - gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, - PowerOf2(width), PowerOf2(height), 0, - GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, null); - gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, - width, height, - GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, byteBuffer); - mCropWorkspace[0] = 0; // u - mCropWorkspace[1] = height; // v - mCropWorkspace[2] = width; - mCropWorkspace[3] = -height; - ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, - GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCropWorkspace, 0); - ((GL11Ext) gl).glDrawTexiOES(0, -mHeight, 0, mWidth, mHeight); - gl.glActiveTexture(0); - gl.glClientActiveTexture(0); - gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); - gl.glDeleteTextures(1, mTextureNameWorkspace, 0); - - gl.glFlush(); - */ - } - private native void nativeInitJavaCallbacks(); private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo, int isDebuggerConnected); diff --git a/project/jni/application/ballfield/AndroidAppSettings.cfg b/project/jni/application/ballfield/AndroidAppSettings.cfg index cf9d10beb..320b22670 100644 --- a/project/jni/application/ballfield/AndroidAppSettings.cfg +++ b/project/jni/application/ballfield/AndroidAppSettings.cfg @@ -230,7 +230,7 @@ CustomBuildScript=n AppCflags='-O2 -finline-functions' # Additional LDFLAGS for application -AppLdflags='' +AppLdflags='-fuse-ld=bfd' # Hack, because NDK seems to be bugged # If application has headers with the same name as system headers, this option tries to fix compiler flags to make it compilable AppOverlapsSystemHeaders= diff --git a/project/jni/application/ballfield/ballfield.cpp b/project/jni/application/ballfield/ballfield.cpp index d4feed749..93dc65f7a 100644 --- a/project/jni/application/ballfield/ballfield.cpp +++ b/project/jni/application/ballfield/ballfield.cpp @@ -688,7 +688,10 @@ int main(int argc, char* argv[]) if(evt.key.keysym.sym == SDLK_1) SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 0); if(evt.key.keysym.sym == SDLK_2) + { SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, 1); + screen = SDL_SetVideoMode(SCREEN_W, SDL_GetVideoSurface()->h + 1, bpp, flags); + } if(evt.key.keysym.sym == SDLK_3) SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, 0); if(evt.key.keysym.sym == SDLK_4) diff --git a/project/jni/application/hid-pc-keyboard/src b/project/jni/application/hid-pc-keyboard/src index 6d7ed5237..ee98efcb3 160000 --- a/project/jni/application/hid-pc-keyboard/src +++ b/project/jni/application/hid-pc-keyboard/src @@ -1 +1 @@ -Subproject commit 6d7ed5237ec4535d0267ea2514c68056b410775b +Subproject commit ee98efcb3405d21757eb740ab460bff432c8751e diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c index 446130224..bcba32cea 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo-1.2.c @@ -449,6 +449,8 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, SDL_ANDROID_ForceClearScreenRect[3].h = window.y; SDL_SelectVideoDisplay(0); + if (SDL_VideoWindow) + SDL_DestroyWindow(SDL_VideoWindow); SDL_VideoWindow = SDL_CreateWindow("", window.x, window.y, window.w, window.h, SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL); SDL_memset(&mode, 0, sizeof(mode)); @@ -524,6 +526,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current, */ void ANDROID_VideoQuit(_THIS) { + // TODO: this function crashes SDL __android_log_print(ANDROID_LOG_INFO, "libSDL", "Calling VideoQuit()"); if( !SDL_ANDROID_InsideVideoThread() ) { @@ -1172,8 +1175,11 @@ void SDL_ANDROID_VideoContextLost() } }; +extern DECLSPEC int SDL_ANDROID_ScreenKeyboardUpdateToNewVideoMode(int oldx, int oldy, int newx, int newy); + void SDL_ANDROID_VideoContextRecreated() { + int i; __android_log_print(ANDROID_LOG_INFO, "libSDL", "Sending SDL_VIDEORESIZE event %dx%d", SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight); //SDL_PrivateResize(SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight); if ( SDL_ProcessEvents[SDL_VIDEORESIZE] == SDL_ENABLE ) { @@ -1186,9 +1192,15 @@ void SDL_ANDROID_VideoContextRecreated() } } + SDL_ANDROID_ScreenKeyboardUpdateToNewVideoMode(SDL_modelist[0]->w, SDL_modelist[0]->h, SDL_ANDROID_sWindowWidth, SDL_ANDROID_sWindowHeight); + + SDL_modelist[0]->w = SDL_ANDROID_sWindowWidth; + SDL_modelist[0]->h = SDL_ANDROID_sWindowHeight; + if( ! sdl_opengl ) { - int i; + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "Setting display dimensions to %dx%d", SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight); + SDL_PrivateAndroidSetDesktopMode(SDL_VideoWindow, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight); SDL_SelectRenderer(SDL_VideoWindow); // Re-apply glOrtho() and blend modes // Re-apply our custom 4:3 screen aspect ratio glViewport(0, 0, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c index 0f94915a1..82edb2441 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_androidvideo.c @@ -177,17 +177,14 @@ int SDL_ANDROID_CallJavaSwapBuffers() JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoRenderer_nativeResize) ( JNIEnv* env, jobject thiz, jint w, jint h, jint keepRatio ) { - if( SDL_ANDROID_sRealWindowWidth == 0 ) - { - SDL_ANDROID_sRealWindowWidth = w; - SDL_ANDROID_sRealWindowHeight = h; - SDL_ANDROID_sWindowWidth = w; - SDL_ANDROID_sWindowHeight = h; - SDL_ANDROID_TouchscreenCalibrationWidth = SDL_ANDROID_sWindowWidth; - SDL_ANDROID_TouchscreenCalibrationHeight = SDL_ANDROID_sWindowHeight; - SDL_ANDROID_ScreenKeep43Ratio = keepRatio; - __android_log_print(ANDROID_LOG_INFO, "libSDL", "Physical screen resolution is %dx%d", w, h ); - } + SDL_ANDROID_sRealWindowWidth = w; + SDL_ANDROID_sRealWindowHeight = h; + SDL_ANDROID_sWindowWidth = w; + SDL_ANDROID_sWindowHeight = h; + SDL_ANDROID_TouchscreenCalibrationWidth = SDL_ANDROID_sWindowWidth; + SDL_ANDROID_TouchscreenCalibrationHeight = SDL_ANDROID_sWindowHeight; + SDL_ANDROID_ScreenKeep43Ratio = keepRatio; + __android_log_print(ANDROID_LOG_INFO, "libSDL", "Physical screen resolution is %dx%d", w, h ); } JNIEXPORT void JNICALL diff --git a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c index 572201f1d..c0a2b70ff 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c @@ -1198,6 +1198,20 @@ extern DECLSPEC int SDLCALL SDL_ANDROID_SetScreenKeyboardFloatingJoystick(int en return 1; } +extern DECLSPEC int SDL_ANDROID_ScreenKeyboardUpdateToNewVideoMode(int oldx, int oldy, int newx, int newy) +{ + int i; + for( i = 0; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM; i++ ) + { + SDL_Rect pos, pos2; + SDL_ANDROID_GetScreenKeyboardButtonPos(i, &pos); + pos2.x = pos.x * newx / oldx; + pos2.y = pos.y * newy / oldy; + pos2.w = (pos.x + pos.w) * newx / oldx - pos2.x; + pos2.h = (pos.y + pos.h) * newy / oldy - pos2.y; + SDL_ANDROID_SetScreenKeyboardButtonPos(i, &pos2); + } +} /** * @brief Dumps OpenGL state for debugging - typically every capability set with glEnable(). diff --git a/project/jni/sdl-1.2/src/video/android/SDL_video-1.3.h b/project/jni/sdl-1.2/src/video/android/SDL_video-1.3.h index 3024138e4..c63a30b61 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_video-1.3.h +++ b/project/jni/sdl-1.2/src/video/android/SDL_video-1.3.h @@ -1421,6 +1421,9 @@ extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window * window); */ extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context); +/** Private function exported to SDL 1.2 */ +void SDL_PrivateAndroidSetDesktopMode(SDL_Window * window, int w, int h); + /*@}*//*OpenGL support functions*/ diff --git a/project/jni/sdl-1.2/src/video/android/SDL_video.c b/project/jni/sdl-1.2/src/video/android/SDL_video.c index 51191f091..1b81368da 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_video.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_video.c @@ -1193,6 +1193,8 @@ SDL_GetWindowData(SDL_Window * window) return window->userdata; } +#endif + void SDL_SetWindowPosition(SDL_Window * window, int x, int y) { @@ -1207,7 +1209,9 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y) if (_this->SetWindowPosition) { _this->SetWindowPosition(_this, window); } +#if SDL_VERSION_ATLEAST(1,3,0) SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y); +#endif } void @@ -1234,7 +1238,9 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h) if (_this->SetWindowSize) { _this->SetWindowSize(_this, window); } +#if SDL_VERSION_ATLEAST(1,3,0) SDL_OnWindowResized(window); +#endif } void @@ -1257,6 +1263,8 @@ SDL_GetWindowSize(SDL_Window * window, int *w, int *h) } } +#if SDL_VERSION_ATLEAST(1,3,0) + void SDL_ShowWindow(SDL_Window * window) { @@ -3686,4 +3694,10 @@ SDL_SetTextInputRect(SDL_Rect *rect) } #endif +void SDL_PrivateAndroidSetDesktopMode(SDL_Window * window, int w, int h) +{ + window->display->desktop_mode.w = w; + window->display->desktop_mode.h = h; +} + /* vi: set ts=4 sw=4 expandtab: */