sdl2-compat: Fix build / add get Drawable functions

From b4b4c95d866fb4fae5b7c0245d568be68db900c1 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Sun, 29 Jan 2023 21:01:13 +0100
Subject: [PATCH] Fix build / add get Drawable functions

---
 src/sdl2_compat.c          | 26 +++++++++++++++++++++-----
 src/sdl3_include_wrapper.h | 15 ---------------
 src/sdl3_syms.h            |  3 ---
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 71d76c4..e1b2889 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -1356,7 +1356,7 @@ EventFilter3to2(void *userdata, SDL_Event *event3)
         case SDL_EVENT_WINDOW_EXPOSED:
         case SDL_EVENT_WINDOW_MOVED:
         case SDL_EVENT_WINDOW_RESIZED:
-        case SDL_EVENT_WINDOW_SIZE_CHANGED:
+        case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
         case SDL_EVENT_WINDOW_MINIMIZED:
         case SDL_EVENT_WINDOW_MAXIMIZED:
         case SDL_EVENT_WINDOW_RESTORED:
@@ -3218,8 +3218,10 @@ static void
 DisplayMode_2to3(const SDL2_DisplayMode *in, SDL_DisplayMode *out) {
     if (in && out) {
         out->format = in->format;
-        out->w = in->w;
-        out->h = in->h;
+        out->pixel_w = in->w;
+        out->pixel_h = in->h;
+        out->screen_w = in->w;
+        out->screen_h = in->h;
         out->refresh_rate = (float) in->refresh_rate;
         out->display_scale = 1.0f;
         out->driverdata = in->driverdata;
@@ -3230,8 +3232,8 @@ static void
 DisplayMode_3to2(const SDL_DisplayMode *in, SDL2_DisplayMode *out) {
     if (in && out) {
         out->format = in->format;
-        out->w = SDL3_lroundf(in->w / in->display_scale);
-        out->h = SDL3_lroundf(in->h / in->display_scale);
+        out->w = in->pixel_w;
+        out->h = in->pixel_h;
         out->refresh_rate = (int) SDL3_ceil(in->refresh_rate);
         out->driverdata = in->driverdata;
     }
@@ -4183,6 +4185,20 @@ DECLSPEC int SDLCALL SDL_ConvertAudio(SDL_AudioCVT *cvt)
     return -1;
 }
 
+DECLSPEC void SDLCALL SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h)
+{
+    SDL_GetWindowSizeInPixels(window, w, h);
+}
+
+DECLSPEC void SDLCALL SDL_Vulkan_GetDrawableSize(SDL_Window * window, int *w, int *h)
+{
+    SDL_GetWindowSizeInPixels(window, w, h);
+}
+
+DECLSPEC void SDLCALL SDL_Metal_GetDrawableSize(SDL_Window* window, int *w, int *h)
+{
+    SDL_GetWindowSizeInPixels(window, w, h);
+}
 
 #ifdef __cplusplus
 }
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 66515b2..8f33b1b 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -173,7 +173,6 @@
 #define SDL_Metal_CreateView IGNORE_THIS_VERSION_OF_SDL_Metal_CreateView
 #define SDL_Metal_DestroyView IGNORE_THIS_VERSION_OF_SDL_Metal_DestroyView
 #define SDL_Metal_GetLayer IGNORE_THIS_VERSION_OF_SDL_Metal_GetLayer
-#define SDL_Metal_GetDrawableSize IGNORE_THIS_VERSION_OF_SDL_Metal_GetDrawableSize
 #define SDL_CreateMutex IGNORE_THIS_VERSION_OF_SDL_CreateMutex
 #define SDL_LockMutex IGNORE_THIS_VERSION_OF_SDL_LockMutex
 #define SDL_TryLockMutex IGNORE_THIS_VERSION_OF_SDL_TryLockMutex
@@ -520,7 +519,6 @@
 #define SDL_EGL_GetCurrentEGLConfig IGNORE_THIS_VERSION_OF_SDL_EGL_GetCurrentEGLConfig
 #define SDL_EGL_GetWindowEGLSurface IGNORE_THIS_VERSION_OF_SDL_EGL_GetWindowEGLSurface
 #define SDL_EGL_SetEGLAttributeCallbacks IGNORE_THIS_VERSION_OF_SDL_EGL_SetEGLAttributeCallbacks
-#define SDL_GL_GetDrawableSize IGNORE_THIS_VERSION_OF_SDL_GL_GetDrawableSize
 #define SDL_GL_SetSwapInterval IGNORE_THIS_VERSION_OF_SDL_GL_SetSwapInterval
 #define SDL_GL_GetSwapInterval IGNORE_THIS_VERSION_OF_SDL_GL_GetSwapInterval
 #define SDL_GL_SwapWindow IGNORE_THIS_VERSION_OF_SDL_GL_SwapWindow
