sdl2-compat: Updated for SDL3 enum changes

From 2b891e059dd8760400697baa9945f11d293a78fb Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 7 Mar 2024 10:52:26 -0800
Subject: [PATCH] Updated for SDL3 enum changes

---
 src/sdl2_compat.c | 38 +++++++++++++++++++++++++++++++-------
 src/sdl3_syms.h   | 18 +++++++++---------
 2 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index eebdbbb..e8027f5 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -2603,7 +2603,7 @@ DECLSPEC SDL_Surface * SDLCALL
 SDL_ConvertSurfaceFormat(SDL_Surface * src, Uint32 pixel_format, Uint32 flags)
 {
     (void) flags; /* SDL3 removed the (unused) `flags` argument */
-    return SDL3_ConvertSurfaceFormat(src, pixel_format);
+    return SDL3_ConvertSurfaceFormat(src, (SDL_PixelFormatEnum)pixel_format);
 }
 
 #define SDL_YUV_SD_THRESHOLD 576
@@ -2658,7 +2658,13 @@ SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int
 {
     SDL_Colorspace src_colorspace = GetColorspaceForFormatAndSize(src_format, width, height);
     SDL_Colorspace dst_colorspace = GetColorspaceForFormatAndSize(dst_format, width, height);
-    return SDL3_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, 0, src, src_pitch, dst_format, dst_colorspace, 0, dst, dst_pitch);
+    return SDL3_ConvertPixelsAndColorspace(width, height, (SDL_PixelFormatEnum)src_format, src_colorspace, 0, src, src_pitch, (SDL_PixelFormatEnum)dst_format, dst_colorspace, 0, dst, dst_pitch);
+}
+
+DECLSPEC int SDLCALL
+SDL_PremultiplyAlpha(int width, int height, Uint32 src_format, const void * src, int src_pitch, Uint32 dst_format, void * dst, int dst_pitch)
+{
+    return SDL3_PremultiplyAlpha(width, height, (SDL_PixelFormatEnum)src_format, src, src_pitch, (SDL_PixelFormatEnum)dst_format, dst, dst_pitch);
 }
 
 DECLSPEC SDL_Surface * SDLCALL
@@ -2670,7 +2676,7 @@ SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmas
 DECLSPEC SDL_Surface * SDLCALL
 SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format)
 {
-    return SDL3_CreateSurface(width, height, format);
+    return SDL3_CreateSurface(width, height, (SDL_PixelFormatEnum)format);
 }
 
 DECLSPEC SDL_Surface * SDLCALL
@@ -2682,7 +2688,7 @@ SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pit
 DECLSPEC SDL_Surface * SDLCALL
 SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format)
 {
-    return SDL3_CreateSurfaceFrom(pixels, width, height, pitch, format);
+    return SDL3_CreateSurfaceFrom(pixels, width, height, pitch, (SDL_PixelFormatEnum)format);
 }
 
 DECLSPEC int SDLCALL
@@ -4295,7 +4301,7 @@ SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 form
     }
 
     if (SDL3_GetSurfaceColorspace(surface, &surface_colorspace) == 0 &&
-        SDL3_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format->format, surface_colorspace, SDL3_GetSurfaceProperties(surface), surface->pixels, surface->pitch, format, SDL_COLORSPACE_SRGB, 0, pixels, pitch) == 0 ) {
+        SDL3_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format->format, surface_colorspace, SDL3_GetSurfaceProperties(surface), surface->pixels, surface->pitch, (SDL_PixelFormatEnum)format, SDL_COLORSPACE_SRGB, 0, pixels, pitch) == 0 ) {
         result = 0;
     }
 
@@ -5378,7 +5384,7 @@ struct SDL2_DisplayMode
 static void
 DisplayMode_2to3(const SDL2_DisplayMode *in, SDL_DisplayMode *out) {
     if (in && out) {
-        out->format = in->format;
+        out->format = (SDL_PixelFormatEnum)in->format;
         out->w = in->w;
         out->h = in->h;
         out->refresh_rate = (float) in->refresh_rate;
@@ -6239,6 +6245,18 @@ SDL_SetCursor(SDL_Cursor * cursor)
     SDL3_SetCursor(cursor);
 }
 
+DECLSPEC SDL_bool SDLCALL
+SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
+{
+    return SDL3_GetMasksForPixelFormatEnum((SDL_PixelFormatEnum)format, bpp, Rmask, Gmask, Bmask, Amask);
+}
+
+DECLSPEC Uint32 SDLCALL
+SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
+{
+    return (Uint32)SDL3_GetPixelFormatEnumForMasks(bpp, Rmask, Gmask, Bmask, Amask);
+}
+
 DECLSPEC const char *
 SDL_GetPixelFormatName(Uint32 format)
 {
@@ -6248,10 +6266,16 @@ SDL_GetPixelFormatName(Uint32 format)
     case SDL_PIXELFORMAT_XBGR8888:
         return "SDL_PIXELFORMAT_BGR888";
     default:
-        return SDL3_GetPixelFormatName(format);
+        return SDL3_GetPixelFormatName((SDL_PixelFormatEnum)format);
     }
 }
 
