Merge commit '314bb5a1ed1a90276597b9aefef225a7c5027845' into main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 8537be3..cd33242 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -652,7 +652,7 @@ QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture,
return retval;
}
-static int UpdateLogicalSize(SDL_Renderer *renderer);
+static int UpdateLogicalSize(SDL_Renderer *renderer, SDL_bool flush_viewport_cmd);
int
SDL_GetNumRenderDrivers(void)
@@ -730,7 +730,14 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
}
if (renderer->logical_w) {
- UpdateLogicalSize(renderer);
+#if defined(__ANDROID__)
+ /* Don't immediatly flush because the app may be in
+ * background, and the egl context shouldn't be used. */
+ SDL_bool flush_viewport_cmd = SDL_FALSE;
+#else
+ SDL_bool flush_viewport_cmd = SDL_TRUE;
+#endif
+ UpdateLogicalSize(renderer, flush_viewport_cmd);
} else {
/* Window was resized, reset viewport */
int w, h;
@@ -746,7 +753,12 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
renderer->viewport.w = (double)w;
renderer->viewport.h = (double)h;
QueueCmdSetViewport(renderer);
+#if defined(__ANDROID__)
+ /* Don't immediatly flush because the app may be in
+ * background, and the egl context shouldn't be used. */
+#else
FlushRenderCommandsIfNotBatching(renderer);
+#endif
}
if (saved_target) {
@@ -2272,7 +2284,7 @@ SDL_GetRenderTarget(SDL_Renderer *renderer)
}
static int
-UpdateLogicalSize(SDL_Renderer *renderer)
+UpdateLogicalSize(SDL_Renderer *renderer, SDL_bool flush_viewport_cmd)
{
int w = 1, h = 1;
float want_aspect;
@@ -2329,12 +2341,12 @@ UpdateLogicalSize(SDL_Renderer *renderer)
viewport.x = (w - viewport.w) / 2;
viewport.h = (int)SDL_floor(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2;
-
- SDL_RenderSetViewport(renderer, &viewport);
} else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
/* The aspect ratios are the same, just scale appropriately */
scale = (float)w / renderer->logical_w;
- SDL_RenderSetViewport(renderer, NULL);
+
+ SDL_zero(viewport);
+ SDL_GetRendererOutputSize(renderer, &viewport.w, &viewport.h);
} else if (want_aspect > real_aspect) {
if (scale_policy == 1) {
/* We want a wider aspect ratio than is available -
@@ -2346,7 +2358,6 @@ UpdateLogicalSize(SDL_Renderer *renderer)
viewport.h = h;
viewport.w = (int)SDL_floor(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2;
- SDL_RenderSetViewport(renderer, &viewport);
} else {
/* We want a wider aspect ratio than is available - letterbox it */
scale = (float)w / renderer->logical_w;
@@ -2354,7 +2365,6 @@ UpdateLogicalSize(SDL_Renderer *renderer)
viewport.w = w;
viewport.h = (int)SDL_floor(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2;
- SDL_RenderSetViewport(renderer, &viewport);
}
} else {
if (scale_policy == 1) {
@@ -2367,7 +2377,6 @@ UpdateLogicalSize(SDL_Renderer *renderer)
viewport.w = w;
viewport.h = (int)SDL_floor(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2;
- SDL_RenderSetViewport(renderer, &viewport);
} else {
/* We want a narrower aspect ratio than is available - use side-bars */
scale = (float)h / renderer->logical_h;
@@ -2375,10 +2384,19 @@ UpdateLogicalSize(SDL_Renderer *renderer)
viewport.h = h;
viewport.w = (int)SDL_floor(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2;
- SDL_RenderSetViewport(renderer, &viewport);
}
}
+ /* Set the new viewport */
+ renderer->viewport.x = (double)viewport.x * renderer->scale.x;
+ renderer->viewport.y = (double)viewport.y * renderer->scale.y;
+ renderer->viewport.w = (double)viewport.w * renderer->scale.x;
+ renderer->viewport.h = (double)viewport.h * renderer->scale.y;
+ QueueCmdSetViewport(renderer);
+ if (flush_viewport_cmd) {
+ FlushRenderCommandsIfNotBatching(renderer);
+ }
+
/* Set the new scale */
SDL_RenderSetScale(renderer, scale, scale);
@@ -2402,7 +2420,7 @@ SDL_RenderSetLogicalSize(SDL_Renderer * renderer, int w, int h)
renderer->logical_w = w;
renderer->logical_h = h;
- return UpdateLogicalSize(renderer);
+ return UpdateLogicalSize(renderer, SDL_TRUE);
}
void
@@ -2425,7 +2443,7 @@ SDL_RenderSetIntegerScale(SDL_Renderer * renderer, SDL_bool enable)
renderer->integer_scale = enable;
- return UpdateLogicalSize(renderer);
+ return UpdateLogicalSize(renderer, SDL_TRUE);
}
SDL_bool