SDL: Remove _THIS in src/video and in src/events (also VideoDevice)

From 81ff49f4b5e07144a52c2734a58803c7e78bb6e7 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Tue, 9 May 2023 12:55:11 +0200
Subject: [PATCH] Remove _THIS in src/video and in src/events (also
 VideoDevice)

---
 src/events/SDL_events.c                       |   2 +-
 src/video/SDL_egl.c                           |  42 ++---
 src/video/SDL_egl_c.h                         |  44 ++---
 src/video/SDL_sysvideo.h                      | 167 +++++++++---------
 src/video/SDL_video.c                         |   4 +-
 src/video/android/SDL_androidclipboard.c      |   6 +-
 src/video/android/SDL_androidclipboard.h      |   6 +-
 src/video/android/SDL_androidevents.c         |   4 +-
 src/video/android/SDL_androidevents.h         |   4 +-
 src/video/android/SDL_androidgl.c             |   8 +-
 src/video/android/SDL_androidgl.h             |   8 +-
 src/video/android/SDL_androidkeyboard.c       |  10 +-
 src/video/android/SDL_androidkeyboard.h       |  10 +-
 src/video/android/SDL_androidvideo.c          |  10 +-
 src/video/android/SDL_androidvulkan.c         |   8 +-
 src/video/android/SDL_androidvulkan.h         |   8 +-
 src/video/android/SDL_androidwindow.c         |  14 +-
 src/video/android/SDL_androidwindow.h         |  16 +-
 src/video/cocoa/SDL_cocoaclipboard.h          |   6 +-
 src/video/cocoa/SDL_cocoaclipboard.m          |   6 +-
 src/video/cocoa/SDL_cocoaevents.h             |   8 +-
 src/video/cocoa/SDL_cocoaevents.m             |  10 +-
 src/video/cocoa/SDL_cocoakeyboard.h           |  14 +-
 src/video/cocoa/SDL_cocoakeyboard.m           |  16 +-
 src/video/cocoa/SDL_cocoametalview.h          |   6 +-
 src/video/cocoa/SDL_cocoametalview.m          |   6 +-
 src/video/cocoa/SDL_cocoamodes.h              |  12 +-
 src/video/cocoa/SDL_cocoamodes.m              |  14 +-
 src/video/cocoa/SDL_cocoamouse.h              |   6 +-
 src/video/cocoa/SDL_cocoamouse.m              |   8 +-
 src/video/cocoa/SDL_cocoaopengl.h             |  18 +-
 src/video/cocoa/SDL_cocoaopengl.m             |  18 +-
 src/video/cocoa/SDL_cocoaopengles.h           |  14 +-
 src/video/cocoa/SDL_cocoaopengles.m           |  14 +-
 src/video/cocoa/SDL_cocoavideo.m              |   8 +-
 src/video/cocoa/SDL_cocoavulkan.h             |   8 +-
 src/video/cocoa/SDL_cocoavulkan.m             |  10 +-
 src/video/cocoa/SDL_cocoawindow.h             |  54 +++---
 src/video/cocoa/SDL_cocoawindow.m             |  56 +++---
 src/video/dummy/SDL_nullevents.c              |   2 +-
 src/video/dummy/SDL_nullevents_c.h            |   2 +-
 src/video/dummy/SDL_nullframebuffer.c         |   6 +-
 src/video/dummy/SDL_nullframebuffer_c.h       |   6 +-
 src/video/dummy/SDL_nullvideo.c               |  16 +-
 .../emscripten/SDL_emscriptenframebuffer.c    |   6 +-
 .../emscripten/SDL_emscriptenframebuffer.h    |   6 +-
 src/video/emscripten/SDL_emscriptenopengles.c |  18 +-
 src/video/emscripten/SDL_emscriptenopengles.h |  18 +-
 src/video/emscripten/SDL_emscriptenvideo.c    |  46 ++---
 src/video/haiku/SDL_bclipboard.cc             |   6 +-
 src/video/haiku/SDL_bclipboard.h              |   6 +-
 src/video/haiku/SDL_bevents.cc                |   2 +-
 src/video/haiku/SDL_bevents.h                 |   2 +-
 src/video/haiku/SDL_bframebuffer.cc           |   6 +-
 src/video/haiku/SDL_bframebuffer.h            |   6 +-
 src/video/haiku/SDL_bmodes.cc                 |  10 +-
 src/video/haiku/SDL_bmodes.h                  |  10 +-
 src/video/haiku/SDL_bopengl.cc                |  20 +--
 src/video/haiku/SDL_bopengl.h                 |  20 +--
 src/video/haiku/SDL_bvideo.cc                 |   6 +-
 src/video/haiku/SDL_bvideo.h                  |   6 +-
 src/video/haiku/SDL_bwindow.cc                |  38 ++--
 src/video/haiku/SDL_bwindow.h                 |  36 ++--
 src/video/kmsdrm/SDL_kmsdrmevents.c           |   2 +-
 src/video/kmsdrm/SDL_kmsdrmevents.h           |   6 +-
 src/video/kmsdrm/SDL_kmsdrmmouse.c            |   6 +-
 src/video/kmsdrm/SDL_kmsdrmmouse.h            |   6 +-
 src/video/kmsdrm/SDL_kmsdrmopengles.c         |  10 +-
 src/video/kmsdrm/SDL_kmsdrmopengles.h         |  12 +-
 src/video/kmsdrm/SDL_kmsdrmvideo.c            |  54 +++---
 src/video/kmsdrm/SDL_kmsdrmvideo.h            |  62 +++----
 src/video/kmsdrm/SDL_kmsdrmvulkan.c           |   8 +-
 src/video/kmsdrm/SDL_kmsdrmvulkan.h           |   8 +-
 src/video/n3ds/SDL_n3dsevents.c               |   2 +-
 src/video/n3ds/SDL_n3dsevents_c.h             |   2 +-
 src/video/n3ds/SDL_n3dsframebuffer.c          |   6 +-
 src/video/n3ds/SDL_n3dsframebuffer_c.h        |   6 +-
 src/video/n3ds/SDL_n3dsswkb.c                 |   6 +-
 src/video/n3ds/SDL_n3dsswkb.h                 |   6 +-
 src/video/n3ds/SDL_n3dsvideo.c                |  20 +--
 src/video/ngage/SDL_ngageevents.cpp           |  12 +-
 src/video/ngage/SDL_ngageevents_c.h           |   2 +-
 src/video/ngage/SDL_ngageframebuffer.cpp      |  22 +--
 src/video/ngage/SDL_ngageframebuffer_c.h      |   6 +-
 src/video/ngage/SDL_ngagevideo.cpp            |   8 +-
 src/video/ngage/SDL_ngagevideo.h              |   2 +-
 src/video/ngage/SDL_ngagewindow.cpp           |  12 +-
 src/video/ngage/SDL_ngagewindow.h             |   4 +-
 src/video/offscreen/SDL_offscreenevents.c     |   2 +-
 src/video/offscreen/SDL_offscreenevents_c.h   |   2 +-
 .../offscreen/SDL_offscreenframebuffer.c      |   6 +-
 .../offscreen/SDL_offscreenframebuffer_c.h    |   6 +-
 src/video/offscreen/SDL_offscreenopengles.c   |   8 +-
 src/video/offscreen/SDL_offscreenopengles.h   |   8 +-
 src/video/offscreen/SDL_offscreenvideo.c      |  12 +-
 src/video/offscreen/SDL_offscreenwindow.c     |   4 +-
 src/video/offscreen/SDL_offscreenwindow.h     |   4 +-
 src/video/ps2/SDL_ps2video.c                  |  10 +-
 src/video/psp/SDL_pspevents.c                 |   8 +-
 src/video/psp/SDL_pspevents_c.h               |   4 +-
 src/video/psp/SDL_pspgl.c                     |  18 +-
 src/video/psp/SDL_pspgl_c.h                   |  18 +-
 src/video/psp/SDL_pspvideo.c                  |  40 ++---
 src/video/psp/SDL_pspvideo.h                  |  58 +++---
 src/video/qnx/SDL_qnx.h                       |  16 +-
 src/video/qnx/SDL_qnxgl.c                     |  30 ++--
 src/video/qnx/SDL_qnxvideo.c                  |  38 ++--
 src/video/raspberry/SDL_rpievents.c           |   2 +-
 src/video/raspberry/SDL_rpievents_c.h         |   6 +-
 src/video/raspberry/SDL_rpimouse.c            |   4 +-
 src/video/raspberry/SDL_rpimouse.h            |   4 +-
 src/video/raspberry/SDL_rpiopengles.c         |   6 +-
 src/video/raspberry/SDL_rpiopengles.h         |  10 +-
 src/video/raspberry/SDL_rpivideo.c            |  28 +--
 src/video/raspberry/SDL_rpivideo.h            |  50 +++---
 src/video/riscos/SDL_riscosevents.c           |  10 +-
 src/video/riscos/SDL_riscosevents_c.h         |   6 +-
 src/video/riscos/SDL_riscosframebuffer.c      |   6 +-
 src/video/riscos/SDL_riscosframebuffer_c.h    |   6 +-
 src/video/riscos/SDL_riscosmodes.c            |   6 +-
 src/video/riscos/SDL_riscosmodes.h            |   6 +-
 src/video/riscos/SDL_riscosmouse.c            |   4 +-
 src/video/riscos/SDL_riscosmouse.h            |   2 +-
 src/video/riscos/SDL_riscosvideo.c            |   8 +-
 src/video/riscos/SDL_riscoswindow.c           |   6 +-
 src/video/riscos/SDL_riscoswindow.h           |   6 +-
 src/video/uikit/SDL_uikitclipboard.h          |  10 +-
 src/video/uikit/SDL_uikitclipboard.m          |  10 +-
 src/video/uikit/SDL_uikitevents.h             |   2 +-
 src/video/uikit/SDL_uikitevents.m             |   2 +-
 src/video/uikit/SDL_uikitmetalview.h          |   6 +-
 src/video/uikit/SDL_uikitmetalview.m          |   6 +-
 src/video/uikit/SDL_uikitmodes.h              |  10 +-
 src/video/uikit/SDL_uikitmodes.m              |  10 +-
 src/video/uikit/SDL_uikitopengles.h           |  12 +-
 src/video/uikit/SDL_uikitopengles.m           |  12 +-
 src/video/uikit/SDL_uikitvideo.h              |   2 +-
 src/video/uikit/SDL_uikitvideo.m              |  10 +-
 src/video/uikit/SDL_uikitviewcontroller.h     |  10 +-
 src/video/uikit/SDL_uikitviewcontroller.m     |  10 +-
 src/video/uikit/SDL_uikitvulkan.h             |   8 +-
 src/video/uikit/SDL_uikitvulkan.m             |   8 +-
 src/video/uikit/SDL_uikitwindow.h             |  24 +--
 src/video/uikit/SDL_uikitwindow.m             |  28 +--
 src/video/vita/SDL_vitaframebuffer.c          |   6 +-
 src/video/vita/SDL_vitaframebuffer.h          |   6 +-
 src/video/vita/SDL_vitagl_pvr.c               |   6 +-
 src/video/vita/SDL_vitagl_pvr_c.h             |   6 +-
 src/video/vita/SDL_vitagles.c                 |  18 +-
 src/video/vita/SDL_vitagles_c.h               |  18 +-
 src/video/vita/SDL_vitagles_pvr.c             |   8 +-
 src/video/vita/SDL_vitagles_pvr_c.h           |   8 +-
 src/video/vita/SDL_vitavideo.c                |  40 ++---
 src/video/vita/SDL_vitavideo.h                |  68 +++----
 src/video/vivante/SDL_vivanteopengles.c       |   2 +-
 src/video/vivante/SDL_vivanteopengles.h       |   8 +-
 src/video/vivante/SDL_vivanteplatform.c       |   8 +-
 src/video/vivante/SDL_vivanteplatform.h       |   8 +-
 src/video/vivante/SDL_vivantevideo.c          |  24 +--
 src/video/vivante/SDL_vivantevideo.h          |  26 +--
 src/video/vivante/SDL_vivantevulkan.c         |   8 +-
 src/video/vivante/SDL_vivantevulkan.h         |   8 +-
 src/video/wayland/SDL_waylandclipboard.c      |  12 +-
 src/video/wayland/SDL_waylandclipboard.h      |  12 +-
 src/video/wayland/SDL_waylanddatamanager.h    |   4 +-
 src/video/wayland/SDL_waylandevents.c         |  10 +-
 src/video/wayland/SDL_waylandevents_c.h       |   6 +-
 src/video/wayland/SDL_waylandkeyboard.c       |  12 +-
 src/video/wayland/SDL_waylandkeyboard.h       |  12 +-
 src/video/wayland/SDL_waylandopengles.c       |  16 +-
 src/video/wayland/SDL_waylandopengles.h       |  16 +-
 src/video/wayland/SDL_waylandvideo.c          |  16 +-
 src/video/wayland/SDL_waylandvideo.h          |   2 +-
 src/video/wayland/SDL_waylandvulkan.c         |   8 +-
 src/video/wayland/SDL_waylandvulkan.h         |   8 +-
 src/video/wayland/SDL_waylandwindow.c         |  50 +++---
 src/video/wayland/SDL_waylandwindow.h         |  50 +++---
 src/video/windows/SDL_windowsclipboard.c      |   8 +-
 src/video/windows/SDL_windowsclipboard.h      |   6 +-
 src/video/windows/SDL_windowsevents.c         |   6 +-
 src/video/windows/SDL_windowsevents.h         |   6 +-
 src/video/windows/SDL_windowsframebuffer.c    |   6 +-
 src/video/windows/SDL_windowsframebuffer.h    |   6 +-
 src/video/windows/SDL_windowskeyboard.c       |  18 +-
 src/video/windows/SDL_windowskeyboard.h       |  14 +-
 src/video/windows/SDL_windowsmodes.c          |  24 +--
 src/video/windows/SDL_windowsmodes.h          |  14 +-
 src/video/windows/SDL_windowsmouse.c          |   4 +-
 src/video/windows/SDL_windowsmouse.h          |   4 +-
 src/video/windows/SDL_windowsopengl.c         |  34 ++--
 src/video/windows/SDL_windowsopengl.h         |  26 +--
 src/video/windows/SDL_windowsopengles.c       |  10 +-
 src/video/windows/SDL_windowsopengles.h       |  14 +-
 src/video/windows/SDL_windowsvideo.c          |  26 +--
 src/video/windows/SDL_windowsvideo.h          |   2 +-
 src/video/windows/SDL_windowsvulkan.c         |   8 +-
 src/video/windows/SDL_windowsvulkan.h         |   8 +-
 src/video/windows/SDL_windowswindow.c         |  58 +++---
 src/video/windows/SDL_windowswindow.h         |  54 +++---
 src/video/winrt/SDL_winrtevents.cpp           |   2 +-
 src/video/winrt/SDL_winrtevents_c.h           |  14 +-
 src/video/winrt/SDL_winrtgamebar.cpp          |   4 +-
 src/video/winrt/SDL_winrtgamebar_cpp.h        |   4 +-
 src/video/winrt/SDL_winrtkeyboard.cpp         |  10 +-
 src/video/winrt/SDL_winrtmouse.cpp            |   4 +-
 src/video/winrt/SDL_winrtmouse_c.h            |   4 +-
 src/video/winrt/SDL_winrtopengles.cpp         |   4 +-
 src/video/winrt/SDL_winrtopengles.h           |  10 +-
 src/video/winrt/SDL_winrtpointerinput.cpp     |   2 +-
 src/video/winrt/SDL_winrtvideo.cpp            |  48 ++---
 src/video/x11/SDL_x11clipboard.c              |  18 +-
 src/video/x11/SDL_x11clipboard.h              |  12 +-
 src/video/x11/SDL_x11events.c                 |  30 ++--
 src/video/x11/SDL_x11events.h                 |  10 +-
 src/video/x11/SDL_x11framebuffer.c            |   6 +-
 src/video/x11/SDL_x11framebuffer.h            |   6 +-
 src/video/x11/SDL_x11keyboard.c               |  28 +--
 src/video/x11/SDL_x11keyboard.h               |  22 +--
 src/video/x11/SDL_x11modes.c                  |  22 +--
 src/video/x11/SDL_x11modes.h                  |  14 +-
 src/video/x11/SDL_x11mouse.c                  |   4 +-
 src/video/x11/SDL_x11mouse.h                  |   4 +-
 src/video/x11/SDL_x11opengl.c                 |  28 +--
 src/video/x11/SDL_x11opengl.h                 |  22 +--
 src/video/x11/SDL_x11opengles.c               |   8 +-
 src/video/x11/SDL_x11opengles.h               |  12 +-
 src/video/x11/SDL_x11touch.c                  |   6 +-
 src/video/x11/SDL_x11touch.h                  |   6 +-
 src/video/x11/SDL_x11video.c                  |  10 +-
 src/video/x11/SDL_x11vulkan.c                 |   8 +-
 src/video/x11/SDL_x11vulkan.h                 |   8 +-
 src/video/x11/SDL_x11window.c                 |  74 ++++----
 src/video/x11/SDL_x11window.h                 |  62 +++----
 src/video/x11/SDL_x11xfixes.c                 |   8 +-
 src/video/x11/SDL_x11xfixes.h                 |   8 +-
 src/video/x11/SDL_x11xinput2.c                |  10 +-
 src/video/x11/SDL_x11xinput2.h                |  10 +-
 237 files changed, 1674 insertions(+), 1675 deletions(-)

diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c
index a46b9999cb5b..5266e1d5985f 100644
--- a/src/events/SDL_events.c
+++ b/src/events/SDL_events.c
@@ -900,7 +900,7 @@ static SDL_bool SDL_events_need_periodic_poll(void)
     return need_periodic_poll;
 }
 
-static int SDL_WaitEventTimeout_Device(_THIS, SDL_Window *wakeup_window, SDL_Event *event, Uint64 start, Sint64 timeoutNS)
+static int SDL_WaitEventTimeout_Device(SDL_VideoDevice *_this, SDL_Window *wakeup_window, SDL_Event *event, Uint64 start, Sint64 timeoutNS)
 {
     Sint64 loop_timeoutNS = timeoutNS;
     SDL_bool need_periodic_poll = SDL_events_need_periodic_poll();
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 93ef45aa7f22..c59e518c89a9 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -176,7 +176,7 @@ int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint
 
 /* EGL implementation of SDL OpenGL ES support */
 
-SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext)
+SDL_bool SDL_EGL_HasExtension(SDL_VideoDevice *_this, SDL_EGL_ExtensionType type, const char *ext)
 {
     size_t ext_len;
     const char *ext_override;
@@ -248,7 +248,7 @@ SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext
     return SDL_FALSE;
 }
 
-SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(_THIS, const char *proc)
+SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(SDL_VideoDevice *_this, const char *proc)
 {
     SDL_FunctionPointer retval = NULL;
     if (_this->egl_data != NULL) {
@@ -275,7 +275,7 @@ SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(_THIS, const char *proc)
     return retval;
 }
 
-void SDL_EGL_UnloadLibrary(_THIS)
+void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this)
 {
     if (_this->egl_data) {
         if (_this->egl_data->egl_display) {
@@ -297,7 +297,7 @@ void SDL_EGL_UnloadLibrary(_THIS)
     }
 }
 
-static int SDL_EGL_LoadLibraryInternal(_THIS, const char *egl_path)
+static int SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_path)
 {
     void *egl_dll_handle = NULL, *opengl_dll_handle = NULL;
     const char *path = NULL;
@@ -468,7 +468,7 @@ static int SDL_EGL_LoadLibraryInternal(_THIS, const char *egl_path)
     return 0;
 }
 
-int SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
+int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path)
 {
     if (_this->egl_data) {
         return SDL_SetError("EGL context already created");
@@ -487,7 +487,7 @@ int SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
     return 0;
 }
 
-static void SDL_EGL_GetVersion(_THIS)
+static void SDL_EGL_GetVersion(SDL_VideoDevice *_this)
 {
     if (_this->egl_data->eglQueryString) {
         const char *egl_version = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_VERSION);
@@ -503,7 +503,7 @@ static void SDL_EGL_GetVersion(_THIS)
     }
 }
 