+DECLSPEC SDL_PixelFormat * SDLCALL
+SDL_AllocFormat(Uint32 pixel_format)
+{
+    return SDL3_CreatePixelFormat((SDL_PixelFormatEnum)pixel_format);
+}
+
 DECLSPEC void SDLCALL
 SDL_FreeFormat(SDL_PixelFormat *format)
 {
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 35234d9..3f1b876 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -280,10 +280,10 @@ SDL3_SYM_RENAMED(int,CondSignal,SignalCondition,(SDL_Condition *a),(a),return)
 SDL3_SYM_RENAMED(int,CondBroadcast,BroadcastCondition,(SDL_Condition *a),(a),return)
 SDL3_SYM_RENAMED(int,CondWait,WaitCondition,(SDL_Condition *a, SDL_Mutex *b),(a,b),return)
 SDL3_SYM(int,WaitConditionTimeout,(SDL_Condition *a, SDL_Mutex *b, Sint32 c),(a,b,c),return)
-SDL3_SYM(const char*,GetPixelFormatName,(Uint32 a),(a),return)
-SDL3_SYM_RENAMED(SDL_bool,PixelFormatEnumToMasks,GetMasksForPixelFormatEnum,(Uint32 a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
-SDL3_SYM_RENAMED(Uint32,MasksToPixelFormatEnum,GetPixelFormatEnumForMasks,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
-SDL3_SYM_RENAMED(SDL_PixelFormat*,AllocFormat,CreatePixelFormat,(Uint32 a),(a),return)
+SDL3_SYM(const char*,GetPixelFormatName,(SDL_PixelFormatEnum a),(a),return)
+SDL3_SYM(SDL_bool,GetMasksForPixelFormatEnum,(SDL_PixelFormatEnum a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
+SDL3_SYM(SDL_PixelFormatEnum,GetPixelFormatEnumForMasks,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return)
+SDL3_SYM(SDL_PixelFormat*,CreatePixelFormat,(SDL_PixelFormatEnum a),(a),return)
 SDL3_SYM(void,DestroyPixelFormat,(SDL_PixelFormat *a),(a),)
 SDL3_SYM_RENAMED(SDL_Palette*,AllocPalette,CreatePalette,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,SetPixelFormatPalette,(SDL_PixelFormat *a, SDL_Palette *b),(a,b),return)
@@ -412,8 +412,8 @@ SDL3_SYM_PASSTHROUGH(SDL_iconv_t,iconv_open,(const char *a, const char *b),(a,b)
 SDL3_SYM_PASSTHROUGH(int,iconv_close,(SDL_iconv_t a),(a),return)
 SDL3_SYM_PASSTHROUGH(size_t,iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return)
 SDL3_SYM_PASSTHROUGH(char*,iconv_string,(const char *a, const char *b, const char *c, size_t d),(a,b,c,d),return)
-SDL3_SYM(SDL_Surface*,CreateSurface,(int a, int b, Uint32 c),(a,b,c),return)
-SDL3_SYM(SDL_Surface*,CreateSurfaceFrom,(void *a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return)
+SDL3_SYM(SDL_Surface*,CreateSurface,(int a, int b, SDL_PixelFormatEnum c),(a,b,c),return)
+SDL3_SYM(SDL_Surface*,CreateSurfaceFrom,(void *a, int b, int c, int d, SDL_PixelFormatEnum e),(a,b,c,d,e),return)
 SDL3_SYM_RENAMED(void,FreeSurface,DestroySurface,(SDL_Surface *a),(a),)
 SDL3_SYM_PASSTHROUGH(int,SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(int,LockSurface,(SDL_Surface *a),(a),return)
@@ -433,8 +433,8 @@ SDL3_SYM_RENAMED(SDL_bool,SetClipRect,SetSurfaceClipRect,(SDL_Surface *a, const
 SDL3_SYM(int,GetSurfaceClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),return)
 SDL3_SYM(int,ConvertEventToRenderCoordinates,(SDL_Renderer *a, SDL_Event *b),(a,b),return)
 SDL3_SYM(SDL_Surface*,ConvertSurface,(SDL_Surface *a, const SDL_PixelFormat *b),(a,b),return)
-SDL3_SYM(SDL_Surface*,ConvertSurfaceFormat,(SDL_Surface *a, Uint32 b),(a,b),return)
-SDL3_SYM(int,ConvertPixelsAndColorspace,(int a, int b, Uint32 c, SDL_Colorspace d, SDL_PropertiesID e, const void *f, int g, Uint32 h, SDL_Colorspace i, SDL_PropertiesID j, void *k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
+SDL3_SYM(SDL_Surface*,ConvertSurfaceFormat,(SDL_Surface *a, SDL_PixelFormatEnum b),(a,b),return)
+SDL3_SYM(int,ConvertPixelsAndColorspace,(int a, int b, SDL_PixelFormatEnum c, SDL_Colorspace d, SDL_PropertiesID e, const void *f, int g, SDL_PixelFormatEnum h, SDL_Colorspace i, SDL_PropertiesID j, void *k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return)
 SDL3_SYM_RENAMED(int,FillRect,FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return)
 SDL3_SYM_RENAMED(int,FillRects,FillSurfaceRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return)
 SDL3_SYM_RENAMED(int,UpperBlit,BlitSurface,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
@@ -729,7 +729,7 @@ SDL3_SYM_PASSTHROUGH(const SDL_Rect*,GetWindowMouseRect,(SDL_Window *a),(a),retu
 SDL3_SYM(int,RenderCoordinatesFromWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return)
 SDL3_SYM(int,RenderCoordinatesToWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return)
 SDL3_SYM_PASSTHROUGH(void,hid_ble_scan,(SDL_bool a),(a),)
-SDL3_SYM_PASSTHROUGH(int,PremultiplyAlpha,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h),(a,b,c,d,e,f,g,h),return)
+SDL3_SYM(int,PremultiplyAlpha,(int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h),(a,b,c,d,e,f,g,h),return)
 SDL3_SYM(const char*,GetTouchDeviceName,(SDL_TouchID a),(a),return)
 SDL3_SYM_PASSTHROUGH(void,ClearComposition,(void),(),)
 SDL3_SYM_RENAMED(SDL_bool,IsTextInputShown,TextInputShown,(void),(),return)