12
12
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
13
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
14
14
*
15
- * In no event and under no legal theory, whether in tort (including negligence),
16
- * contract, or otherwise, unless required by applicable law (such as deliberate
15
+ * In no event and under no legal theory, whether in tort (including negligence),
16
+ * contract, or otherwise, unless required by applicable law (such as deliberate
17
17
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
18
- * liable for any damages, including any direct, indirect, special, incidental,
19
- * or consequential damages of any character arising as a result of this License or
20
- * out of the use or inability to use the software (including but not limited to damages
21
- * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
22
- * all other commercial damages or losses), even if such Contributor has been advised
18
+ * liable for any damages, including any direct, indirect, special, incidental,
19
+ * or consequential damages of any character arising as a result of this License or
20
+ * out of the use or inability to use the software (including but not limited to damages
21
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
22
+ * all other commercial damages or losses), even if such Contributor has been advised
23
23
* of the possibility of such damages.
24
24
*/
25
25
26
26
#include " AndroidAppBase.hpp"
27
+ #include " Errors.hpp"
27
28
#include " Timer.hpp"
28
29
29
30
#include < android/sensor.h>
@@ -118,22 +119,60 @@ void AndroidAppBase::HandleCmd(struct android_app* app, int32_t cmd)
118
119
AndroidAppBase* eng = (AndroidAppBase*)app->userData ;
119
120
switch (cmd)
120
121
{
121
- case APP_CMD_SAVE_STATE:
122
- break ;
123
-
124
122
case APP_CMD_INIT_WINDOW:
125
- // The window is being shown, get it ready.
126
- if (app->window != NULL )
123
+ #if (DILIGENT_DEVLOPMENT)
124
+ LOG_INFO_MESSAGE (" APP_CMD_INIT_WINDOW" );
125
+ #endif
126
+ app->window = app->pendingWindow ;
127
+ if (app->window &&
128
+ ANativeWindow_getWidth (app->window ) &&
129
+ ANativeWindow_getHeight (app->window ))
127
130
{
131
+ #if (DILIGENT_DEVLOPMENT)
132
+ LOG_INFO_MESSAGE (" INIT DISPLAY - HAS SURFACE" );
133
+ #endif
128
134
eng->InitDisplay ();
129
135
eng->DrawFrame ();
136
+ std::lock_guard<std::mutex> lock (eng->mutex );
137
+ eng->app_status_ |= APP_STATUS_FLAG_HAS_REAL_SURFACE;
138
+ }
139
+ else
140
+ {
141
+ #if (DILIGENT_DEVLOPMENT)
142
+ LOG_INFO_MESSAGE (" LOST SURFACE" );
143
+ #endif
144
+ std::lock_guard<std::mutex> lock (eng->mutex );
145
+ eng->app_status_ &= ~APP_STATUS_FLAG_HAS_REAL_SURFACE;
130
146
}
131
147
break ;
132
148
133
- case APP_CMD_CONFIG_CHANGED:
149
+ case APP_CMD_TERM_WINDOW:
150
+ #if (DILIGENT_DEVLOPMENT)
151
+ LOG_INFO_MESSAGE (" APP_CMD_TERM_WINDOW - LOST SURFACE" );
152
+ #endif
153
+ {
154
+ std::lock_guard<std::mutex> lock (eng->mutex );
155
+ eng->app_status_ &= ~APP_STATUS_FLAG_HAS_REAL_SURFACE;
156
+ }
157
+ #if (DILIGENT_DEVLOPMENT)
158
+ LOG_INFO_MESSAGE (" TERM DISPLAY" );
159
+ #endif
160
+ eng->TermDisplay ();
161
+ break ;
162
+
163
+ // Note that as of NDK r21b (21.1.6352462), APP_CMD_CONTENT_RECT_CHANGED event is never
164
+ // generated by android_native_app_glue
165
+ case APP_CMD_CONTENT_RECT_CHANGED:
134
166
{
135
- // This callback is not reliable for handling orientation changes. Depending on the
136
- // device, it may be called before or after the surface has been actually resized.
167
+ #if (DILIGENT_DEVLOPMENT)
168
+ LOG_INFO_MESSAGE (" APP_CMD_CONTENT_RECT_CHANGED" );
169
+ #endif
170
+
171
+ int32_t new_window_width =
172
+ app->contentRect .right - app->contentRect .left ;
173
+ int32_t new_window_height =
174
+ app->contentRect .bottom - app->contentRect .top ;
175
+ eng->WindowResize (new_window_width, new_window_height);
137
176
break ;
138
177
}
139
178
@@ -144,45 +183,111 @@ void AndroidAppBase::HandleCmd(struct android_app* app, int32_t cmd)
144
183
// does not work either - the callback is only called once after the window has been created.
145
184
case APP_CMD_WINDOW_RESIZED:
146
185
{
147
- auto new_window_width = ANativeWindow_getWidth (app->window );
148
- auto new_window_height = ANativeWindow_getHeight (app->window );
149
- eng->WindowResize (new_window_width, new_window_height);
186
+ #if (DILIGENT_DEVLOPMENT)
187
+ LOG_INFO_MESSAGE (" APP_CMD_WINDOW_RESIZED" );
188
+ #endif
189
+ if (app->window )
190
+ {
191
+ int32_t new_window_width = ANativeWindow_getWidth (app->window );
192
+ int32_t new_window_height = ANativeWindow_getHeight (app->window );
193
+ if (new_window_width && new_window_height)
194
+ {
195
+ eng->WindowResize (new_window_width, new_window_height);
196
+ }
197
+ }
150
198
break ;
151
199
}
152
200
153
- // Note that as of NDK r21b (21.1.6352462), APP_CMD_CONTENT_RECT_CHANGED event is never
154
- // generated by android_native_app_glue
155
- case APP_CMD_CONTENT_RECT_CHANGED:
156
- {
157
- auto new_window_width = app->contentRect .right - app->contentRect .left ;
158
- auto new_window_height = app->contentRect .bottom - app->contentRect .top ;
159
- eng->WindowResize (new_window_width, new_window_height);
201
+ case APP_CMD_GAINED_FOCUS:
202
+ #if (DILIGENT_DEVLOPMENT)
203
+ LOG_INFO_MESSAGE (" APP_CMD_GAINED_FOCUS - HAS FOCUS" );
204
+ #endif
205
+ {
206
+ std::lock_guard<std::mutex> lock (eng->mutex );
207
+ eng->app_status_ |= APP_STATUS_FLAG_FOCUSED;
208
+ }
209
+ eng->ResumeSensors ();
210
+ break ;
211
+
212
+ case APP_CMD_LOST_FOCUS:
213
+ #if (DILIGENT_DEVLOPMENT)
214
+ LOG_INFO_MESSAGE (" APP_CMD_LOST_FOCUS - LOST FOCUS" );
215
+ #endif
216
+ {
217
+ std::lock_guard<std::mutex> lock (eng->mutex );
218
+ eng->app_status_ &= ~APP_STATUS_FLAG_FOCUSED;
219
+ }
220
+ eng->SuspendSensors ();
221
+ break ;
222
+
223
+ case APP_CMD_RESUME:
224
+ #if (DILIGENT_DEVLOPMENT)
225
+ LOG_INFO_MESSAGE (" APP_CMD_RESUME - IS ACTIVE" );
226
+ #endif
227
+ {
228
+ std::lock_guard<std::mutex> lock (eng->mutex );
229
+ eng->app_status_ |= APP_STATUS_FLAG_ACTIVE;
230
+ }
231
+ break ;
232
+
233
+ case APP_CMD_START:
234
+ #if (DILIGENT_DEVLOPMENT)
235
+ LOG_INFO_MESSAGE (" APP_CMD_START" );
236
+ #endif
160
237
break ;
161
- }
162
238
163
- case APP_CMD_TERM_WINDOW:
164
239
case APP_CMD_PAUSE:
165
- // The window is being hidden or closed, clean it up.
166
- eng->TermDisplay ();
167
- eng->has_focus_ = false ;
240
+ #if (DILIGENT_DEVLOPMENT)
241
+ LOG_INFO_MESSAGE (" APP_CMD_PAUSE - IS NOT ACTIVE" );
242
+ #endif
243
+ {
244
+ std::lock_guard<std::mutex> lock (eng->mutex );
245
+ eng->app_status_ &= ~APP_STATUS_FLAG_ACTIVE;
246
+ }
168
247
break ;
169
248
170
249
case APP_CMD_STOP:
250
+ #if (DILIGENT_DEVLOPMENT)
251
+ LOG_INFO_MESSAGE (" APP_CMD_STOP" );
252
+ #endif
171
253
break ;
172
254
173
- case APP_CMD_GAINED_FOCUS:
174
- eng->ResumeSensors ();
175
- // Start animation
176
- eng->has_focus_ = true ;
255
+ case APP_CMD_CONFIG_CHANGED:
256
+ #if (DILIGENT_DEVLOPMENT)
257
+ LOG_INFO_MESSAGE (" APP_CMD_CONFIG_CHANGED" );
258
+ #endif
259
+ // AConfiguration_fromAssetManager(app->config, app->activity->assetManager);
260
+ // This callback is not reliable for handling orientation changes. Depending on the
261
+ // device, it may be called before or after the surface has been actually resized.
177
262
break ;
178
263
179
- case APP_CMD_LOST_FOCUS:
180
- eng->SuspendSensors ();
181
- // Also stop animating.
182
- eng->has_focus_ = false ;
264
+ case APP_CMD_DESTROY:
265
+ #if (DILIGENT_DEVLOPMENT)
266
+ LOG_INFO_MESSAGE (" APP_CMD_DESTROY - IS NOT RUNNING" );
267
+ #endif
268
+ {
269
+ std::lock_guard<std::mutex> lock (eng->mutex );
270
+ eng->app_status_ &= ~APP_STATUS_FLAG_RUNNING;
271
+ }
272
+ break ;
273
+
274
+ case APP_CMD_WINDOW_REDRAW_NEEDED:
275
+ #if (DILIGENT_DEVLOPMENT)
276
+ LOG_INFO_MESSAGE (" APP_CMD_WINDOW_REDRAW_NEEDED" );
277
+ #endif
278
+ if (eng->IsReady ()) eng->DrawFrame ();
279
+ break ;
280
+
281
+ case APP_CMD_SAVE_STATE:
282
+ #if (DILIGENT_DEVLOPMENT)
283
+ LOG_INFO_MESSAGE (" APP_CMD_SAVE_STATE" );
284
+ #endif
183
285
break ;
184
286
185
287
case APP_CMD_LOW_MEMORY:
288
+ #if (DILIGENT_DEVLOPMENT)
289
+ LOG_INFO_MESSAGE (" APP_CMD_LOW_MEMORY" );
290
+ #endif
186
291
// Free up GL resources
187
292
eng->TrimMemory ();
188
293
break ;
@@ -244,10 +349,11 @@ void AndroidAppBase::SetState(android_app* state, const char* native_activity_cl
244
349
245
350
bool AndroidAppBase::IsReady ()
246
351
{
247
- if (has_focus_)
248
- return true ;
249
-
250
- return false ;
352
+ std::lock_guard<std::mutex> lock (mutex);
353
+ return (app_status_ & APP_STATUS_FLAG_RUNNING) != APP_STATUS_FLAG_NONE &&
354
+ (app_status_ & APP_STATUS_FLAG_ACTIVE) != APP_STATUS_FLAG_NONE &&
355
+ (app_status_ & APP_STATUS_FLAG_FOCUSED) != APP_STATUS_FLAG_NONE &&
356
+ (app_status_ & APP_STATUS_FLAG_HAS_REAL_SURFACE) != APP_STATUS_FLAG_NONE;
251
357
}
252
358
253
359
// void Engine::TransformPosition( ndk_helper::Vec2& vec )
0 commit comments