-int SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
+int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
 {
     int library_load_retcode = SDL_EGL_LoadLibraryOnly(_this, egl_path);
     if (library_load_retcode != 0) {
@@ -583,7 +583,7 @@ int SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_di
    valid available GPU for EGL to use.
 */
 
-int SDL_EGL_InitializeOffscreen(_THIS, int device)
+int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device)
 {
     void *egl_devices[SDL_EGL_MAX_DEVICES];
     EGLint num_egl_devices = 0;
@@ -661,7 +661,7 @@ int SDL_EGL_InitializeOffscreen(_THIS, int device)
     return 0;
 }
 
-void SDL_EGL_SetRequiredVisualId(_THIS, int visual_id)
+void SDL_EGL_SetRequiredVisualId(SDL_VideoDevice *_this, int visual_id)
 {
     _this->egl_data->egl_required_visual_id = visual_id;
 }
@@ -715,7 +715,7 @@ static Attribute all_attributes[] = {
     ATTRIBUTE(EGL_CONFORMANT),
 };
 
-static void dumpconfig(_THIS, EGLConfig config)
+static void dumpconfig(SDL_VideoDevice *_this, EGLConfig config)
 {
     int attr;
     for (attr = 0; attr < sizeof(all_attributes) / sizeof(Attribute); attr++) {
@@ -727,7 +727,7 @@ static void dumpconfig(_THIS, EGLConfig config)
 
 #endif /* DUMP_EGL_CONFIG */
 
-static int SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
+static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, SDL_bool set_config_caveat_none)
 {
     /* 64 seems nice. */
     EGLint attribs[64];
@@ -925,7 +925,7 @@ static int SDL_EGL_PrivateChooseConfig(_THIS, SDL_bool set_config_caveat_none)
     return 0;
 }
 
-int SDL_EGL_ChooseConfig(_THIS)
+int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this)
 {
     int ret;
 
@@ -950,7 +950,7 @@ int SDL_EGL_ChooseConfig(_THIS)
 }
 
 SDL_GLContext
-SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
+SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surface)
 {
     /* max 16 key+value pairs plus terminator. */
     EGLint attribs[33];
@@ -1123,7 +1123,7 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
     return (SDL_GLContext)egl_context;
 }
 