@@ -853,7 +851,6 @@
 #define SDL_Vulkan_UnloadLibrary IGNORE_THIS_VERSION_OF_SDL_Vulkan_UnloadLibrary
 #define SDL_Vulkan_GetInstanceExtensions IGNORE_THIS_VERSION_OF_SDL_Vulkan_GetInstanceExtensions
 #define SDL_Vulkan_CreateSurface IGNORE_THIS_VERSION_OF_SDL_Vulkan_CreateSurface
-#define SDL_Vulkan_GetDrawableSize IGNORE_THIS_VERSION_OF_SDL_Vulkan_GetDrawableSize
 #define SDL_LogSetAllPriority IGNORE_THIS_VERSION_OF_SDL_LogSetAllPriority
 #define SDL_LogSetPriority IGNORE_THIS_VERSION_OF_SDL_LogSetPriority
 #define SDL_LogGetPriority IGNORE_THIS_VERSION_OF_SDL_LogGetPriority
@@ -1499,10 +1496,6 @@ typedef void (__cdecl *pfnSDL_CurrentEndThread) (unsigned);
 #undef SDL_Metal_GetLayer
 #endif
 
-#ifdef SDL_Metal_GetDrawableSize
-#undef SDL_Metal_GetDrawableSize
-#endif
-
 #ifdef SDL_CreateMutex
 #undef SDL_CreateMutex
 #endif
@@ -2887,10 +2880,6 @@ typedef void (__cdecl *pfnSDL_CurrentEndThread) (unsigned);
 #undef SDL_EGL_SetEGLAttributeCallbacks
 #endif
 
-#ifdef SDL_GL_GetDrawableSize
-#undef SDL_GL_GetDrawableSize
-#endif
-
 #ifdef SDL_GL_SetSwapInterval
 #undef SDL_GL_SetSwapInterval
 #endif
@@ -4219,10 +4208,6 @@ typedef void (__cdecl *pfnSDL_CurrentEndThread) (unsigned);
 #undef SDL_Vulkan_CreateSurface
 #endif
 
-#ifdef SDL_Vulkan_GetDrawableSize
-#undef SDL_Vulkan_GetDrawableSize
-#endif
-
 #ifdef SDL_LogSetAllPriority
 #undef SDL_LogSetAllPriority
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 6e537ed..0db6969 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -537,7 +537,6 @@ SDL3_SYM_PASSTHROUGH(SDL_GLContext,GL_CreateContext,(SDL_Window *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,GL_MakeCurrent,(SDL_Window *a, SDL_GLContext b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(SDL_Window*,GL_GetCurrentWindow,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_GLContext,GL_GetCurrentContext,(void),(),return)
-SDL3_SYM_PASSTHROUGH(void,GL_GetDrawableSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
 SDL3_SYM_PASSTHROUGH(int,GL_SetSwapInterval,(int a),(a),return)
 SDL3_SYM(int,GL_GetSwapInterval,(int *a),(a),return)
 SDL3_SYM(int,GL_SwapWindow,(SDL_Window *a),(a),return)
@@ -610,7 +609,6 @@ SDL3_SYM_PASSTHROUGH(void*,Vulkan_GetVkGetInstanceProcAddr,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,Vulkan_UnloadLibrary,(void),(),)
 SDL3_SYM(SDL_bool,Vulkan_GetInstanceExtensions,(unsigned int *a, const char **b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, VkSurfaceKHR *c),(a,b,c),return)
-SDL3_SYM_PASSTHROUGH(void,Vulkan_GetDrawableSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
 SDL3_SYM_PASSTHROUGH(void,GetMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),)
 SDL3_SYM_PASSTHROUGH(int,SetMemoryFunctions,(SDL_malloc_func a, SDL_calloc_func b, SDL_realloc_func c, SDL_free_func d),(a,b,c,d),return)
 SDL3_SYM_PASSTHROUGH(int,GetNumAllocations,(void),(),return)
@@ -741,7 +739,6 @@ SDL3_SYM_RENAMED(int,JoystickSetVirtualButton,SetJoystickVirtualButton,(SDL_Joys
 SDL3_SYM_RENAMED(int,JoystickSetVirtualHat,SetJoystickVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(char*,GetErrorMsg,(char *a, int b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(void*,Metal_GetLayer,(SDL_MetalView a),(a),return)
-SDL3_SYM_PASSTHROUGH(void,Metal_GetDrawableSize,(SDL_Window *a, int *b, int *c),(a,b,c),)
 SDL3_SYM_PASSTHROUGH(double,trunc,(double a),(a),return)
 SDL3_SYM_PASSTHROUGH(float,truncf,(float a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_Locale *,GetPreferredLocales,(void),(),return)