sdl12-compat: SDL_ListModes: Treat formats with the same bpp as identical

From cdbf875ab8982eb9f55d9e9348e66bd600e3c7e0 Mon Sep 17 00:00:00 2001
From: David Gow <[EMAIL REDACTED]>
Date: Mon, 12 Apr 2021 11:57:56 +0800
Subject: [PATCH] SDL_ListModes: Treat formats with the same bpp as identical
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Some games do some interesting things with SDL_ListModes(),
SDL_VideoModeOK() and similar in order to choose and/or validate video

In particular, Darwinia, Defcon, and Multiwinia all take the desktop
mode's format (via SDL_GetVideoInfo()->vfmt), replace the BitsPerPixel
field with their desired bpp, and then validate that SDL_ListModes()
returns a list of modes. (It then goes on to verify the mode it selects
with SDL_VideoModeOK(), and very aggressively falls back to 800×600
windowed at 16-bit.)

With sdl12-compat, this never yields a valid mode under X11. By just
checking if there's a mode with the same bit depth (which, after all, is
what the game is really asking for), then — under X11 and XWayland —
24bpp modes are working fine (32 and 16 bpp modes aren't, which is still
a regression from SDL 1.2, but at least _something_ works.)

Note the SDL 1.2 is much more lenient still, at least under X11, where
there is only one list of modes (as X11 can't change bit depths at
runtime), and it is returned whenever the format has the same bpp as any
valid visual.
 src/SDL12_compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index a861826..6767d27 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -2886,7 +2886,7 @@ SDL_ListModes(const SDL12_PixelFormat *format12, Uint32 flags)
     for (i = 0; i < VideoModesCount; i++) {
         VideoModeList *modes = &VideoModes[i];
-        if (modes->format == fmt) {
+        if (SDL_BITSPERPIXEL(modes->format) == SDL_BITSPERPIXEL(fmt)) {
             return modes->modes12;