-int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
+int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context)
 {
     EGLContext egl_context = (EGLContext)context;
 
@@ -1160,7 +1160,7 @@ int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
     return 0;
 }
 
-int SDL_EGL_SetSwapInterval(_THIS, int interval)
+int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
 {
     EGLBoolean status;
 
@@ -1184,7 +1184,7 @@ int SDL_EGL_SetSwapInterval(_THIS, int interval)
     return SDL_EGL_SetError("Unable to set the EGL swap interval", "eglSwapInterval");
 }
 
-int SDL_EGL_GetSwapInterval(_THIS, int *interval)
+int SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
 {
     if (!_this->egl_data) {
         return SDL_SetError("EGL not initialized");
@@ -1194,7 +1194,7 @@ int SDL_EGL_GetSwapInterval(_THIS, int *interval)
     return 0;
 }
 
-int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
+int SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface)
 {
     if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) {
         return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers");
@@ -1202,7 +1202,7 @@ int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
     return 0;
 }
 
-int SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
+int SDL_EGL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
 {
     EGLContext egl_context = (EGLContext)context;
 
@@ -1218,7 +1218,7 @@ int SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
 }
 
 EGLSurface *
-SDL_EGL_CreateSurface(_THIS, SDL_Window *window, NativeWindowType nw)
+SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, NativeWindowType nw)
 {
 #ifdef SDL_VIDEO_DRIVER_ANDROID
     EGLint format_wanted;
@@ -1311,7 +1311,7 @@ SDL_EGL_CreateSurface(_THIS, SDL_Window *window, NativeWindowType nw)
 }
 
 EGLSurface
