render: draw when hidden, except on iOS and Android.

Fixes #2979.
This commit is contained in:
Ryan C. Gordon 2021-04-02 14:01:41 -04:00
parent b42bf2a774
commit 57c2a4566f
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 35 additions and 0 deletions

View File

@ -32,6 +32,18 @@
# include "../core/android/SDL_android.h" # include "../core/android/SDL_android.h"
#endif #endif
/* as a courtesy to iOS apps, we don't try to draw when in the background, as
that will crash the app. However, these apps _should_ have used
SDL_AddEventWatch to catch SDL_APP_WILLENTERBACKGROUND events and stopped
drawing themselves. Other platforms still draw, as the compositor can use it,
and more importantly: drawing to render targets isn't lost. But I still think
this should probably be removed at some point in the future. --ryan. */
#if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
#define DONT_DRAW_WHILE_HIDDEN 1
#else
#define DONT_DRAW_WHILE_HIDDEN 0
#endif
#define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData" #define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData"
#define CHECK_RENDERER_MAGIC(renderer, retval) \ #define CHECK_RENDERER_MAGIC(renderer, retval) \
@ -2481,10 +2493,12 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
return RenderDrawPointsWithRects(renderer, points, count); return RenderDrawPointsWithRects(renderer, points, count);
@ -2551,10 +2565,12 @@ SDL_RenderDrawPointsF(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
return RenderDrawPointsWithRectsF(renderer, points, count); return RenderDrawPointsWithRectsF(renderer, points, count);
@ -2726,10 +2742,12 @@ SDL_RenderDrawLines(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
return RenderDrawLinesWithRects(renderer, points, count); return RenderDrawLinesWithRects(renderer, points, count);
@ -2769,10 +2787,12 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
return RenderDrawLinesWithRectsF(renderer, points, count); return RenderDrawLinesWithRectsF(renderer, points, count);
@ -2853,10 +2873,12 @@ SDL_RenderDrawRects(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) { if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
@ -2881,10 +2903,12 @@ SDL_RenderDrawRectsF(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
if (SDL_RenderDrawRectF(renderer, &rects[i]) < 0) { if (SDL_RenderDrawRectF(renderer, &rects[i]) < 0) {
@ -2946,10 +2970,12 @@ SDL_RenderFillRects(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
frects = SDL_small_alloc(SDL_FRect, count, &isstack); frects = SDL_small_alloc(SDL_FRect, count, &isstack);
if (!frects) { if (!frects) {
@ -2987,10 +3013,12 @@ SDL_RenderFillRectsF(SDL_Renderer * renderer,
return 0; return 0;
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
frects = SDL_small_alloc(SDL_FRect, count, &isstack); frects = SDL_small_alloc(SDL_FRect, count, &isstack);
if (!frects) { if (!frects) {
@ -3095,10 +3123,12 @@ SDL_RenderCopyF(SDL_Renderer * renderer, SDL_Texture * texture,
return SDL_SetError("Texture was not created with this renderer"); return SDL_SetError("Texture was not created with this renderer");
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
real_srcrect.x = 0; real_srcrect.x = 0;
real_srcrect.y = 0; real_srcrect.y = 0;
@ -3184,10 +3214,12 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
return SDL_SetError("Renderer does not support RenderCopyEx"); return SDL_SetError("Renderer does not support RenderCopyEx");
} }
#if DONT_DRAW_WHILE_HIDDEN
/* Don't draw while we're hidden */ /* Don't draw while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return 0; return 0;
} }
#endif
real_srcrect.x = 0; real_srcrect.x = 0;
real_srcrect.y = 0; real_srcrect.y = 0;
@ -3277,10 +3309,13 @@ SDL_RenderPresent(SDL_Renderer * renderer)
FlushRenderCommands(renderer); /* time to send everything to the GPU! */ FlushRenderCommands(renderer); /* time to send everything to the GPU! */
#if DONT_DRAW_WHILE_HIDDEN
/* Don't present while we're hidden */ /* Don't present while we're hidden */
if (renderer->hidden) { if (renderer->hidden) {
return; return;
} }
#endif
renderer->RenderPresent(renderer); renderer->RenderPresent(renderer);
} }