From 2ee5efc4a1d217f4cb5ddebcc89e38f269a817f3 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 24 Dec 2012 20:17:16 +0100 Subject: [PATCH] (Android) Orientation change now done in a stable way without freeing/ reiniting the video driver again --- android/native/jni/main.c | 10 +++++++ gfx/context/androidegl_ctx.c | 57 ++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/android/native/jni/main.c b/android/native/jni/main.c index bc828a01de..2bb7ca5ccd 100644 --- a/android/native/jni/main.c +++ b/android/native/jni/main.c @@ -184,6 +184,16 @@ void engine_handle_cmd(struct android_app* android_app, int32_t cmd) AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); print_cur_config(android_app); + + int32_t new_orient = AConfiguration_getOrientation(g_android.app->config); + + if (new_orient != g_android.last_orient && g_android.window_ready) + { + g_android.last_orient = new_orient; + gfx_ctx_orientation_update(); + // reinit video driver for new window dimensions + } + break; case APP_CMD_TERM_WINDOW: RARCH_LOG("engine_handle_cmd: APP_CMD_TERM_WINDOW.\n"); diff --git a/gfx/context/androidegl_ctx.c b/gfx/context/androidegl_ctx.c index 645bfaf1b7..04baa40cac 100644 --- a/gfx/context/androidegl_ctx.c +++ b/gfx/context/androidegl_ctx.c @@ -85,6 +85,30 @@ static void gfx_ctx_get_video_size(unsigned *width, unsigned *height) } } +static bool gfx_ctx_orientation_update(void) +{ + gl_t *gl = (gl_t*)driver.video_data; + + // Get real known video size, which might have been altered by context. + gfx_ctx_get_video_size(&gl->win_width, &gl->win_height); + RARCH_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height); + + if (gl->full_x || gl->full_y) // We got bogus from gfx_ctx_get_video_size. Replace. + { + gl->full_x = gl->win_width; + gl->full_y = gl->win_height; + } + +#ifdef HAVE_GLSL + gl_glsl_use(0); +#endif + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); +#ifdef HAVE_GLSL + gl_glsl_use(1); +#endif + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); +} + static bool gfx_ctx_init(void) { RARCH_LOG("gfx_ctx_init().\n"); @@ -168,27 +192,7 @@ static bool gfx_ctx_init(void) if (g_extern.lifecycle_state & (1ULL << RARCH_REENTRANT)) { RARCH_LOG("[ANDROID/EGL]: Setting up reentrant state.\n"); - - gl_t *gl = (gl_t*)driver.video_data; - - // Get real known video size, which might have been altered by context. - gfx_ctx_get_video_size(&gl->win_width, &gl->win_height); - RARCH_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height); - - if (gl->full_x || gl->full_y) // We got bogus from gfx_ctx_get_video_size. Replace. - { - gl->full_x = gl->win_width; - gl->full_y = gl->win_height; - } - -#ifdef HAVE_GLSL - gl_glsl_use(0); -#endif - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); -#ifdef HAVE_GLSL - gl_glsl_use(1); -#endif - gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); + gfx_ctx_orientation_update(); } return true; @@ -239,17 +243,6 @@ static void gfx_ctx_check_window(bool *quit, RARCH_PERFORMANCE_STOP(alooper_pollonce); - int32_t new_orient = AConfiguration_getOrientation(g_android.app->config); - - if (new_orient != g_android.last_orient && g_android.window_ready) - { - *resize = true; - g_android.last_orient = new_orient; - // reinit video driver for new window dimensions - driver.video->free(driver.video_data); - init_video_input(); - } - // Check if we are exiting. if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY)) *quit = true;