-SDL_EGL_CreateOffscreenSurface(_THIS, int width, int height)
+SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height)
 {
     EGLint attributes[] = {
         EGL_WIDTH, 0,
@@ -1331,7 +1331,7 @@ SDL_EGL_CreateOffscreenSurface(_THIS, int width, int height)
         attributes);
 }
 
-void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
+void SDL_EGL_DestroySurface(SDL_VideoDevice *_this, EGLSurface egl_surface)
 {
     if (!_this->egl_data) {
         return;
diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h
index d2a4aa74a843..1916e12eaab5 100644
--- a/src/video/SDL_egl_c.h
+++ b/src/video/SDL_egl_c.h
@@ -114,32 +114,32 @@ typedef enum SDL_EGL_ExtensionType
     SDL_EGL_CLIENT_EXTENSION
 } SDL_EGL_ExtensionType;
 
-extern SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext);
+extern SDL_bool SDL_EGL_HasExtension(SDL_VideoDevice *_this, SDL_EGL_ExtensionType type, const char *ext);
 
-extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
+extern int SDL_EGL_GetAttribute(SDL_VideoDevice *_this, SDL_GLattr attrib, int *value);
 /* SDL_EGL_LoadLibrary can get a display for a specific platform (EGL_PLATFORM_*)
  * or, if 0 is passed, let the implementation decide.
  */
