sdl2-compat: render API int + lock sensor / joystick (stubs)

From 7d758198a42f4e9189f3ca94eb7011dc43b673e2 Mon Sep 17 00:00:00 2001
From: Sylvain Becker <[EMAIL REDACTED]>
Date: Wed, 4 Jan 2023 12:14:15 +0100
Subject: [PATCH] render API  int +  lock sensor / joystick (stubs)

---
 src/sdl2_compat.c | 248 ++++++++++++++++++++++++++++++++++++++++++++++
 src/sdl3_syms.h   |  34 ++-----
 2 files changed, 258 insertions(+), 24 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 87d208a..ee48203 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -2838,6 +2838,254 @@ SDL_VideoQuit(void)
     SDL_QuitSubSystem(SDL_INIT_VIDEO);
 }
 
+DECLSPEC void SDLCALL 
+SDL_LockJoysticks(void)
+{
+    // FIXME    
+}
+
+DECLSPEC void SDLCALL
+SDL_UnlockJoysticks(void)
+{
+    // FIXME    
+}
+
+DECLSPEC void SDLCALL 
+SDL_LockSensors(void)
+{
+    // FIXME    
+}
+
+DECLSPEC void SDLCALL
+SDL_UnlockSensors(void)
+{
+    // FIXME    
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderDrawPoint(SDL_Renderer *renderer, int x, int y)
+{
+    SDL_FPoint fpoint;
+    fpoint.x = (float)x;
+    fpoint.y = (float)y;
+    return SDL3_RenderPoints(renderer, &fpoint, 1);
+}
+
+int SDL_RenderDrawPoints(SDL_Renderer *renderer,
+                         const SDL_Point *points, int count)
+{
+    SDL_FPoint *fpoints;
+    int i;
+    int retval;
+
+    if (points == NULL) {
+        SDL_InvalidParamError("SDL_RenderPoints(): points");
+        return -1;
+    }
+
+    fpoints = SDL_malloc(sizeof (SDL_FPoint) * count);
+    if (fpoints == NULL) {
+        return SDL_OutOfMemory();
+    }
+
+    for (i = 0; i < count; ++i) {
+        fpoints[i].x = (float)points[i].x;
+        fpoints[i].y = (float)points[i].y;
+    }
+
+    retval = SDL3_RenderPoints(renderer, fpoints, count);
+
+    SDL_free(fpoints);
+
+    return retval;
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2)
+{
+    SDL_FPoint points[2];
+    points[0].x = (float)x1;
+    points[0].y = (float)y1;
+    points[1].x = (float)x2;
+    points[1].y = (float)y2;
+    return SDL3_RenderLines(renderer, points, 2);
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderDrawLine(SDL_Renderer *renderer, int x1, int y1, int x2, int y2)
+{
+    SDL_FPoint points[2];
+    points[0].x = (float)x1;
+    points[0].y = (float)y1;
+    points[1].x = (float)x2;
+    points[1].y = (float)y2;
+    return SDL3_RenderLines(renderer, points, 2);
+}
+
+
+DECLSPEC int SDLCALL
+SDL_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
+{
+    SDL_FPoint *fpoints;
+    int i;
+    int retval;
+
+    if (points == NULL) {
+        SDL_InvalidParamError("SDL_RenderLines(): points");
+        return -1;
+    }
+
+    if (count < 2) {
+        return 0;
+    }
+
+    fpoints = SDL_malloc(sizeof (SDL_FPoint) * count);
+    if (fpoints == NULL) {
+        return SDL_OutOfMemory();
+    }
+
+    for (i = 0; i < count; ++i) {
+        fpoints[i].x = (float)points[i].x;
+        fpoints[i].y = (float)points[i].y;
+    }
+
+    retval = SDL3_RenderLines(renderer, fpoints, count);
+
+    SDL_free(fpoints);
+
+    return retval;
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderDrawRect(SDL_Renderer *renderer, const SDL_Rect *rect)
+{
+    SDL_FRect frect;
+    SDL_FRect *prect = NULL;
+
+    if (rect) {
+        frect.x = (float)rect->x;
+        frect.y = (float)rect->y;
+        frect.w = (float)rect->w;
+        frect.h = (float)rect->h;
+        prect = &frect;
+    }
+
+    return SDL3_RenderRect(renderer, prect);
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderDrawRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
+{
+    int i;
+
+    if (rects == NULL) {
+        SDL_InvalidParamError("SDL_RenderRectsFloat(): rects");
+        return -1;
+    }
+    if (count < 1) {
+        return 0;
+    }
+
+    for (i = 0; i < count; ++i) {
+        if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
+            return -1;
+        }
+    }
+    return 0;
+}
+
+
+DECLSPEC int SDLCALL
+SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_Rect *rect)
+{
+    SDL_FRect frect;
+    if (rect) {
+        frect.x = (float)rect->x;
+        frect.y = (float)rect->y;
+        frect.w = (float)rect->w;
+        frect.h = (float)rect->h;
+        return SDL3_RenderFillRect(renderer, &frect);
+    } else {
+        return SDL3_RenderFillRect(renderer, NULL);
+    }
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
+{
+    SDL_FRect *frects;
+    int i;
+    int retval;
+
+    if (rects == NULL) {
+        SDL_InvalidParamError("SDL_RenderFillRectsFloat(): rects");
+        return -1;
+    }
+    if (count < 1) {
+        return 0;
+    }
+
+    frects = SDL_malloc(sizeof (SDL_FRect) * count);
+    if (frects == NULL) {
+        return SDL_OutOfMemory();
+    }
+    for (i = 0; i < count; ++i) {
+        frects[i].x = rects[i].x;
+        frects[i].y = rects[i].y;
+        frects[i].w = rects[i].w;
+        frects[i].h = rects[i].h;
+    }
+
+    retval = SDL3_RenderFillRects(renderer, frects, count);
+
+    SDL_free(frects);
+
+    return retval;
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
+{
+    SDL_FRect dstfrect;
+    SDL_FRect *pdstfrect = NULL;
+    if (dstrect) {
+        dstfrect.x = (float)dstrect->x;
+        dstfrect.y = (float)dstrect->y;
+        dstfrect.w = (float)dstrect->w;
+        dstfrect.h = (float)dstrect->h;
+        pdstfrect = &dstfrect;
+    }
+    return SDL3_RenderTexture(renderer, texture, srcrect, pdstfrect);
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture,
+                     const SDL_Rect *srcrect, const SDL_Rect *dstrect,
+                     const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
+{
+    SDL_FRect dstfrect;
+    SDL_FRect *pdstfrect = NULL;
+    SDL_FPoint fcenter;
+    SDL_FPoint *pfcenter = NULL;
+
+    if (dstrect) {
+        dstfrect.x = (float)dstrect->x;
+        dstfrect.y = (float)dstrect->y;
+        dstfrect.w = (float)dstrect->w;
+        dstfrect.h = (float)dstrect->h;
+        pdstfrect = &dstfrect;
+    }
+
+    if (center) {
+        fcenter.x = (float)center->x;
+        fcenter.y = (float)center->y;
+        pfcenter = &fcenter;
+    }
+
+    return SDL3_RenderTextureRotated(renderer, texture, srcrect, pdstfrect, angle, pfcenter, flip);
+}
+
+
 /* SDL3 doesn't have 3dNow. */
 #if defined(__GNUC__) && defined(__i386__)
 #define cpuid(func, a, b, c, d) \
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 7945d67..8e3eb37 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -337,16 +337,6 @@ SDL3_SYM_PASSTHROUGH(int,GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c
 SDL3_SYM_PASSTHROUGH(int,SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(int,GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(int,RenderClear,(SDL_Renderer *a),(a),return)
-SDL3_SYM_RENAMED(int,RenderDrawPoint,RenderPoint,(SDL_Renderer *a, int b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderDrawPoints,RenderPoints,(SDL_Renderer *a, const SDL_Point *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderDrawLine,RenderLine,(SDL_Renderer *a, int b, int c, int d, int e),(a,b,c,d,e),return)
-SDL3_SYM_RENAMED(int,RenderDrawLines,RenderLines,(SDL_Renderer *a, const SDL_Point *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderDrawRect,RenderRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
-SDL3_SYM_RENAMED(int,RenderDrawRects,RenderRects,(SDL_Renderer *a, const SDL_Rect *b, int c),(a,b,c),return)
-SDL3_SYM_PASSTHROUGH(int,RenderFillRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
-SDL3_SYM_PASSTHROUGH(int,RenderFillRects,(SDL_Renderer *a, const SDL_Rect *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderCopy,RenderTexture,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d),(a,b,c,d),return)
-SDL3_SYM_RENAMED(int,RenderCopyEx,RenderTextureRotated,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_Rect *d, const double e, const SDL_Point *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
 SDL3_SYM_PASSTHROUGH(int,RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b, Uint32 c, void *d, int e),(a,b,c,d,e),return)
 SDL3_SYM_PASSTHROUGH(void,RenderPresent,(SDL_Renderer *a),(a),)
 SDL3_SYM_PASSTHROUGH(void,DestroyTexture,(SDL_Texture *a),(a),)
@@ -629,8 +619,6 @@ SDL3_SYM_PASSTHROUGH(void,Vulkan_UnloadLibrary,(void),(),)
 SDL3_SYM_PASSTHROUGH(SDL_bool,Vulkan_GetInstanceExtensions,(SDL_Window *a, unsigned int *b, const char **c),(a,b,c),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,LockJoysticks,(void),(),)
-SDL3_SYM_PASSTHROUGH(void,UnlockJoysticks,(void),(),)
 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)
@@ -702,16 +690,16 @@ SDL3_SYM_PASSTHROUGH(SDL_Thread*,CreateThreadWithStackSize,(SDL_ThreadFunction a
 SDL3_SYM_RENAMED(int,JoystickGetPlayerIndex,GetJoystickPlayerIndex,(SDL_Joystick *a),(a),return)
 SDL3_SYM_RENAMED(int,GameControllerGetPlayerIndex,GetGamepadPlayerIndex,(SDL_GameController *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,RenderFlush,(SDL_Renderer *a),(a),return)
-SDL3_SYM_RENAMED(int,RenderDrawPointF,RenderPointFloat,(SDL_Renderer *a, float b, float c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderDrawPointsF,RenderPointsFloat,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderDrawLineF,RenderLineFloat,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return)
-SDL3_SYM_RENAMED(int,RenderDrawLinesF,RenderLinesFloat,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderDrawRectF,RenderRectFloat,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
-SDL3_SYM_RENAMED(int,RenderDrawRectsF,RenderRectsFloat,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderFillRectF,RenderFillRectFloat,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
-SDL3_SYM_RENAMED(int,RenderFillRectsF,RenderFillRectsFloat,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderCopyF,RenderTextureFloat,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d),(a,b,c,d),return)
-SDL3_SYM_RENAMED(int,RenderCopyExF,RenderTextureRotatedFloat,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
+SDL3_SYM_RENAMED(int,RenderDrawPointF,RenderPoint,(SDL_Renderer *a, float b, float c),(a,b,c),return)
+SDL3_SYM_RENAMED(int,RenderDrawPointsF,RenderPoints,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return)
+SDL3_SYM_RENAMED(int,RenderDrawLineF,RenderLine,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return)
+SDL3_SYM_RENAMED(int,RenderDrawLinesF,RenderLines,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return)
+SDL3_SYM_RENAMED(int,RenderDrawRectF,RenderRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
+SDL3_SYM_RENAMED(int,RenderDrawRectsF,RenderRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return)
+SDL3_SYM_RENAMED(int,RenderFillRectF,RenderFillRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
+SDL3_SYM_RENAMED(int,RenderFillRectsF,RenderFillRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return)
+SDL3_SYM_RENAMED(int,RenderCopyF,RenderTexture,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d),(a,b,c,d),return)
+SDL3_SYM_RENAMED(int,RenderCopyExF,RenderTextureRotated,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
 SDL3_SYM_PASSTHROUGH(SDL_TouchDeviceType,GetTouchDeviceType,(SDL_TouchID a),(a),return)
 #ifdef __IOS__
 SDL3_SYM_PASSTHROUGH(int,UIKitRunApp,(int a, char *b, SDL_main_func c),(a,b,c),return)
@@ -760,8 +748,6 @@ SDL3_SYM_RENAMED(int,JoystickSetVirtualAxis,SetJoystickVirtualAxis,(SDL_Joystick
 SDL3_SYM_RENAMED(int,JoystickSetVirtualButton,SetJoystickVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
 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,LockSensors,(void),(),)
-SDL3_SYM_PASSTHROUGH(void,UnlockSensors,(void),(),)
 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)