git.s-ol.nu ~forks/DiligentTools / 4a2a45d
Updated Android native app to better handle orientation changes assiduous 1 year, 1 month ago
3 changed file(s) with 32 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
307307 // 0__|_____|____________________ 0__|________|_______|/
308308 // | | ' | | | ' |
309309 // a.y | | ' | a.x | | ' |
310 // _V_|_ _ _a____b | min_y _V_|_ _d'___a' |
310 // _V_|_ _ _a____b | _V_|_ _d'___a' |
311311 // A | | | | | | | |
312312 // DsplSz.y | | |____| | | |____| |
313313 // -a.y | | d c | | c' b' |
401401 UNEXPECTED("Unknown transform");
402402 return rect;
403403 }
404 };
404 }
405405
406406 void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData* pDrawData)
407407 {
4141 void SetState(android_app* state, const char* native_activity_class_name);
4242 void InitSensors();
4343 void ProcessSensors(int32_t id);
44 void DrawFrame();
44 virtual void DrawFrame();
4545 bool IsReady();
4646 virtual void TrimMemory() = 0;
4747 virtual void TermDisplay() = 0;
4848 static int32_t HandleInput(android_app* app, AInputEvent* event);
4949 static void HandleCmd(android_app* app, int32_t cmd);
5050
51 bool CheckWindowSizeChanged()
52 {
53 auto new_window_width = ANativeWindow_getWidth(app_->window);
54 auto new_window_height = ANativeWindow_getHeight(app_->window);
55 if (new_window_width != window_width_ || new_window_height != window_height_)
56 {
57 window_width_ = new_window_width;
58 window_height_ = new_window_height;
59 return true;
60 }
61 else
62 return false;
63 }
64
6551 protected:
6652 virtual void Initialize()
6753 {
68 CheckWindowSizeChanged();
6954 }
7055
7156 virtual int Resume(ANativeWindow* window) = 0;
9984 void ShowUI();
10085 void UpdateFPS(float fFPS);
10186
102 bool initialized_resources_ = false;
103 bool has_focus_ = false;
104 int32_t window_width_ = 0;
105 int32_t window_height_ = 0;
87 bool initialized_resources_ = false;
88 bool has_focus_ = false;
10689
10790 ASensorManager* sensor_manager_ = nullptr;
10891 const ASensor* accelerometer_sensor_ = nullptr;
7171 //
7272 void AndroidAppBase::DrawFrame()
7373 {
74 // APP_CMD_CONFIG_CHANGED event is generated seveal frames
75 // before the screen is actually resized. The only robust way
76 // to detect window resize is to check it very frame
77 if (CheckWindowSizeChanged())
78 WindowResize(window_width_, window_height_);
79
8074 float fFPS;
8175 if (monitor_.Update(fFPS))
8276 {
134128 break;
135129
136130 case APP_CMD_CONFIG_CHANGED:
131 {
132 // This callback is not reliable for handling orientation changes. Depending on the
133 // device, it may be called before or after the surface has been actually resized.
134 break;
135 }
136
137 // Note that as of NDK r21b (21.1.6352462), APP_CMD_WINDOW_RESIZED event is never generated
138 // by android_native_app_glue.
139 // Also note that modifying android_native_app_glue to handle onNativeWindowResized
140 // callback (as suggested in https://android-developers.googleblog.com/2020/02/handling-device-orientation-efficiently.html)
141 // does not work either - the callback is only called once after the window has been created.
137142 case APP_CMD_WINDOW_RESIZED:
138 // This does not work as the screen resizes few frames
139 // after the event has been received
140 // eng->WindowResize(0,0);
141 break;
143 {
144 auto new_window_width = ANativeWindow_getWidth(app->window);
145 auto new_window_height = ANativeWindow_getHeight(app->window);
146 eng->WindowResize(new_window_width, new_window_height);
147 break;
148 }
149
150 // Note that as of NDK r21b (21.1.6352462), APP_CMD_CONTENT_RECT_CHANGED event is never
151 // generated by android_native_app_glue
152 case APP_CMD_CONTENT_RECT_CHANGED:
153 {
154 auto new_window_width = app->contentRect.right - app->contentRect.left;
155 auto new_window_height = app->contentRect.bottom - app->contentRect.top;
156 eng->WindowResize(new_window_width, new_window_height);
157 break;
158 }
142159
143160 case APP_CMD_TERM_WINDOW:
144161 // The window is being hidden or closed, clean it up.