-extern int SDL_EGL_LoadLibraryOnly(_THIS, const char *path);
-extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display, EGLenum platform);
-extern SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(_THIS, const char *proc);
-extern void SDL_EGL_UnloadLibrary(_THIS);
-extern void SDL_EGL_SetRequiredVisualId(_THIS, int visual_id);
-extern int SDL_EGL_ChooseConfig(_THIS);
-extern int SDL_EGL_SetSwapInterval(_THIS, int interval);
-extern int SDL_EGL_GetSwapInterval(_THIS, int *interval);
-extern int SDL_EGL_DeleteContext(_THIS, SDL_GLContext context);
-extern EGLSurface *SDL_EGL_CreateSurface(_THIS, SDL_Window *window, NativeWindowType nw);
-extern void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface);
-
-extern EGLSurface SDL_EGL_CreateOffscreenSurface(_THIS, int width, int height);
+extern int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *path);
+extern int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *path, NativeDisplayType native_display, EGLenum platform);
+extern SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(SDL_VideoDevice *_this, const char *proc);
+extern void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this);
+extern void SDL_EGL_SetRequiredVisualId(SDL_VideoDevice *_this, int visual_id);
+extern int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this);
+extern int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval);
+extern int SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
+extern int SDL_EGL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
+extern EGLSurface *SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, NativeWindowType nw);
+extern void SDL_EGL_DestroySurface(SDL_VideoDevice *_this, EGLSurface egl_surface);
+
+extern EGLSurface SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height);
 /* Assumes that LoadLibraryOnly() has succeeded */
-extern int SDL_EGL_InitializeOffscreen(_THIS, int device);
+extern int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device);
 
 /* These need to be wrapped to get the surface for the window by the platform GLES implementation */
-extern SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface);
-extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context);
-extern int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface);
+extern SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surface);
+extern int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context);
+extern int SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface);
 
 /* SDL Error-reporting */
 extern int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode);
@@ -148,19 +148,19 @@ extern int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName,
 /* A few of useful macros */
 
 #define SDL_EGL_SwapWindow_impl(BACKEND)                                                        \
-    int BACKEND##_GLES_SwapWindow(_THIS, SDL_Window *window)                                    \
+    int BACKEND##_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)                                    \
     {                                                                                           \
         return SDL_EGL_SwapBuffers(_this, window->driverdata->egl_surface);                     \
     }
 
 #define SDL_EGL_MakeCurrent_impl(BACKEND)                                                                                          \
-    int BACKEND##_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)                                               \
+    int BACKEND##_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)                                               \
     {                                                                                                                              \
         return SDL_EGL_MakeCurrent(_this, window ? window->driverdata->egl_surface : EGL_NO_SURFACE, context); \
     }
 
 #define SDL_EGL_CreateContext_impl(BACKEND)                                                     \
-    SDL_GLContext BACKEND##_GLES_CreateContext(_THIS, SDL_Window *window)                       \
+    SDL_GLContext BACKEND##_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)                       \
     {                                                                                           \
         return SDL_EGL_CreateContext(_this, window->driverdata->egl_surface);                   \
     }
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 567dc7a170fe..2e87dab5749f 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -155,9 +155,6 @@ struct SDL_VideoDisplay
 /* Forward declaration */
 struct SDL_SysWMinfo;
 
