From: <be...@us...> - 2012-05-03 14:12:46
|
Revision: 1291 http://freeglut.svn.sourceforge.net/freeglut/?rev=1291&view=rev Author: beuc Date: 2012-05-03 14:12:35 +0000 (Thu, 03 May 2012) Log Message: ----------- android: make code 're-entrant' - i.e. NativeActivity can restart the program without unloading it Modified Paths: -------------- trunk/freeglut/freeglut/src/android/fg_init_android.c trunk/freeglut/freeglut/src/android/fg_internal_android.h trunk/freeglut/freeglut/src/android/fg_main_android.c trunk/freeglut/freeglut/src/android/fg_runtime_android.c trunk/freeglut/freeglut/src/android/fg_structure_android.c trunk/freeglut/freeglut/src/android/fg_window_android.c Modified: trunk/freeglut/freeglut/src/android/fg_init_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_init_android.c 2012-05-03 13:32:06 UTC (rev 1290) +++ trunk/freeglut/freeglut/src/android/fg_init_android.c 2012-05-03 14:12:35 UTC (rev 1291) @@ -25,6 +25,7 @@ #include <GL/freeglut.h> #include "fg_internal.h" +#include "fg_init.h" #include "egl/fg_init_egl.h" void fgPlatformInitialize() Modified: trunk/freeglut/freeglut/src/android/fg_internal_android.h =================================================================== --- trunk/freeglut/freeglut/src/android/fg_internal_android.h 2012-05-03 13:32:06 UTC (rev 1290) +++ trunk/freeglut/freeglut/src/android/fg_internal_android.h 2012-05-03 14:12:35 UTC (rev 1291) @@ -104,7 +104,8 @@ typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState; struct tagSFG_PlatformWindowState { - int unused; + int32_t LastHeight; + int32_t LastWidth; }; #endif /* FREEGLUT_INTERNAL_ANDROID_H */ Modified: trunk/freeglut/freeglut/src/android/fg_main_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_main_android.c 2012-05-03 13:32:06 UTC (rev 1290) +++ trunk/freeglut/freeglut/src/android/fg_main_android.c 2012-05-03 14:12:35 UTC (rev 1291) @@ -318,6 +318,7 @@ /* The window is being hidden or closed, clean it up. */ LOGI("handle_cmd: APP_CMD_TERM_WINDOW"); fgDestroyWindow(fgDisplay.pDisplay.single_window); + fgDisplay.pDisplay.single_window = NULL; break; case APP_CMD_DESTROY: LOGI("handle_cmd: APP_CMD_DESTROY"); @@ -347,9 +348,6 @@ void fgPlatformProcessSingleEvent ( void ) { - static int32_t last_width = -1; - static int32_t last_height = -1; - /* When the screen is resized, the window handle still points to the old window until the next SwapBuffer, while it's crucial to set the size (onShape) correctly before the next onDisplay callback. @@ -363,9 +361,9 @@ if (window != NULL && window->Window.Handle != NULL) { int32_t width = ANativeWindow_getWidth(window->Window.Handle); int32_t height = ANativeWindow_getHeight(window->Window.Handle); - if (width != last_width || height != last_height) { - last_width = width; - last_height = height; + if (width != window->State.pWState.LastWidth || height != window->State.pWState.LastHeight) { + window->State.pWState.LastWidth = width; + window->State.pWState.LastHeight = height; LOGI("width=%d, height=%d", width, height); if( FETCH_WCB( *window, Reshape ) ) INVOKE_WCB( *window, Reshape, ( width, height ) ); Modified: trunk/freeglut/freeglut/src/android/fg_runtime_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_runtime_android.c 2012-05-03 13:32:06 UTC (rev 1290) +++ trunk/freeglut/freeglut/src/android/fg_runtime_android.c 2012-05-03 14:12:35 UTC (rev 1291) @@ -154,6 +154,8 @@ char progname[5] = "self"; char* argv[] = {progname, NULL}; main(1, argv); + /* FreeGLUT will exit() by itself if + GLUT_ACTION_ON_WINDOW_CLOSE == GLUT_ACTION_EXIT */ } LOGI("android_main: end"); @@ -163,7 +165,8 @@ while (!app->destroyRequested) fgPlatformProcessSingleEvent(); - /* In theory we should let NativeActivity restart us, however this - doesn't work well yet, so force exit */ - exit(0); + /* Let NativeActivity restart us */ + /* Users may want to forcibly exit() in their main() anyway because + NativeActivity doesn't dlclose() us, so all statically-assigned + variables keep their old values on restart.. */ } Modified: trunk/freeglut/freeglut/src/android/fg_structure_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_structure_android.c 2012-05-03 13:32:06 UTC (rev 1290) +++ trunk/freeglut/freeglut/src/android/fg_structure_android.c 2012-05-03 14:12:35 UTC (rev 1291) @@ -33,4 +33,6 @@ void fgPlatformCreateWindow ( SFG_Window *window ) { fghPlatformCreateWindowEGL(window); + window->State.pWState.LastWidth = -1; + window->State.pWState.LastHeight = -1; } Modified: trunk/freeglut/freeglut/src/android/fg_window_android.c =================================================================== --- trunk/freeglut/freeglut/src/android/fg_window_android.c 2012-05-03 13:32:06 UTC (rev 1290) +++ trunk/freeglut/freeglut/src/android/fg_window_android.c 2012-05-03 14:12:35 UTC (rev 1291) @@ -42,11 +42,10 @@ GLboolean gameMode, GLboolean isSubWindow ) { /* TODO: only one full-screen window possible? */ - static int nb_windows = 0; - if (nb_windows == 0) { - nb_windows++; + if (fgDisplay.pDisplay.single_window == NULL) { fgDisplay.pDisplay.single_window = window; } else { + fgWarning("You can't have more than one window on Android"); return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |