SDL: video: Rename SDL_GL_DeleteContext to SDL_GL_DestroyContext.

From af2dbf3ff3688828349f5e6b6b2118a63ec04623 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 10 Jul 2024 14:50:57 -0400
Subject: [PATCH] video: Rename SDL_GL_DeleteContext to SDL_GL_DestroyContext.

Turns out that there isn't a strong OpenGL naming convention for "Delete" ...
WGL offers "wglDeleteContext" but the GLX equivalent is "glxDestroyContext"
and then EGL sealed the deal by going with Destroy as well! Since it matches
SDL3 naming conventions (Create/Destroy), we're renaming it.

Fixes #10197.
---
 build-scripts/SDL_migration.cocci       |  5 +++++
 docs/README-migration.md                |  3 +++
 include/SDL3/SDL_oldnames.h             |  2 ++
 include/SDL3/SDL_video.h                |  4 ++--
 src/dynapi/SDL_dynapi.sym               |  2 +-
 src/dynapi/SDL_dynapi_overrides.h       |  2 +-
 src/dynapi/SDL_dynapi_procs.h           |  2 +-
 src/render/opengl/SDL_render_gl.c       |  8 ++++----
 src/render/opengles2/SDL_render_gles2.c |  8 ++++----
 src/video/SDL_video.c                   |  2 +-
 src/video/cocoa/SDL_cocoaopengl.m       | 10 +++++-----
 src/video/uikit/SDL_uikitopengles.m     |  2 +-
 test/testgl.c                           |  2 +-
 test/testgles.c                         |  2 +-
 test/testgles2.c                        |  2 +-
 test/testgles2_sdf.c                    |  2 +-
 16 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 67fa06af3d87e..8d2eea587dd7d 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -3501,3 +3501,8 @@ typedef SDL_PixelFormat, SDL_PackedPixelDetails;
 @@
 - SDL_SIMD_ALIGNED
 + SDL_SURFACE_SIMD_ALIGNED
