Android/Vulkan: Recreate swapchain on orientation change.

ANativeWindow getWidth/Height does not detect any changes when using
Vulkan, so use the old onContentRectChanged callback to get notified
when size changed. Use those values instead when figuring out how large
swapchain to create.

Tested trivially on Galaxy S9+ Exynos model.
This commit is contained in:
Themaister 2019-12-15 16:45:00 +01:00
parent 15838c2850
commit 15ffffa835
3 changed files with 33 additions and 4 deletions

View File

@ -377,6 +377,18 @@ static void onInputQueueDestroyed(ANativeActivity* activity,
android_app_set_input((struct android_app*)activity->instance, NULL); android_app_set_input((struct android_app*)activity->instance, NULL);
} }
static void onContentRectChanged(ANativeActivity *activity,
const ARect *rect)
{
struct android_app *instance = (struct android_app*)activity->instance;
unsigned width = rect->right - rect->left;
unsigned height = rect->bottom - rect->top;
RARCH_LOG("Content rect changed: %u x %u\n", width, height);
instance->content_rect.changed = true;
instance->content_rect.width = width;
instance->content_rect.height = height;
}
JNIEnv *jni_thread_getenv(void) JNIEnv *jni_thread_getenv(void)
{ {
JNIEnv *env; JNIEnv *env;
@ -486,6 +498,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity,
activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed; activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed;
activity->callbacks->onInputQueueCreated = onInputQueueCreated; activity->callbacks->onInputQueueCreated = onInputQueueCreated;
activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed; activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed;
activity->callbacks->onContentRectChanged = onContentRectChanged;
/* These are set only for the native activity, /* These are set only for the native activity,
* and are reset when it ends. */ * and are reset when it ends. */

View File

@ -165,6 +165,12 @@ struct android_app
jmethodID setScreenOrientation; jmethodID setScreenOrientation;
jmethodID getUserLanguageString; jmethodID getUserLanguageString;
jmethodID doVibrate; jmethodID doVibrate;
struct
{
unsigned width, height;
bool changed;
} content_rect;
}; };
enum enum

View File

@ -218,6 +218,10 @@ static void android_gfx_ctx_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, bool *resize, unsigned *width, unsigned *height,
bool is_shutdown) bool is_shutdown)
{ {
#ifdef HAVE_VULKAN
struct android_app *android_app = (struct android_app*)g_android;
#endif
unsigned new_width = 0; unsigned new_width = 0;
unsigned new_height = 0; unsigned new_height = 0;
android_ctx_data_t *and = (android_ctx_data_t*)data; android_ctx_data_t *and = (android_ctx_data_t*)data;
@ -234,11 +238,17 @@ static void android_gfx_ctx_check_window(void *data, bool *quit,
break; break;
case GFX_CTX_VULKAN_API: case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN #ifdef HAVE_VULKAN
if (android_app->content_rect.changed)
{
and->vk.need_new_swapchain = true;
android_app->content_rect.changed = false;
}
/* Swapchains are recreated in set_resize as a /* Swapchains are recreated in set_resize as a
* central place, so use that to trigger swapchain reinit. */ * central place, so use that to trigger swapchain reinit. */
*resize = and->vk.need_new_swapchain; *resize = and->vk.need_new_swapchain;
new_width = and->width; new_width = android_app->content_rect.width;
new_height = and->height; new_height = android_app->content_rect.height;
#endif #endif
break; break;
case GFX_CTX_NONE: case GFX_CTX_NONE:
@ -276,8 +286,8 @@ static bool android_gfx_ctx_set_resize(void *data,
{ {
case GFX_CTX_VULKAN_API: case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN #ifdef HAVE_VULKAN
and->width = ANativeWindow_getWidth(android_app->window); and->width = android_app->content_rect.width;
and->height = ANativeWindow_getHeight(android_app->window); and->height = android_app->content_rect.height;
RARCH_LOG("[Android]: Native window size: %u x %u.\n", and->width, and->height); RARCH_LOG("[Android]: Native window size: %u x %u.\n", and->width, and->height);
if (!vulkan_create_swapchain(&and->vk, and->width, and->height, and->swap_interval)) if (!vulkan_create_swapchain(&and->vk, and->width, and->height, and->swap_interval))
{ {