sdl12-compat: video: Fix apps that UpdateRect and never PumpEvents.

From 0668c11486d33eea06beae8782777001dd17459d Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 20 Oct 2022 23:48:27 -0400
Subject: [PATCH] video: Fix apps that UpdateRect and never PumpEvents.

An app that _only_ calls SDL_UpdateRects (perhaps to draw just a piece of
animation that doesn't cover the screen but while not accepting user input)
will now check inside SDL_UpdateRects itself to decide if enough time has
gone by to warrant a present.

Also, if SDL_Delay is called and a present is pending at all, just do it,
as a signal from the app that the frame is complete. This catches things
that update a rectangle and then delay for the user to view it.

Fixes #253.
---
 src/SDL12_compat.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 4173b13dc..26b5caaef 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -6821,7 +6821,11 @@ SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL12_Rect *rects12)
         } else if (whole_screen) {
             PresentScreen();  /* flip it now. */
         } else {
-            VideoSurfacePresentTicks = VideoSurfaceLastPresentTicks + GetDesiredMillisecondsPerFrame();  /* flip it later. */
+            if (!VideoSurfacePresentTicks) {
+                VideoSurfacePresentTicks = VideoSurfaceLastPresentTicks + GetDesiredMillisecondsPerFrame();  /* flip it later. */
+            } else if (SDL_TICKS_PASSED(SDL20_GetTicks(), VideoSurfacePresentTicks)) {
+                PresentScreen();
+            }
         }
 
         if (renderer) {
@@ -7828,9 +7832,14 @@ SDL_Delay(Uint32 ticks)
 {
     /* In case there's a loading screen from a background thread and the main thread is waiting... */
     const SDL_bool ThisIsSetVideoModeThread = (SDL20_ThreadID() == SetVideoModeThread) ? SDL_TRUE : SDL_FALSE;
-    if (ThisIsSetVideoModeThread && VideoSurfaceUpdatedInBackgroundThread) {
-        SDL_Flip(VideoSurface12);  /* this will update the texture and present. */
+    if (ThisIsSetVideoModeThread) {
+        if (VideoSurfaceUpdatedInBackgroundThread) {
+            SDL_Flip(VideoSurface12);  /* this will update the texture and present. */
+        } else if (VideoSurfacePresentTicks) {
+            PresentScreen();
+        }
     }
+
     SDL20_Delay(ticks);
 }