-/* Define the SDL video driver structure */
-#define _THIS SDL_VideoDevice *_this
-
 /* Video device flags */
 typedef enum
 {
@@ -179,18 +176,18 @@ struct SDL_VideoDevice
      * Initialize the native video subsystem, filling in the list of
      * displays for this driver, returning 0 or -1 if there's an error.
      */
-    int (*VideoInit)(_THIS);
+    int (*VideoInit)(SDL_VideoDevice *_this);
 
     /*
      * Reverse the effects VideoInit() -- called if VideoInit() fails or
      * if the application is shutting down the video subsystem.
      */
-    void (*VideoQuit)(_THIS);
+    void (*VideoQuit)(SDL_VideoDevice *_this);
 
     /*
      * Reinitialize the touch devices -- called if an unknown touch ID occurs.
      */
-    void (*ResetTouch)(_THIS);
+    void (*ResetTouch)(SDL_VideoDevice *_this);
 
     /* * * */
     /*
@@ -200,22 +197,22 @@ struct SDL_VideoDevice
     /*
      * Refresh the display list
      */
-    void (*RefreshDisplays)(_THIS);
+    void (*RefreshDisplays)(SDL_VideoDevice *_this);
 
     /*
      * Get the bounds of a display
      */
-    int (*GetDisplayBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
+    int (*GetDisplayBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
 
     /*
      * Get the usable bounds of a display (bounds minus menubar or whatever)
      */
-    int (*GetDisplayUsableBounds)(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
+    int (*GetDisplayUsableBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
 
     /*
      * Get a list of the available display modes for a display.
      */
-    int (*GetDisplayModes)(_THIS, SDL_VideoDisplay *display);
+    int (*GetDisplayModes)(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
 
     /*
      * Setting the display mode is independent of creating windows, so
@@ -223,46 +220,46 @@ struct SDL_VideoDevice
      * their data updated accordingly, including the display surfaces
      * associated with them.
      */
-    int (*SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
+    int (*SetDisplayMode)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
 
     /* * * */
     /*
      * Window functions
      */
-    int (*CreateSDLWindow)(_THIS, SDL_Window *window);
-    int (*CreateSDLWindowFrom)(_THIS, SDL_Window *window, const void *data);
-    void (*SetWindowTitle)(_THIS, SDL_Window *window);
-    int (*SetWindowIcon)(_THIS, SDL_Window *window, SDL_Surface *icon);
-    int (*SetWindowPosition)(_THIS, SDL_Window *window);
-    void (*SetWindowSize)(_THIS, SDL_Window *window);
-    void (*SetWindowMinimumSize)(_THIS, SDL_Window *window);
-    void (*SetWindowMaximumSize)(_THIS, SDL_Window *window);
-    int (*GetWindowBordersSize)(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right);
-    void (*GetWindowSizeInPixels)(_THIS, SDL_Window *window, int *w, int *h);
-    int (*SetWindowOpacity)(_THIS, SDL_Window *window, float opacity);
-    int (*SetWindowModalFor)(_THIS, SDL_Window *modal_window, SDL_Window *parent_window);
-    int (*SetWindowInputFocus)(_THIS, SDL_Window *window);
-    void (*ShowWindow)(_THIS, SDL_Window *window);
-    void (*HideWindow)(_THIS, SDL_Window *window);
-    void (*RaiseWindow)(_THIS, SDL_Window *window);
-    void (*MaximizeWindow)(_THIS, SDL_Window *window);
-    void (*MinimizeWindow)(_THIS, SDL_Window *window);
-    void (*RestoreWindow)(_THIS, SDL_Window *window);
-    void (*SetWindowBordered)(_THIS, SDL_Window *window, SDL_bool bordered);
-    void (*SetWindowResizable)(_THIS, SDL_Window *window, SDL_bool resizable);
-    void (*SetWindowAlwaysOnTop)(_THIS, SDL_Window *window, SDL_bool on_top);
-    void (*SetWindowFullscreen)(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen);
-    void *(*GetWindowICCProfile)(_THIS, SDL_Window *window, size_t *size);
-    SDL_DisplayID (*GetDisplayForWindow)(_THIS, SDL_Window *window);
-    void (*SetWindowMouseRect)(_THIS, SDL_Window *window);
-    void (*SetWindowMouseGrab)(_THIS, SDL_Window *window, SDL_bool grabbed);
-    void (*SetWindowKeyboardGrab)(_THIS, SDL_Window *window, SDL_bool grabbed);
-    void (*DestroyWindow)(_THIS, SDL_Window *window);
-    int (*CreateWindowFramebuffer)(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch);
-    int (*UpdateWindowFramebuffer)(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects);
-    void (*DestroyWindowFramebuffer)(_THIS, SDL_Window *window);
-    void (*OnWindowEnter)(_THIS, SDL_Window *window);
-    int (*FlashWindow)(_THIS, SDL_Window *window, SDL_FlashOperation operation);
+    int (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *win

(Patch may be truncated, please check the link at the top of this post.)