+@@
+@@
+- SDL_GL_DeleteContext
++ SDL_GL_DestroyContext
+  (...)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 526b4e15b4435..9c9501a266e12 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1977,6 +1977,8 @@ SDL_GL_GetProcAddress() and SDL_EGL_GetProcAddress() now return `SDL_FunctionPoi
 
 SDL_GL_SwapWindow() returns 0 if the function succeeds or a negative error code if there was an error.
 
+SDL_GL_DeleteContext() has been renamed to SDL_GL_DestroyContext to match SDL naming conventions (and glX!). It also now returns 0 if the function succeeds or a negative error code if there was an error (it returned void in SDL2).
+
 SDL_GL_GetSwapInterval() takes the interval as an output parameter and returns 0 if the function succeeds or a negative error code if there was an error.
 
 SDL_GL_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be used in its place.
@@ -1987,6 +1989,7 @@ The SDL_WINDOW_TOOLTIP and SDL_WINDOW_POPUP_MENU window flags are now supported
 SDL_WindowFlags is used instead of Uint32 for API functions that refer to window flags, and has been extended to 64 bits.
 
 The following functions have been renamed:
+* SDL_GL_DeleteContext() => SDL_GL_DestroyContext()
 * SDL_GetClosestDisplayMode() => SDL_GetClosestFullscreenDisplayMode()
 * SDL_GetDisplayOrientation() => SDL_GetCurrentDisplayOrientation()
 * SDL_GetPointDisplayIndex() => SDL_GetDisplayForPoint()
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index c9abf8147633e..84add35ea3484 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -618,6 +618,7 @@
 #define SDL_PATCHLEVEL SDL_MICRO_VERSION
 
 /* ##SDL_video.h */
+#define SDL_GL_DeleteContext SDL_GL_DestroyContext
 #define SDL_GetClosestDisplayMode SDL_GetClosestFullscreenDisplayMode
 #define SDL_GetDisplayOrientation SDL_GetCurrentDisplayOrientation
 #define SDL_GetPointDisplayIndex SDL_GetDisplayForPoint
@@ -1215,6 +1216,7 @@
 #define SDL_PATCHLEVEL SDL_PATCHLEVEL_renamed_SDL_MICRO_VERSION
 
 /* ##SDL_video.h */
+#define SDL_GL_DeleteContext SDL_GL_DeleteContext_renamed_SDL_GL_DestroyContext
 #define SDL_GetClosestDisplayMode SDL_GetClosestDisplayMode_renamed_SDL_GetClosestFullscreenDisplayMode
 #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_renamed_SDL_GetCurrentDisplayOrientation
 #define SDL_GetPointDisplayIndex SDL_GetPointDisplayIndex_renamed_SDL_GetDisplayForPoint
diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h
index 5dcee6694ddb3..db54c9f99fa1f 100644
--- a/include/SDL3/SDL_video.h
+++ b/include/SDL3/SDL_video.h
@@ -2592,7 +2592,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
  *
  * \since This function is available since SDL 3.0.0.
  *
- * \sa SDL_GL_DeleteContext
+ * \sa SDL_GL_DestroyContext
  * \sa SDL_GL_MakeCurrent
  */
 extern SDL_DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *window);
@@ -2769,7 +2769,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GL_SwapWindow(SDL_Window *window);
  *
  * \sa SDL_GL_CreateContext
  */
-extern SDL_DECLSPEC int SDLCALL SDL_GL_DeleteContext(SDL_GLContext context);
+extern SDL_DECLSPEC int SDLCALL SDL_GL_DestroyContext(SDL_GLContext context);
 
 /* @} *//* OpenGL support functions */
 
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 79aec801d97fc..9e665952b8e01 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -140,7 +140,7 @@ SDL3_0.0.0 {
     SDL_GDKGetTaskQueue;
     SDL_GDKSuspendComplete;
     SDL_GL_CreateContext;
-    SDL_GL_DeleteContext;
+    SDL_GL_DestroyContext;
     SDL_GL_ExtensionSupported;
     SDL_GL_GetAttribute;
     SDL_GL_GetCurrentContext;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 6b1a00ae28699..e1107a0e7e99c 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -164,7 +164,7 @@
 #define SDL_GDKGetTaskQueue SDL_GDKGetTaskQueue_REAL
 #define SDL_GDKSuspendComplete SDL_GDKSuspendComplete_REAL
 #define SDL_GL_CreateContext SDL_GL_CreateContext_REAL
-#define SDL_GL_DeleteContext SDL_GL_DeleteContext_REAL
+#define SDL_GL_DestroyContext SDL_GL_DestroyContext_REAL
 #define SDL_GL_ExtensionSupported SDL_GL_ExtensionSupported_REAL
 #define SDL_GL_GetAttribute SDL_GL_GetAttribute_REAL
 #define SDL_GL_GetCurrentContext SDL_GL_GetCurrentContext_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 51be63cac93ff..2399bfc4ff305 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -183,7 +183,7 @@ SDL_DYNAPI_PROC(int,SDL_GDKGetDefaultUser,(XUserHandle *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GDKGetTaskQueue,(XTaskQueueHandle *a),(a),return)
 SDL_DYNAPI_PROC(void,SDL_GDKSuspendComplete,(void),(),)
 SDL_DYNAPI_PROC(SDL_GLContext,SDL_GL_CreateContext,(SDL_Window *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_GL_DeleteContext,(SDL_GLContext a),(a),return)
+SDL_DYNAPI_PROC(int,SDL_GL_DestroyContext,(SDL_GLContext a),(a),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_GL_ExtensionSupported,(const char *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return)
 SDL_DYNAPI_PROC(SDL_GLContext,SDL_GL_GetCurrentContext,(void),(),return)
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 6c6399ddcf14c..a4f7cd061a7c7 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -1578,7 +1578,7 @@ static void GL_DestroyRenderer(SDL_Renderer *renderer)
                 SDL_free(data->framebuffers);
                 data->framebuffers = nextnode;
             }
-            SDL_GL_DeleteContext(data->context);
+            SDL_GL_DestroyContext(data->context);
         }
         SDL_free(data);
     }
@@ -1686,12 +1686,12 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro
         goto error;
     }
     if (SDL_GL_MakeCurrent(window, data->context) < 0) {
-        SDL_GL_DeleteContext(data->context);
+        SDL_GL_DestroyContext(data->context);
         goto error;
     }
 
     if (GL_LoadFunctions(data) < 0) {
-        SDL_GL_DeleteContext(data->context);
+        SDL_GL_DestroyContext(data->context);
         goto error;
     }
 
@@ -1807,7 +1807,7 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro
             SDL_GL_GetProcAddress("glCheckFramebufferStatusEXT");
     } else {
         SDL_SetError("Can't create render targets, GL_EXT_framebuffer_object not available");
-        SDL_GL_DeleteContext(data->context);
+        SDL_GL_DestroyContext(data->context);
         goto error;
     }
 
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index cdfa9faed7cbc..b87626dc7a2d5 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -1440,7 +1440,7 @@ static void GLES2_DestroyRenderer(SDL_Renderer *renderer)
             GL_CheckError("", renderer);
 #endif
 
-            SDL_GL_DeleteContext(data->context);
+            SDL_GL_DestroyContext(data->context);
         }
 
         SDL_free(data);
@@ -2107,17 +2107,17 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_
         goto error;
     }
     if (SDL_GL_MakeCurrent(window, data->context) < 0) {
-        SDL_GL_DeleteContext(data->context);
+        SDL_GL_DestroyContext(data->context);
         goto error;
     }
 
     if (GLES2_LoadFunctions(data) < 0) {
-        SDL_GL_DeleteContext(data->context);
+        SDL_GL_DestroyContext(data->context);
         goto error;
     }
 
     if (GLES2_CacheShaders(data) < 0) {
-        SDL_GL_DeleteContext(data->context);
+        SDL_GL_DestroyContext(data->context);
         goto error;
     }
 
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 82de50bd8d384..516ac5369c407 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -4920,7 +4920,7 @@ int SDL_GL_SwapWindow(SDL_Window *window)
     return _this->GL_SwapWindow(_this, window);
 }
 
-int SDL_GL_DeleteContext(SDL_GLContext context)
+int SDL_GL_DestroyContext(SDL_GLContext context)
 {
     if (!_this) {
         return SDL_UninitializedVideo();                                       \
diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m
index 022d0786ff41e..8b067aa4218a5 100644
--- a/src/video/cocoa/SDL_cocoaopengl.m
+++ b/src/video/cocoa/SDL_cocoaopengl.m
@@ -386,7 +386,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
         [context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
 
         if (Cocoa_GL_MakeCurrent(_this, window, sdlcontext) < 0) {
-            SDL_GL_DeleteContext(sdlcontext);
+            SDL_GL_DestroyContext(sdlcontext);
             SDL_SetError("Failed making OpenGL context current");
             return NULL;
         }
@@ -400,27 +400,27 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
 
             glGetStringFunc = (const GLubyte *(APIENTRY *)(GLenum))SDL_GL_GetProcAddress("glGetString");
             if (!glGetStringFunc) {
-                SDL_GL_DeleteContext(sdlcontext);
+                SDL_GL_DestroyContext(sdlcontext);
                 SDL_SetError("Failed getting OpenGL glGetString entry point");
                 return NULL;
             }
 
             glversion = (const char *)glGetStringFunc(GL_VERSION);
             if (glversion == NULL) {
-                SDL_GL_DeleteContext(sdlcontext);
+                SDL_GL_DestroyContext(sdlcontext);
                 SDL_SetError("Failed getting OpenGL context version");
                 return NULL;
             }
 
             if (SDL_sscanf(glversion, "%d.%d", &glversion_major, &glversion_minor) != 2) {
-                SDL_GL_DeleteContext(sdlcontext);
+                SDL_GL_DestroyContext(sdlcontext);
                 SDL_SetError("Failed parsing OpenGL context version");
                 return NULL;
             }
 
             if ((glversion_major < _this->gl_config.major_version) ||
                 ((glversion_major == _this->gl_config.major_version) && (glversion_minor < _this->gl_config.minor_version))) {
-                SDL_GL_DeleteContext(sdlcontext);
+                SDL_GL_DestroyContext(sdlcontext);
                 SDL_SetError("Failed creating OpenGL context at version requested");
                 return NULL;
             }
diff --git a/src/video/uikit/SDL_uikitopengles.m b/src/video/uikit/SDL_uikitopengles.m
index afcd900463d8b..1890a33e29c70 100644
--- a/src/video/uikit/SDL_uikitopengles.m
+++ b/src/video/uikit/SDL_uikitopengles.m
@@ -60,7 +60,7 @@ SDL_FunctionPointer UIKit_GL_GetProcAddress(SDL_VideoDevice *_this, const char *
 }
 
 /*
-  note that SDL_GL_DeleteContext makes it current without passing the window
+  note that SDL_GL_DestroyContext makes it current without passing the window
 */
 int UIKit_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
 {
diff --git a/test/testgl.c b/test/testgl.c
index abbaa0743a538..cbf44ae02a237 100644
--- a/test/testgl.c
+++ b/test/testgl.c
@@ -63,7 +63,7 @@ static void quit(int rc)
 {
     if (context) {
         /* SDL_GL_MakeCurrent(0, NULL); */ /* doesn't do anything */
-        SDL_GL_DeleteContext(context);
+        SDL_GL_DestroyContext(context);
     }
     SDLTest_CommonQuit(state);
     /* Let 'main()' return normally */
diff --git a/test/testgles.c b/test/testgles.c
index 25829391da6a0..d32015f3a09ce 100644
--- a/test/testgles.c
+++ b/test/testgles.c
@@ -35,7 +35,7 @@ quit(int rc)
     if (context) {
         for (i = 0; i < state->num_windows; i++) {
             if (context[i]) {
-                SDL_GL_DeleteContext(context[i]);
+                SDL_GL_DestroyContext(context[i]);
             }
         }
 
diff --git a/test/testgles2.c b/test/testgles2.c
index c75ea84ab9045..89546ca13d3ea 100644
--- a/test/testgles2.c
+++ b/test/testgles2.c
@@ -103,7 +103,7 @@ quit(int rc)
     if (context) {
         for (i = 0; i < state->num_windows; i++) {
             if (context[i]) {
-                SDL_GL_DeleteContext(context[i]);
+                SDL_GL_DestroyContext(context[i]);
             }
         }
 
diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c
index 23c11238eada5..da8935b591c79 100644
--- a/test/testgles2_sdf.c
+++ b/test/testgles2_sdf.c
@@ -95,7 +95,7 @@ quit(int rc)
     if (context) {
         for (i = 0; i < state->num_windows; i++) {
             if (context[i]) {
-                SDL_GL_DeleteContext(context[i]);
+                SDL_GL_DestroyContext(context[i]);
             }
         }