SDL: Removed SDL_HINT_VIDEO_EXTERNAL_CONTEXT

From dca2721b9196754f381d5c0e8df44daa04d48f4b Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 11 Feb 2024 19:37:16 -0800
Subject: [PATCH] Removed SDL_HINT_VIDEO_EXTERNAL_CONTEXT

This is replaced with SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT in SDL_CreateWindowWithProperties()
---
 docs/README-migration.md              |  7 ++++---
 include/SDL3/SDL_hints.h              | 13 -------------
 include/SDL3/SDL_video.h              |  6 ++++--
 src/video/SDL_sysvideo.h              |  2 +-
 src/video/SDL_video.c                 |  9 +++------
 src/video/android/SDL_androidevents.c | 11 ++++-------
 6 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 50ddd3ec1fb2..49a70d1cc126 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -712,11 +712,12 @@ The following hints have been removed:
 * SDL_HINT_RENDER_LOGICAL_SIZE_MODE - the logical size mode is explicitly set with SDL_SetRenderLogicalPresentation()
 * SDL_HINT_RENDER_OPENGL_SHADERS - shaders are always used if they are available
 * SDL_HINT_RENDER_SCALE_QUALITY - textures now default to linear filtering, use SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST) if you want nearest pixel mode instead
+* SDL_HINT_VIDEO_EXTERNAL_CONTEXT - replaced with SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT in SDL_CreateWindowWithProperties()
 * SDL_HINT_THREAD_STACK_SIZE - the stack size can be specified using SDL_CreateThreadWithStackSize()
-* SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL - replaced with the "opengl" property in SDL_CreateWindowWithProperties()
-* SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN - replaced with the "vulkan" property in SDL_CreateWindowWithProperties()
+* SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL - replaced with SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN in SDL_CreateWindowWithProperties()
+* SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN - replaced with SDL_PROP_WINDOW_CREATE_VULKAN_BOOLEAN in SDL_CreateWindowWithProperties()
 * SDL_HINT_VIDEO_HIGHDPI_DISABLED - high DPI support is always enabled
-* SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT - replaced with the "win32.pixel_format_hwnd" in SDL_CreateWindowWithProperties()
+* SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT - replaced with SDL_PROP_WINDOW_CREATE_WIN32_PIXEL_FORMAT_HWND_POINTER in SDL_CreateWindowWithProperties()
 * SDL_HINT_VIDEO_X11_FORCE_EGL - use SDL_HINT_VIDEO_FORCE_EGL instead
 * SDL_HINT_VIDEO_X11_XINERAMA - Xinerama no longer supported by the X11 backend
 * SDL_HINT_VIDEO_X11_XVIDMODE - Xvidmode no longer supported by the X11 backend
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index b9ed452ee229..1e4fd9f83ef7 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -1990,19 +1990,6 @@ extern "C" {
  */
 #define SDL_HINT_VIDEO_EGL_ALLOW_GETDISPLAY_FALLBACK "SDL_VIDEO_EGL_GETDISPLAY_FALLBACK"
 
-/**
- * A variable controlling whether the default graphics context should be initialized.
- *
- * By default a window will be created with the appropriate flags (SDL_WINDOW_OPENGL or SDL_WINDOW_METAL) for the current platform.
- *
- * The variable can be set to the following values:
- *   "0"       - SDL will manage graphics contexts that are attached to windows.
- *   "1"       - Disable graphics context management on windows.
- *
- * This hint should be set before creating a window.
- */
-#define SDL_HINT_VIDEO_EXTERNAL_CONTEXT    "SDL_VIDEO_EXTERNAL_CONTEXT"
-
 /**
  * A variable controlling whether the OpenGL context should be created with EGL.
  *
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index 60c067d5c725..b8ba36b25ce4 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -842,6 +842,7 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, in
  *   be always on top
  * - `SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN`: true if the window has no
  *   window decoration
+ * - `SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN`: true if the window will be used with an externally managed graphics context.
  * - `SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN`: true if the window should
  *   accept keyboard input (defaults true)
  * - `SDL_PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN`: true if the window should
@@ -945,13 +946,14 @@ extern DECLSPEC SDL_Window *SDLCALL SDL_CreatePopupWindow(SDL_Window *parent, in
  */
 extern DECLSPEC SDL_Window *SDLCALL SDL_CreateWindowWithProperties(SDL_PropertiesID props);
 
-#define SDL_PROP_WINDOW_CREATE_ALWAYS_ON_TOP_BOOLEAN               "always-on-top"
+#define SDL_PROP_WINDOW_CREATE_ALWAYS_ON_TOP_BOOLEAN               "always_on_top"
 #define SDL_PROP_WINDOW_CREATE_BORDERLESS_BOOLEAN                  "borderless"
 #define SDL_PROP_WINDOW_CREATE_FOCUSABLE_BOOLEAN                   "focusable"
+#define SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN   "external_graphics_context"
 #define SDL_PROP_WINDOW_CREATE_FULLSCREEN_BOOLEAN                  "fullscreen"
 #define SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER                       "height"
 #define SDL_PROP_WINDOW_CREATE_HIDDEN_BOOLEAN                      "hidden"
-#define SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN          "high-pixel-density"
+#define SDL_PROP_WINDOW_CREATE_HIGH_PIXEL_DENSITY_BOOLEAN          "high_pixel_density"
 #define SDL_PROP_WINDOW_CREATE_MAXIMIZED_BOOLEAN                   "maximized"
 #define SDL_PROP_WINDOW_CREATE_MENU_BOOLEAN                        "menu"
 #define SDL_PROP_WINDOW_CREATE_METAL_BOOLEAN                       "metal"
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 7b7409c0715a..4eb861c3f37f 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -49,6 +49,7 @@ struct SDL_Window
     Uint32 flags;
     Uint32 pending_flags;
     float display_scale;
+    SDL_bool external_graphics_context;
     SDL_bool fullscreen_exclusive;  /* The window is currently fullscreen exclusive */
     SDL_DisplayID last_fullscreen_exclusive_display;  /* The last fullscreen_exclusive display */
     SDL_DisplayID last_displayID;
@@ -487,7 +488,6 @@ extern VideoBootStrap QNX_bootstrap;
 /* Use SDL_OnVideoThread() sparingly, to avoid regressions in use cases that currently happen to work */
 extern SDL_bool SDL_OnVideoThread(void);
 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
-extern SDL_bool SDL_IsVideoContextExternal(void);
 extern void SDL_SetSystemTheme(SDL_SystemTheme theme);
 extern SDL_DisplayID SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode);
 extern SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index a2f91a94a181..87f8f9b4646b 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -627,11 +627,6 @@ SDL_bool SDL_OnVideoThread(void)
     return (_this && SDL_GetCurrentThreadID() == _this->thread);
 }
 
