X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fandroid%2Ffg_runtime_android.c;h=d96f3af92d7b3f57073a903d8806924c93bb5b0c;hb=207c3128bf025b5e025bace5c0425d380dd72aa9;hp=13f2e864f8520e020d3cd81d78f4c8c382aa59d3;hpb=e5cd5f98d651aad9c265e569db6188fb0378aeeb;p=freeglut diff --git a/src/android/fg_runtime_android.c b/src/android/fg_runtime_android.c index 13f2e86..d96f3af 100644 --- a/src/android/fg_runtime_android.c +++ b/src/android/fg_runtime_android.c @@ -1,5 +1,5 @@ /* - * freeglut_runtime_android.c + * fg_runtime_android.c * * Android runtime * @@ -49,11 +49,12 @@ #include #include #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__)) +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "FreeGLUT-jnicb", __VA_ARGS__)) +#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "FreeGLUT-jnicb", __VA_ARGS__)) -/* Cf. freeglut_main_android.c */ +/* Cf. fg_main_android.c */ extern int32_t handle_input(struct android_app* app, AInputEvent* event); extern void handle_cmd(struct android_app* app, int32_t cmd); @@ -78,7 +79,6 @@ static void onNativeWindowResized(ANativeActivity* activity, ANativeWindow* wind static void onNativeWindowRedrawNeeded(ANativeActivity* activity, ANativeWindow* window) { LOGI("onNativeWindowRedrawNeeded: %p\n", (void*)activity); struct android_app* app = (struct android_app*)activity->instance; - //if (fgDisplay.pDisplay.single_window->Window.pContext.eglSurface != EGL_NO_SURFACE) android_app_write_cmd(app, APP_CMD_WINDOW_RESIZED); } @@ -128,6 +128,8 @@ static void extract_assets(struct android_app* app) { AAssetDir_close(assetDir); } } + + (*vm)->DetachCurrentThread(vm); } /** @@ -136,9 +138,9 @@ static void extract_assets(struct android_app* app) { * event loop for receiving input events and doing other things. */ void android_main(struct android_app* app) { - LOGI("android_main"); + LOGI("android_main savedState=%p", app->savedState); - // Register window resize callback + /* Register window resize callback */ app->activity->callbacks->onNativeWindowResized = onNativeWindowResized; app->activity->callbacks->onContentRectChanged = onContentRectChanged; app->activity->callbacks->onNativeWindowRedrawNeeded = onNativeWindowRedrawNeeded; @@ -152,9 +154,16 @@ void android_main(struct android_app* app) { { char progname[5] = "self"; char* argv[] = {progname, NULL}; + fgDisplay.pDisplay.app = app; main(1, argv); + /* FreeGLUT will exit() by itself if + GLUT_ACTION_ON_WINDOW_CLOSE == GLUT_ACTION_EXIT */ } LOGI("android_main: end"); - 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.. */ }