From: <be...@us...> - 2012-05-03 19:35:18
|
Revision: 1292 http://freeglut.svn.sourceforge.net/freeglut/?rev=1292&view=rev Author: beuc Date: 2012-05-03 16:40:20 +0000 (Thu, 03 May 2012) Log Message: ----------- Document android app lifecycle; kill app when window is closed, until pausing/restoring windows is possible Modified Paths: -------------- trunk/freeglut/freeglut/src/android/fg_main_android.c trunk/freeglut/freeglut/src/android/fg_main_android.h trunk/freeglut/freeglut/src/android/fg_runtime_android.c Modified: trunk/freeglut/freeglut/src/android/fg_main_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_main_android.c 2012-05-03 14:12:35 UTC (rev 1291) +++ trunk/freeglut/freeglut/src/android/fg_main_android.c 2012-05-03 16:40:20 UTC (rev 1292) @@ -303,43 +303,75 @@ */ void handle_cmd(struct android_app* app, int32_t cmd) { switch (cmd) { - case APP_CMD_SAVE_STATE: - /* The system has asked us to save our current state. Do so. */ - LOGI("handle_cmd: APP_CMD_SAVE_STATE"); + /* App life cycle, in that order: */ + case APP_CMD_START: + LOGI("handle_cmd: APP_CMD_START"); break; - case APP_CMD_INIT_WINDOW: + case APP_CMD_RESUME: + LOGI("handle_cmd: APP_CMD_RESUME"); + /* If coming back from a pause: */ + /* - Recreate window context and surface */ + /* - Call user-defined hook to restore resources (textures...) */ + /* - Unpause GLUT callbacks */ + break; + case APP_CMD_INIT_WINDOW: /* surfaceCreated */ /* The window is being shown, get it ready. */ LOGI("handle_cmd: APP_CMD_INIT_WINDOW"); fgDisplay.pDisplay.single_window->Window.Handle = app->window; /* glPlatformOpenWindow was waiting for Handle to be defined and will now return from fgPlatformProcessSingleEvent() */ break; - case APP_CMD_TERM_WINDOW: - /* The window is being hidden or closed, clean it up. */ - LOGI("handle_cmd: APP_CMD_TERM_WINDOW"); + case APP_CMD_GAINED_FOCUS: + LOGI("handle_cmd: APP_CMD_GAINED_FOCUS"); + break; + case APP_CMD_WINDOW_RESIZED: + LOGI("handle_cmd: APP_CMD_WINDOW_RESIZED"); + if (fgDisplay.pDisplay.single_window->Window.pContext.egl.Surface != EGL_NO_SURFACE) + /* Make ProcessSingleEvent detect the new size, only available + after the next SwapBuffer */ + glutPostRedisplay(); + break; + + case APP_CMD_SAVE_STATE: /* onSaveInstanceState */ + /* The system has asked us to save our current state, when it + pauses the application without destroying it right after. */ + /* app->savedState = ... */ + /* app->savedStateSize = ... */ + LOGI("handle_cmd: APP_CMD_SAVE_STATE"); + break; + case APP_CMD_PAUSE: + LOGI("handle_cmd: APP_CMD_PAUSE"); + /* - Pause GLUT callbacks */ + break; + case APP_CMD_LOST_FOCUS: + LOGI("handle_cmd: APP_CMD_LOST_FOCUS"); + break; + case APP_CMD_TERM_WINDOW: /* surfaceDestroyed */ + /* The application is being hidden, but may be restored */ + /* TODO: Pausing/resuming windows not ready yet, so killing it now */ fgDestroyWindow(fgDisplay.pDisplay.single_window); fgDisplay.pDisplay.single_window = NULL; + LOGI("handle_cmd: APP_CMD_TERM_WINDOW"); break; - case APP_CMD_DESTROY: + case APP_CMD_STOP: + LOGI("handle_cmd: APP_CMD_STOP"); + break; + case APP_CMD_DESTROY: /* Activity.onDestroy */ LOGI("handle_cmd: APP_CMD_DESTROY"); + /* User closed the application for good, let's kill the window */ + if (fgDisplay.pDisplay.single_window != NULL) { + fgDestroyWindow(fgDisplay.pDisplay.single_window); + fgDisplay.pDisplay.single_window = NULL; + } /* glue has already set android_app->destroyRequested=1 */ break; - case APP_CMD_GAINED_FOCUS: - LOGI("handle_cmd: APP_CMD_GAINED_FOCUS"); - break; - case APP_CMD_LOST_FOCUS: - LOGI("handle_cmd: APP_CMD_LOST_FOCUS"); - break; + case APP_CMD_CONFIG_CHANGED: /* Handle rotation / orientation change */ LOGI("handle_cmd: APP_CMD_CONFIG_CHANGED"); break; - case APP_CMD_WINDOW_RESIZED: - LOGI("handle_cmd: APP_CMD_WINDOW_RESIZED"); - if (fgDisplay.pDisplay.single_window->Window.pContext.egl.Surface != EGL_NO_SURFACE) - /* Make ProcessSingleEvent detect the new size, only available - after the next SwapBuffer */ - glutPostRedisplay(); + case APP_CMD_LOW_MEMORY: + LOGI("handle_cmd: APP_CMD_LOW_MEMORY"); break; default: LOGI("handle_cmd: unhandled cmd=%d", cmd); Modified: trunk/freeglut/freeglut/src/android/fg_main_android.h =================================================================== --- trunk/freeglut/freeglut/src/android/fg_main_android.h 2012-05-03 14:12:35 UTC (rev 1291) +++ trunk/freeglut/freeglut/src/android/fg_main_android.h 2012-05-03 16:40:20 UTC (rev 1292) @@ -26,6 +26,9 @@ #ifndef __FG_MAIN_ANDROID_H__ #define __FG_MAIN_ANDROID_H__ +#include <GL/freeglut.h> +#include "fg_internal.h" + extern void fgPlatformProcessSingleEvent(void); extern void fgPlatformReshapeWindow(SFG_Window *window, int width, int height); extern void fgPlatformDisplayWindow(SFG_Window *window); Modified: trunk/freeglut/freeglut/src/android/fg_runtime_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_runtime_android.c 2012-05-03 14:12:35 UTC (rev 1291) +++ trunk/freeglut/freeglut/src/android/fg_runtime_android.c 2012-05-03 16:40:20 UTC (rev 1292) @@ -49,6 +49,7 @@ #include <android/asset_manager.h> #include <android/native_window.h> #include "android/native_app_glue/android_native_app_glue.h" +#include "android/fg_main_android.h" #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "FreeGLUT", __VA_ARGS__)) #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "FreeGLUT", __VA_ARGS__)) @@ -160,6 +161,9 @@ LOGI("android_main: end"); + /* TODO: Pausing/resuming windows not ready yet, so exiting now */ + exit(0); + /* Finish processing all events (namely APP_CMD_DESTROY) before exiting thread */ while (!app->destroyRequested) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |