1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Fix splash screen upside down on Android

Fixes an issue introduced in #96439 (see
https://github.com/godotengine/godot/pull/96439#issuecomment-2447288702)

Godot was relying on Java's
activity.getWindowManager().getDefaultDisplay().getRotation(); to apply
pre-rotation but this is wrong.

First, getRotation() may temporarily return a different value from the
correct one; which is what was causing the splash screen to be upside
down. It would return -90 instead of 90 for the first rendered frame.

But unfortunately, the splash screen is just one frame rendered for a
very long time, so the error lingered for a long time for everyone to
see.

Second, to determine what rotation to use, we should be looking at what
Vulkan told us, which is the value we pass to
VkSurfaceTransformFlagBitsKHR::preTransform.

This commit removes the now-unnecessary
screen_get_internal_current_rotation() function (which was introduced by
#96439) and now saves the preTransform value in the swapchain.
This commit is contained in:
Matias N. Goldberg
2024-10-31 16:52:26 -03:00
parent ef8d981267
commit b9a2f108fc
12 changed files with 42 additions and 53 deletions

View File

@@ -2996,6 +2996,24 @@ Error RenderingDeviceDriverVulkan::swap_chain_resize(CommandQueueID p_cmd_queue,
swap_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
swap_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
swap_create_info.preTransform = surface_transform_bits;
switch (swap_create_info.preTransform) {
case VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR:
swap_chain->pre_transform_rotation_degrees = 0;
break;
case VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR:
swap_chain->pre_transform_rotation_degrees = 90;
break;
case VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR:
swap_chain->pre_transform_rotation_degrees = 180;
break;
case VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR:
swap_chain->pre_transform_rotation_degrees = 270;
break;
default:
WARN_PRINT("Unexpected swap_create_info.preTransform = " + itos(swap_create_info.preTransform) + ".");
swap_chain->pre_transform_rotation_degrees = 0;
break;
}
swap_create_info.compositeAlpha = composite_alpha;
swap_create_info.presentMode = present_mode;
swap_create_info.clipped = true;
@@ -3167,6 +3185,13 @@ RDD::RenderPassID RenderingDeviceDriverVulkan::swap_chain_get_render_pass(SwapCh
return swap_chain->render_pass;
}
int RenderingDeviceDriverVulkan::swap_chain_get_pre_rotation_degrees(SwapChainID p_swap_chain) {
DEV_ASSERT(p_swap_chain.id != 0);
SwapChain *swap_chain = (SwapChain *)(p_swap_chain.id);
return swap_chain->pre_transform_rotation_degrees;
}
RDD::DataFormat RenderingDeviceDriverVulkan::swap_chain_get_format(SwapChainID p_swap_chain) {
DEV_ASSERT(p_swap_chain.id != 0);