SDL: video: Don't add SDL_WINDOW_(METAL|OPENGL) to new windows if unsupported.

From 19ae71b2db3be88b3c363531ac015a56f62781d6 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 27 Jan 2022 11:48:32 -0500
Subject: [PATCH] video: Don't add SDL_WINDOW_(METAL|OPENGL) to new windows if
 unsupported.

Fixes #4656.

(Better than the previous fix in 3044310518dbb2d4814b32c6521f332b8d69aae5.)
---
 src/video/SDL_video.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index e5dbf5805ae..e3977831a1e 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1590,12 +1590,14 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
     }
 
     /* Some platforms have certain graphics backends enabled by default */
-    if (!_this->is_dummy && !graphics_flags && !SDL_IsVideoContextExternal()) {
+    if (!graphics_flags && !SDL_IsVideoContextExternal()) {
 #if (SDL_VIDEO_OPENGL && __MACOSX__) || (__IPHONEOS__ && !TARGET_OS_MACCATALYST) || __ANDROID__ || __NACL__
-        flags |= SDL_WINDOW_OPENGL;
+        if (_this->GL_CreateContext != NULL) {
+            flags |= SDL_WINDOW_OPENGL;
+        }
 #endif
 #if SDL_VIDEO_METAL && (TARGET_OS_MACCATALYST || __MACOSX__ || __IPHONEOS__)
-        if ((SDL_strcmp(_this->name, "cocoa") == 0) || (SDL_strcmp(_this->name, "uikit") == 0)) {
+        if (_this->Metal_CreateView != NULL) {
             flags |= SDL_WINDOW_METAL;
         }
 #endif