SDL: video: check graphics flags the same way as the type flags

From 5f2a1231ddd1e08a9d03e28a3471f20b8e161547 Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Sun, 13 Nov 2022 08:00:03 +0100
Subject: [PATCH] video: check graphics flags the same way as the type flags

---
 src/video/SDL_video.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index fdfd912cd0aa..19458608b4ec 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1597,7 +1597,7 @@ SDL_Window *
 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
 {
     SDL_Window *window;
-    Uint32 type_flags, graphics_flags = flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_METAL | SDL_WINDOW_VULKAN);
+    Uint32 type_flags, graphics_flags;
 
     if (!_this) {
         /* Initialize the video system if needed */
@@ -1627,6 +1627,13 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
         return NULL;
     }
 
+    /* ensure no more than one of these flags is set */
+    graphics_flags = flags & (SDL_WINDOW_OPENGL | SDL_WINDOW_METAL | SDL_WINDOW_VULKAN);
+    if ((graphics_flags & (graphics_flags - 1)) != 0) {
+        SDL_SetError("Conflicting window flags specified");
+        return NULL;
+    }
+
     /* Some platforms have certain graphics backends enabled by default */
     if (!graphics_flags && !SDL_IsVideoContextExternal()) {
 #if (SDL_VIDEO_OPENGL && __MACOSX__) || (__IPHONEOS__ && !TARGET_OS_MACCATALYST) || __ANDROID__ || __NACL__
@@ -1656,10 +1663,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
             SDL_ContextNotSupported("Vulkan");
             return NULL;
         }
-        if (graphics_flags & SDL_WINDOW_OPENGL) {
-            SDL_SetError("Vulkan and OpenGL not supported on same window");
-            return NULL;
-        }
         if (SDL_Vulkan_LoadLibrary(NULL) < 0) {
             return NULL;
         }
@@ -1670,16 +1673,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
             SDL_ContextNotSupported("Metal");
             return NULL;
         }
-        /* 'flags' may have default flags appended, don't check against that. */
-        if (graphics_flags & SDL_WINDOW_OPENGL) {
-            SDL_SetError("Metal and OpenGL not supported on same window");
-            return NULL;
-        }
-        if (graphics_flags & SDL_WINDOW_VULKAN) {
-            SDL_SetError("Metal and Vulkan not supported on same window. "
-                         "To use MoltenVK, set SDL_WINDOW_VULKAN only.");
-            return NULL;
-        }
     }
 
     /* Unless the user has specified the high-DPI disabling hint, respect the