-SDL_bool SDL_IsVideoContextExternal(void)
-{
-    return SDL_GetHintBoolean(SDL_HINT_VIDEO_EXTERNAL_CONTEXT, SDL_FALSE);
-}
-
 void SDL_SetSystemTheme(SDL_SystemTheme theme)
 {
     if (_this && theme != _this->system_theme) {
@@ -2005,6 +2000,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
     Uint32 type_flags, graphics_flags;
     SDL_bool undefined_x = SDL_FALSE;
     SDL_bool undefined_y = SDL_FALSE;
+    SDL_bool external_graphics_context = SDL_GetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_EXTERNAL_GRAPHICS_CONTEXT_BOOLEAN, SDL_FALSE);
 
     if (!_this) {
         /* Initialize the video system if needed */
@@ -2092,7 +2088,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
     }
 
     /* Some platforms have certain graphics backends enabled by default */
-    if (!graphics_flags && !SDL_IsVideoContextExternal()) {
+    if (!graphics_flags && !external_graphics_context) {
         flags |= SDL_DefaultGraphicsBackends(_this);
     }
 
@@ -2153,6 +2149,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props)
     window->next = _this->windows;
     window->is_destroying = SDL_FALSE;
     window->last_displayID = SDL_GetDisplayForWindow(window);
+    window->external_graphics_context = external_graphics_context;
 
     if (_this->windows) {
         _this->windows->prev = window;
diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c
index 6f92e347eca2..95ad8ead48e5 100644
--- a/src/video/android/SDL_androidevents.c
+++ b/src/video/android/SDL_androidevents.c
@@ -96,11 +96,9 @@ void Android_PumpEvents_Blocking(SDL_VideoDevice *_this)
     SDL_VideoData *videodata = _this->driverdata;
 
     if (videodata->isPaused) {
-        SDL_bool isContextExternal = SDL_IsVideoContextExternal();
-
 #ifdef SDL_VIDEO_OPENGL_EGL
         /* Make sure this is the last thing we do before pausing */
-        if (!isContextExternal) {
+        if (!Android_Window->external_graphics_context) {
             SDL_LockMutex(Android_ActivityMutex);
             android_egl_context_backup(Android_Window);
             SDL_UnlockMutex(Android_ActivityMutex);
@@ -124,7 +122,7 @@ void Android_PumpEvents_Blocking(SDL_VideoDevice *_this)
 
             /* Restore the GL Context from here, as this operation is thread dependent */
 #ifdef SDL_VIDEO_OPENGL_EGL
-            if (!isContextExternal && !SDL_HasEvent(SDL_EVENT_QUIT)) {
+            if (!Android_Window->external_graphics_context && !SDL_HasEvent(SDL_EVENT_QUIT)) {
                 SDL_LockMutex(Android_ActivityMutex);
                 android_egl_context_restore(Android_Window);
                 SDL_UnlockMutex(Android_ActivityMutex);
@@ -170,11 +168,10 @@ void Android_PumpEvents_NonBlocking(SDL_VideoDevice *_this)
 
     if (videodata->isPaused) {
 
-        SDL_bool isContextExternal = SDL_IsVideoContextExternal();
         if (backup_context) {
 
 #ifdef SDL_VIDEO_OPENGL_EGL
-            if (!isContextExternal) {
+            if (!Android_Window->external_graphics_context) {
                 SDL_LockMutex(Android_ActivityMutex);
                 android_egl_context_backup(Android_Window);
                 SDL_UnlockMutex(Android_ActivityMutex);
@@ -205,7 +202,7 @@ void Android_PumpEvents_NonBlocking(SDL_VideoDevice *_this)
 
 #ifdef SDL_VIDEO_OPENGL_EGL
             /* Restore the GL Context from here, as this operation is thread dependent */
-            if (!isContextExternal && !SDL_HasEvent(SDL_EVENT_QUIT)) {
+            if (!Android_Window->external_graphics_context && !SDL_HasEvent(SDL_EVENT_QUIT)) {
                 SDL_LockMutex(Android_ActivityMutex);
                 android_egl_context_restore(Android_Window);
                 SDL_UnlockMutex(Android_ActivityMutex);