libsdl-org / sdl2-compat

An SDL2 compatibility layer that uses SDL3 behind the scenes.
zlib License
65 stars 17 forks source link

failures after SDL3 enum use changes (SDL_PixelFormatEnum, in particular) #144

Closed sezero closed 4 months ago

sezero commented 4 months ago

After enum patch merges of @Susko3 in SDL3, SDL_PixelFormatEnum in particular, sdl2-compat needed adjusting. I did the following to fix the SDL3 signatures:

diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 35234d9..a1c78f8 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_RENAMED(SDL_bool,PixelFormatEnumToMasks,GetMasksForPixelFormatEnum,(SDL_PixelFormatEnum a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return)
+SDL3_SYM_RENAMED(SDL_PixelFormatEnum,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,(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_PASSTHROUGH(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)

However, signatures of SDL2 and SDL3 procedures don't match and we fail in test_sdl3_syms.cpp :

What is the correct fix here: Should we lie about the SDL2 signatures by changing them to SDL_PixelFormatEnum in dynapi/SDL_dynapi_procs.h and sdl2_protos.h? Or what?

g++ -fPIC -fvisibility=hidden -O3 -Wall -DNDEBUG -D_THREAD_SAFE -D_REENTRANT -Iinclude -o sdl2_compat.o -c sdl2_compat.c
In file included from sdl2_compat.c:143:
sdl3_syms.h: In function ‘int SDL_PremultiplyAlpha_REAL(int, int, SDL_PixelFormatEnum, const void*, int, SDL_PixelFormatEnum, void*, int)’:
sdl3_syms.h:732: error: declaration of C function ‘int SDL_PremultiplyAlpha_REAL(int, int, SDL_PixelFormatEnum, const void*, int, SDL_PixelFormatEnum, void*, int)’ conflicts with
sdl2_protos.h:912: error: previous declaration ‘int SDL_PremultiplyAlpha_REAL(int, int, Uint32, const void*, int, Uint32, void*, int)’ here
In file included from sdl2_compat.c:148:
sdl3_syms.h: In function ‘SDL_bool SDL_PixelFormatEnumToMasks_REAL(SDL_PixelFormatEnum, int*, Uint32*, Uint32*, Uint32*, Uint32*)’:
sdl3_syms.h:284: error: declaration of C function ‘SDL_bool SDL_PixelFormatEnumToMasks_REAL(SDL_PixelFormatEnum, int*, Uint32*, Uint32*, Uint32*, Uint32*)’ conflicts with
sdl2_protos.h:301: error: previous declaration ‘SDL_bool SDL_PixelFormatEnumToMasks_REAL(Uint32, int*, Uint32*, Uint32*, Uint32*, Uint32*)’ here
sdl3_syms.h: In function ‘SDL_PixelFormatEnum SDL_MasksToPixelFormatEnum_REAL(int, Uint32, Uint32, Uint32, Uint32)’:
sdl3_syms.h:285: error: declaration of C function ‘SDL_PixelFormatEnum SDL_MasksToPixelFormatEnum_REAL(int, Uint32, Uint32, Uint32, Uint32)’ conflicts with
sdl2_protos.h:302: error: previous declaration ‘Uint32 SDL_MasksToPixelFormatEnum_REAL(int, Uint32, Uint32, Uint32, Uint32)’ here
sdl3_syms.h: In function ‘SDL_PixelFormat* SDL_AllocFormat_REAL(SDL_PixelFormatEnum)’:
sdl3_syms.h:286: error: declaration of C function ‘SDL_PixelFormat* SDL_AllocFormat_REAL(SDL_PixelFormatEnum)’ conflicts with
sdl2_protos.h:303: error: previous declaration ‘SDL_PixelFormat* SDL_AllocFormat_REAL(Uint32)’ here
sdl2_compat.c: In function ‘SDL_Surface* SDL_ConvertSurfaceFormat_REAL(SDL_Surface*, Uint32, Uint32)’:
sdl2_compat.c:2606: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
sdl2_compat.c: In function ‘int SDL_ConvertPixels_REAL(int, int, Uint32, const void*, int, Uint32, void*, int)’:
sdl2_compat.c:2661: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
sdl2_compat.c:2661: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
sdl2_compat.c: In function ‘SDL_Surface* SDL_CreateRGBSurfaceWithFormat_REAL(Uint32, int, int, int, Uint32)’:
sdl2_compat.c:2673: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
sdl2_compat.c: In function ‘SDL_Surface* SDL_CreateRGBSurfaceWithFormatFrom_REAL(void*, int, int, int, int, Uint32)’:
sdl2_compat.c:2685: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
sdl2_compat.c: In function ‘int SDL_RenderReadPixels_REAL(SDL_Renderer*, const SDL_Rect*, Uint32, void*, int)’:
sdl2_compat.c:4298: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
sdl2_compat.c: In function ‘const char* SDL_GetPixelFormatName_REAL(Uint32)’:
sdl2_compat.c:6251: error: invalid conversion from ‘Uint32’ to ‘SDL_PixelFormatEnum’
make: *** [sdl2_compat.o] Error 1
Susko3 commented 4 months ago

I'm not too familiar with sdl2-compat, but couldn't you manually define functions with SDL2 signatures that call SDL3 functions.

Like how in SDL2 you have

int SDL_ShowCursor(int toggle);

but in SDL3 there are

int SDL_ShowCursor(void);
SDL_bool SDL_CursorVisible(void);
int SDL_HideCursor(void);
sezero commented 4 months ago

That's what we are doing already. The problem is, as I said, mismatching SDL2/SDL3 signatures. E.g. for SDL_PremultiplyAlpha from the preprocessor output:

   /* from sdl2_protos.h -- _REAL stuff is from dynapi.. */
extern int SDL_PremultiplyAlpha_REAL (int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h) ;
   /* function body: */
int SDL_PremultiplyAlpha_REAL (int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h) {
                                     return SDL3_PremultiplyAlpha (a,b,c,d,e,f,g,h); }

Same issue for SDL_PixelFormatEnumToMasks, SDL_MasksToPixelFormatEnum, and SDL_AllocFormat.

As for the rest, i.e. SDL_ConvertPixels, SDL_CreateRGBSurfaceWithFormat, SDL_CreateRGBSurfaceWithFormatFrom, and SDL_RenderReadPixels: We take Uint32 format from SDL2 procedure (because that's its signature) and feeded it to the SDL3 procedure who takes SDL_PixelFormatEnum and that's where g++ fails.

slouken commented 4 months ago

If I'm understanding correctly, I think we need small shim functions to cast between Uint32 and SDL_PixelFormatEnum. Once I'm done with SDL3, I I'll take a crack at handling this if you want, and ask you to review when I'm done.

sezero commented 4 months ago

If I'm understanding correctly, I think we need small shim functions to cast between Uint32 and SDL_PixelFormatEnum. Once I'm done with SDL3, I I'll take a crack at handling this if you want, and ask you to review when I'm done.

Sure, I'm on hold.

If it helps, my solution is lieing about SDL2 signatures: patch.txt (inlined below: )

```diff diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index c131018..010b580 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -307,10 +307,14 @@ SDL_DYNAPI_PROC(int,SDL_CondSignal,(SDL_cond *a),(a),return) SDL_DYNAPI_PROC(int,SDL_CondBroadcast,(SDL_cond *a),(a),return) SDL_DYNAPI_PROC(int,SDL_CondWait,(SDL_cond *a, SDL_mutex *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_CondWaitTimeout,(SDL_cond *a, SDL_mutex *b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(Uint32 a),(a),return) -SDL_DYNAPI_PROC(SDL_bool,SDL_PixelFormatEnumToMasks,(Uint32 a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(Uint32,SDL_MasksToPixelFormatEnum,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(SDL_PixelFormat*,SDL_AllocFormat,(Uint32 a),(a),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(SDL_PixelFormatEnum a),(a),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(SDL_bool,SDL_PixelFormatEnumToMasks,(SDL_PixelFormatEnum a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(SDL_PixelFormatEnum,SDL_MasksToPixelFormatEnum,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e),(a,b,c,d,e),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(SDL_PixelFormat*,SDL_AllocFormat,(SDL_PixelFormatEnum a),(a),return) SDL_DYNAPI_PROC(void,SDL_FreeFormat,(SDL_PixelFormat *a),(a),) SDL_DYNAPI_PROC(SDL_Palette*,SDL_AllocPalette,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_SetPixelFormatPalette,(SDL_PixelFormat *a, SDL_Palette *b),(a,b),return) @@ -375,7 +379,8 @@ SDL_DYNAPI_PROC(int,SDL_RenderFillRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b SDL_DYNAPI_PROC(int,SDL_RenderFillRects,(SDL_Renderer *a, const SDL_Rect *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_RenderCopy,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d),(a,b,c,d),return) SDL_DYNAPI_PROC(int,SDL_RenderCopyEx,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d, const double e, const SDL_Point *f, const SDL_FlipMode g),(a,b,c,d,e,f,g),return) -SDL_DYNAPI_PROC(int,SDL_RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b, Uint32 c, void *d, int e),(a,b,c,d,e),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(int,SDL_RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b, SDL_PixelFormatEnum c, void *d, int e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(void,SDL_RenderPresent,(SDL_Renderer *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyTexture,(SDL_Texture *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyRenderer,(SDL_Renderer *a),(a),) @@ -492,8 +497,10 @@ SDL_DYNAPI_PROC(int,SDL_GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b),( SDL_DYNAPI_PROC(SDL_bool,SDL_SetClipRect,(SDL_Surface *a, const SDL_Rect *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_GetClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),) SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurface,(SDL_Surface *a, const SDL_PixelFormat *b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormat,(SDL_Surface *a, Uint32 b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(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) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceFormat,(SDL_Surface *a, SDL_PixelFormatEnum b, Uint32 c),(a,b,c),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(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) SDL_DYNAPI_PROC(int,SDL_FillRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_FillRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return) SDL_DYNAPI_PROC(int,SDL_UpperBlit,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return) @@ -639,8 +646,10 @@ SDL_DYNAPI_PROC(int,SDL_RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b),(a,b SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGetIntegerScale,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormat,(Uint32 a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormat,(Uint32 a, int b, int c, int d, SDL_PixelFormatEnum e),(a,b,c,d,e),return) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, int e, SDL_PixelFormatEnum f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return) SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceVendor,(int a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceProduct,(int a),(a),return) @@ -924,7 +933,8 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_JoystickHasRumbleTriggers,(SDL_Joystick *a),(a),ret SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumble,(SDL_GameController *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GameControllerHasRumbleTriggers,(SDL_GameController *a),(a),return) SDL_DYNAPI_PROC(void,SDL_hid_ble_scan,(SDL_bool a),(a),) -SDL_DYNAPI_PROC(int,SDL_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) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL_DYNAPI_PROC(int,SDL_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) #ifdef SDL_PLATFORM_ANDROID SDL_DYNAPI_PROC(int,SDL_AndroidSendMessage,(Uint32 a, int b),(a,b),return) #endif diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c index eebdbbb..5a3c8d7 100644 --- a/src/sdl2_compat.c +++ b/src/sdl2_compat.c @@ -2599,8 +2599,9 @@ SDL_ConvertSurface(SDL_Surface *src, const SDL_PixelFormat *fmt, Uint32 flags) return SDL3_ConvertSurface(src, fmt); } +/* NOTE: pixel format param is Uint32 in SDL2. */ DECLSPEC SDL_Surface * SDLCALL -SDL_ConvertSurfaceFormat(SDL_Surface * src, Uint32 pixel_format, Uint32 flags) +SDL_ConvertSurfaceFormat(SDL_Surface * src, SDL_PixelFormatEnum pixel_format, Uint32 flags) { (void) flags; /* SDL3 removed the (unused) `flags` argument */ return SDL3_ConvertSurfaceFormat(src, pixel_format); @@ -2653,8 +2654,9 @@ static SDL_Colorspace GetColorspaceForFormatAndSize(Uint32 format, int width, in return SDL_COLORSPACE_SRGB; } +/* NOTE: pixel format param is Uint32 in SDL2. */ DECLSPEC int SDLCALL -SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int src_pitch, Uint32 dst_format, void *dst, int dst_pitch) +SDL_ConvertPixels(int width, int height, SDL_PixelFormatEnum src_format, const void *src, int src_pitch, SDL_PixelFormatEnum dst_format, void *dst, int dst_pitch) { SDL_Colorspace src_colorspace = GetColorspaceForFormatAndSize(src_format, width, height); SDL_Colorspace dst_colorspace = GetColorspaceForFormatAndSize(dst_format, width, height); @@ -2667,8 +2669,9 @@ SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmas return SDL3_CreateSurface(width, height, SDL3_GetPixelFormatEnumForMasks(depth, Rmask, Gmask, Bmask, Amask)); } +/* NOTE: pixel format param is Uint32 in SDL2. */ DECLSPEC SDL_Surface * SDLCALL -SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, Uint32 format) +SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, SDL_PixelFormatEnum format) { return SDL3_CreateSurface(width, height, format); } @@ -2679,8 +2682,9 @@ SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pit return SDL3_CreateSurfaceFrom(pixels, width, height, pitch, SDL3_GetPixelFormatEnumForMasks(depth, Rmask, Gmask, Bmask, Amask)); } +/* NOTE: pixel format param is Uint32 in SDL2. */ DECLSPEC SDL_Surface * SDLCALL -SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 format) +SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, int width, int height, int depth, int pitch, SDL_PixelFormatEnum format) { return SDL3_CreateSurfaceFrom(pixels, width, height, pitch, format); } @@ -4283,8 +4287,9 @@ SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float return retval < 0 ? retval : FlushRendererIfNotBatching(renderer); } +/* NOTE: pixel format param is Uint32 in SDL2. */ DECLSPEC int SDLCALL -SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 format, void *pixels, int pitch) +SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, SDL_PixelFormatEnum format, void *pixels, int pitch) { SDL_Colorspace surface_colorspace = SDL_COLORSPACE_UNKNOWN; int result = -1; @@ -5368,7 +5373,7 @@ SDL_UnlockSensors(void) struct SDL2_DisplayMode { - Uint32 format; /**< pixel format */ + SDL_PixelFormatEnum format; /**< pixel format (is Uint32 in real SDL2.) */ int w; /**< width, in screen coordinates */ int h; /**< height, in screen coordinates */ int refresh_rate; /**< refresh rate (or zero for unspecified) */ @@ -6239,8 +6244,9 @@ SDL_SetCursor(SDL_Cursor * cursor) SDL3_SetCursor(cursor); } +/* NOTE: pixel format param is Uint32 in SDL2. */ DECLSPEC const char * -SDL_GetPixelFormatName(Uint32 format) +SDL_GetPixelFormatName(SDL_PixelFormatEnum format) { switch (format) { case SDL_PIXELFORMAT_XRGB8888: diff --git a/src/sdl2_protos.h b/src/sdl2_protos.h index 5756ac7..bf9dd8c 100644 --- a/src/sdl2_protos.h +++ b/src/sdl2_protos.h @@ -297,10 +297,14 @@ SDL2_PROTO(int,CondSignal,(SDL_cond *a)) SDL2_PROTO(int,CondBroadcast,(SDL_cond *a)) SDL2_PROTO(int,CondWait,(SDL_cond *a, SDL_mutex *b)) SDL2_PROTO(int,CondWaitTimeout,(SDL_cond *a, SDL_mutex *b, Uint32 c)) -SDL2_PROTO(const char*,GetPixelFormatName,(Uint32 a)) -SDL2_PROTO(SDL_bool,PixelFormatEnumToMasks,(Uint32 a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f)) -SDL2_PROTO(Uint32,MasksToPixelFormatEnum,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e)) -SDL2_PROTO(SDL_PixelFormat*,AllocFormat,(Uint32 a)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(const char*,GetPixelFormatName,(SDL_PixelFormatEnum a)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(SDL_bool,PixelFormatEnumToMasks,(SDL_PixelFormatEnum a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(SDL_PixelFormatEnum,MasksToPixelFormatEnum,(int a, Uint32 b, Uint32 c, Uint32 d, Uint32 e)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(SDL_PixelFormat*,AllocFormat,(SDL_PixelFormatEnum a)) SDL2_PROTO(void,FreeFormat,(SDL_PixelFormat *a)) SDL2_PROTO(SDL_Palette*,AllocPalette,(int a)) SDL2_PROTO(int,SetPixelFormatPalette,(SDL_PixelFormat *a, SDL_Palette *b)) @@ -365,7 +369,8 @@ SDL2_PROTO(int,RenderFillRect,(SDL_Renderer *a, const SDL_Rect *b)) SDL2_PROTO(int,RenderFillRects,(SDL_Renderer *a, const SDL_Rect *b, int c)) SDL2_PROTO(int,RenderCopy,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d)) SDL2_PROTO(int,RenderCopyEx,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d, const double e, const SDL_Point *f, const SDL_FlipMode g)) -SDL2_PROTO(int,RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b, Uint32 c, void *d, int e)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(int,RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b, SDL_PixelFormatEnum c, void *d, int e)) SDL2_PROTO(void,RenderPresent,(SDL_Renderer *a)) SDL2_PROTO(void,DestroyTexture,(SDL_Texture *a)) SDL2_PROTO(void,DestroyRenderer,(SDL_Renderer *a)) @@ -482,8 +487,10 @@ SDL2_PROTO(int,GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b)) SDL2_PROTO(SDL_bool,SetClipRect,(SDL_Surface *a, const SDL_Rect *b)) SDL2_PROTO(void,GetClipRect,(SDL_Surface *a, SDL_Rect *b)) SDL2_PROTO(SDL_Surface*,ConvertSurface,(SDL_Surface *a, const SDL_PixelFormat *b, Uint32 c)) -SDL2_PROTO(SDL_Surface*,ConvertSurfaceFormat,(SDL_Surface *a, Uint32 b, Uint32 c)) -SDL2_PROTO(int,ConvertPixels,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(SDL_Surface*,ConvertSurfaceFormat,(SDL_Surface *a, SDL_PixelFormatEnum b, Uint32 c)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(int,ConvertPixels,(int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h)) SDL2_PROTO(int,FillRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c)) SDL2_PROTO(int,FillRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d)) SDL2_PROTO(int,UpperBlit,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d)) @@ -629,8 +636,10 @@ SDL2_PROTO(int,RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b)) SDL2_PROTO(SDL_bool,RenderGetIntegerScale,(SDL_Renderer *a)) SDL2_PROTO(Uint32,DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c)) SDL2_PROTO(void,SetWindowResizable,(SDL_Window *a, SDL_bool b)) -SDL2_PROTO(SDL_Surface*,CreateRGBSurfaceWithFormat,(Uint32 a, int b, int c, int d, Uint32 e)) -SDL2_PROTO(SDL_Surface*,CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, int e, Uint32 f)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(SDL_Surface*,CreateRGBSurfaceWithFormat,(Uint32 a, int b, int c, int d, SDL_PixelFormatEnum e)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(SDL_Surface*,CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, int e, SDL_PixelFormatEnum f)) SDL2_PROTO(SDL_bool,GetHintBoolean,(const char *a, SDL_bool b)) SDL2_PROTO(Uint16,JoystickGetDeviceVendor,(int a)) SDL2_PROTO(Uint16,JoystickGetDeviceProduct,(int a)) @@ -909,7 +918,8 @@ SDL2_PROTO(SDL_bool,JoystickHasRumbleTriggers,(SDL_Joystick *a)) SDL2_PROTO(SDL_bool,GameControllerHasRumble,(SDL_GameController *a)) SDL2_PROTO(SDL_bool,GameControllerHasRumbleTriggers,(SDL_GameController *a)) SDL2_PROTO(void,hid_ble_scan,(SDL_bool a)) -SDL2_PROTO(int,PremultiplyAlpha,(int a, int b, Uint32 c, const void *d, int e, Uint32 f, void *g, int h)) +/* NOTE: pixel format param is Uint32 in SDL2 */ +SDL2_PROTO(int,PremultiplyAlpha,(int a, int b, SDL_PixelFormatEnum c, const void *d, int e, SDL_PixelFormatEnum f, void *g, int h)) #ifdef SDL_PLATFORM_ANDROID SDL2_PROTO(int,AndroidSendMessage,(Uint32 a, int b)) #endif diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h index 35234d9..a1c78f8 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_RENAMED(SDL_bool,PixelFormatEnumToMasks,GetMasksForPixelFormatEnum,(SDL_PixelFormatEnum a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return) +SDL3_SYM_RENAMED(SDL_PixelFormatEnum,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,(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_PASSTHROUGH(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) ```