diff options
Diffstat (limited to 'NativeApp/src/Android/AndroidAppBase.cpp')
| -rw-r--r-- | NativeApp/src/Android/AndroidAppBase.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/NativeApp/src/Android/AndroidAppBase.cpp b/NativeApp/src/Android/AndroidAppBase.cpp index bc79470..3af8116 100644 --- a/NativeApp/src/Android/AndroidAppBase.cpp +++ b/NativeApp/src/Android/AndroidAppBase.cpp @@ -72,12 +72,6 @@ void AndroidAppBase::InitSensors() // void AndroidAppBase::DrawFrame() { - // APP_CMD_CONFIG_CHANGED event is generated seveal frames - // before the screen is actually resized. The only robust way - // to detect window resize is to check it very frame - if (CheckWindowSizeChanged()) - WindowResize(window_width_, window_height_); - float fFPS; if (monitor_.Update(fFPS)) { @@ -135,11 +129,34 @@ void AndroidAppBase::HandleCmd(struct android_app* app, int32_t cmd) break; case APP_CMD_CONFIG_CHANGED: + { + // This callback is not reliable for handling orientation changes. Depending on the + // device, it may be called before or after the surface has been actually resized. + break; + } + + // Note that as of NDK r21b (21.1.6352462), APP_CMD_WINDOW_RESIZED event is never generated + // by android_native_app_glue. + // Also note that modifying android_native_app_glue to handle onNativeWindowResized + // callback (as suggested in https://android-developers.googleblog.com/2020/02/handling-device-orientation-efficiently.html) + // does not work either - the callback is only called once after the window has been created. case APP_CMD_WINDOW_RESIZED: - // This does not work as the screen resizes few frames - // after the event has been received - // eng->WindowResize(0,0); + { + auto new_window_width = ANativeWindow_getWidth(app->window); + auto new_window_height = ANativeWindow_getHeight(app->window); + eng->WindowResize(new_window_width, new_window_height); break; + } + + // Note that as of NDK r21b (21.1.6352462), APP_CMD_CONTENT_RECT_CHANGED event is never + // generated by android_native_app_glue + case APP_CMD_CONTENT_RECT_CHANGED: + { + auto new_window_width = app->contentRect.right - app->contentRect.left; + auto new_window_height = app->contentRect.bottom - app->contentRect.top; + eng->WindowResize(new_window_width, new_window_height); + break; + } case APP_CMD_TERM_WINDOW: // The window is being hidden or closed, clean it up. |
