android: make code 're-entrant' - i.e. NativeActivity can restart the program without unloading it
git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1291 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
d807511ff9
commit
1d008232f5
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <GL/freeglut.h>
|
#include <GL/freeglut.h>
|
||||||
#include "fg_internal.h"
|
#include "fg_internal.h"
|
||||||
|
#include "fg_init.h"
|
||||||
#include "egl/fg_init_egl.h"
|
#include "egl/fg_init_egl.h"
|
||||||
|
|
||||||
void fgPlatformInitialize()
|
void fgPlatformInitialize()
|
||||||
|
@ -104,7 +104,8 @@ struct tagSFG_PlatformJoystick
|
|||||||
typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState;
|
typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState;
|
||||||
struct tagSFG_PlatformWindowState
|
struct tagSFG_PlatformWindowState
|
||||||
{
|
{
|
||||||
int unused;
|
int32_t LastHeight;
|
||||||
|
int32_t LastWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FREEGLUT_INTERNAL_ANDROID_H */
|
#endif /* FREEGLUT_INTERNAL_ANDROID_H */
|
||||||
|
@ -318,6 +318,7 @@ void handle_cmd(struct android_app* app, int32_t cmd) {
|
|||||||
/* The window is being hidden or closed, clean it up. */
|
/* The window is being hidden or closed, clean it up. */
|
||||||
LOGI("handle_cmd: APP_CMD_TERM_WINDOW");
|
LOGI("handle_cmd: APP_CMD_TERM_WINDOW");
|
||||||
fgDestroyWindow(fgDisplay.pDisplay.single_window);
|
fgDestroyWindow(fgDisplay.pDisplay.single_window);
|
||||||
|
fgDisplay.pDisplay.single_window = NULL;
|
||||||
break;
|
break;
|
||||||
case APP_CMD_DESTROY:
|
case APP_CMD_DESTROY:
|
||||||
LOGI("handle_cmd: APP_CMD_DESTROY");
|
LOGI("handle_cmd: APP_CMD_DESTROY");
|
||||||
@ -347,9 +348,6 @@ void handle_cmd(struct android_app* app, int32_t cmd) {
|
|||||||
|
|
||||||
void fgPlatformProcessSingleEvent ( void )
|
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
|
/* When the screen is resized, the window handle still points to the
|
||||||
old window until the next SwapBuffer, while it's crucial to set
|
old window until the next SwapBuffer, while it's crucial to set
|
||||||
the size (onShape) correctly before the next onDisplay callback.
|
the size (onShape) correctly before the next onDisplay callback.
|
||||||
@ -363,9 +361,9 @@ void fgPlatformProcessSingleEvent ( void )
|
|||||||
if (window != NULL && window->Window.Handle != NULL) {
|
if (window != NULL && window->Window.Handle != NULL) {
|
||||||
int32_t width = ANativeWindow_getWidth(window->Window.Handle);
|
int32_t width = ANativeWindow_getWidth(window->Window.Handle);
|
||||||
int32_t height = ANativeWindow_getHeight(window->Window.Handle);
|
int32_t height = ANativeWindow_getHeight(window->Window.Handle);
|
||||||
if (width != last_width || height != last_height) {
|
if (width != window->State.pWState.LastWidth || height != window->State.pWState.LastHeight) {
|
||||||
last_width = width;
|
window->State.pWState.LastWidth = width;
|
||||||
last_height = height;
|
window->State.pWState.LastHeight = height;
|
||||||
LOGI("width=%d, height=%d", width, height);
|
LOGI("width=%d, height=%d", width, height);
|
||||||
if( FETCH_WCB( *window, Reshape ) )
|
if( FETCH_WCB( *window, Reshape ) )
|
||||||
INVOKE_WCB( *window, Reshape, ( width, height ) );
|
INVOKE_WCB( *window, Reshape, ( width, height ) );
|
||||||
|
@ -154,6 +154,8 @@ void android_main(struct android_app* app) {
|
|||||||
char progname[5] = "self";
|
char progname[5] = "self";
|
||||||
char* argv[] = {progname, NULL};
|
char* argv[] = {progname, NULL};
|
||||||
main(1, argv);
|
main(1, argv);
|
||||||
|
/* FreeGLUT will exit() by itself if
|
||||||
|
GLUT_ACTION_ON_WINDOW_CLOSE == GLUT_ACTION_EXIT */
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGI("android_main: end");
|
LOGI("android_main: end");
|
||||||
@ -163,7 +165,8 @@ void android_main(struct android_app* app) {
|
|||||||
while (!app->destroyRequested)
|
while (!app->destroyRequested)
|
||||||
fgPlatformProcessSingleEvent();
|
fgPlatformProcessSingleEvent();
|
||||||
|
|
||||||
/* In theory we should let NativeActivity restart us, however this
|
/* Let NativeActivity restart us */
|
||||||
doesn't work well yet, so force exit */
|
/* Users may want to forcibly exit() in their main() anyway because
|
||||||
exit(0);
|
NativeActivity doesn't dlclose() us, so all statically-assigned
|
||||||
|
variables keep their old values on restart.. */
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,6 @@
|
|||||||
void fgPlatformCreateWindow ( SFG_Window *window )
|
void fgPlatformCreateWindow ( SFG_Window *window )
|
||||||
{
|
{
|
||||||
fghPlatformCreateWindowEGL(window);
|
fghPlatformCreateWindowEGL(window);
|
||||||
|
window->State.pWState.LastWidth = -1;
|
||||||
|
window->State.pWState.LastHeight = -1;
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,10 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title,
|
|||||||
GLboolean gameMode, GLboolean isSubWindow )
|
GLboolean gameMode, GLboolean isSubWindow )
|
||||||
{
|
{
|
||||||
/* TODO: only one full-screen window possible? */
|
/* TODO: only one full-screen window possible? */
|
||||||
static int nb_windows = 0;
|
if (fgDisplay.pDisplay.single_window == NULL) {
|
||||||
if (nb_windows == 0) {
|
|
||||||
nb_windows++;
|
|
||||||
fgDisplay.pDisplay.single_window = window;
|
fgDisplay.pDisplay.single_window = window;
|
||||||
} else {
|
} else {
|
||||||
|
fgWarning("You can't have more than one window on Android");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user