sdl12-compat: video: SDL_VideoModeOK shouldn't require exact dimensions.

From e9131f26205a539f35fd5dbdcc9678c031374f1f Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 3 Oct 2022 20:41:04 -0400
Subject: [PATCH] video: SDL_VideoModeOK shouldn't require exact dimensions.

1.2 (on many video backends) would allow smaller surfaces that it would
center in a larger mode, so emulate that here.

Reference Issue #228.
---
 src/SDL12_compat.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index a2c1aadd..75dd2da8 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -5117,16 +5117,21 @@ SDL_VideoModeOK(int width, int height, int bpp, Uint32 sdl12flags)
         return 0;
     }
 
+    /* if the 1.2 video backend could center a surface in a larger mode, it
+       would accept the size. Since we scale things, we will, too, even
+       without an exact width/height match. */
+
     if (!(sdl12flags & SDL12_FULLSCREEN)) {
         SDL_DisplayMode mode;
         SDL20_GetDesktopDisplayMode(VideoDisplayIndex, &mode);
-        actual_bpp = SDL_BITSPERPIXEL(mode.format);
+        if ((mode.w >= width) && (mode.h >= height)) {
+            actual_bpp = SDL_BITSPERPIXEL(mode.format);
+        }
     } else {
         for (i = 0; i < VideoModesCount; ++i) {
             VideoModeList *vmode = &VideoModes[i];
             for (j = 0; j < vmode->nummodes; ++j) {
-                if (vmode->modeslist12[j].w == width && vmode->modeslist12[j].h == height)
-                {
+                if (vmode->modeslist12[j].w >= width && vmode->modeslist12[j].h >= height) {
                     if (!vmode->format) {
                         return bpp;
                     }