SDL: Build with -Wfloat-conversion + fix all warnings

From a919774fe49f35094a9f7f1aac46ce249234a3e0 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Mon, 3 Jun 2024 23:33:29 +0200
Subject: [PATCH] Build with -Wfloat-conversion + fix all warnings

---
 cmake/sdlcompilers.cmake                    |   5 +
 src/camera/SDL_camera.c                     |   6 +-
 src/haptic/linux/SDL_syshaptic.c            |   2 +-
 src/joystick/apple/SDL_mfijoystick.m        |   4 +-
 src/joystick/darwin/SDL_iokitjoystick.c     |   2 +-
 src/joystick/psp/SDL_sysjoystick.c          |  22 ++--
 src/joystick/vita/SDL_sysjoystick.c         |  22 ++--
 src/power/emscripten/SDL_syspower.c         |   9 +-
 src/render/opengl/SDL_render_gl.c           |   4 +-
 src/render/psp/SDL_render_psp.c             |  10 +-
 src/render/vitagxm/SDL_render_vita_gxm.c    |   4 +-
 src/test/SDL_test_common.c                  |   2 +-
 src/video/SDL_blit_slow.c                   |   2 +-
 src/video/cocoa/SDL_cocoawindow.m           |   8 +-
 src/video/emscripten/SDL_emscriptenevents.c |   6 +-
 src/video/emscripten/SDL_emscriptenvideo.c  |  10 +-
 src/video/kmsdrm/SDL_kmsdrmmouse.c          |   2 +-
 src/video/kmsdrm/SDL_kmsdrmvulkan.c         |   2 +-
 src/video/uikit/SDL_uikitmodes.m            |  12 +-
 src/video/uikit/SDL_uikitviewcontroller.m   |   4 +-
 src/video/uikit/SDL_uikitwindow.m           |   4 +-
 src/video/vita/SDL_vitatouch.c              |   8 +-
 src/video/wayland/SDL_waylandevents.c       |  14 +--
 src/video/wayland/SDL_waylandmouse.c        |   8 +-
 src/video/wayland/SDL_waylandwindow.c       |  34 +++---
 src/video/x11/SDL_x11events.c               |   4 +-
 src/video/x11/SDL_x11modes.c                |   8 +-
 src/video/x11/SDL_x11pen.c                  |   8 +-
 src/video/x11/SDL_x11xinput2.c              |  22 ++--
 test/testautomation_audio.c                 |  20 ++--
 test/testautomation_math.c                  | 118 ++++++++++----------
 test/testautomation_suites.h                |   4 +
 test/testffmpeg.c                           |   2 +-
 test/testgles2.c                            |   2 +-
 test/testnative.c                           |   2 +-
 test/testsprite.c                           |   2 +-
 test/testspriteminimal.c                    |   2 +-
 test/testwaylandcustom.c                    |   2 +-
 38 files changed, 199 insertions(+), 203 deletions(-)

diff --git a/cmake/sdlcompilers.cmake b/cmake/sdlcompilers.cmake
index 5138fdd0b19fe..ac4db40c6b7c1 100644
--- a/cmake/sdlcompilers.cmake
+++ b/cmake/sdlcompilers.cmake
@@ -59,6 +59,11 @@ function(SDL_AddCommonCompilerFlags TARGET)
       sdl_target_compile_option_all_languages(${TARGET} "-Wundef")
     endif()
 
+    check_c_compiler_flag(-Wfloat-conversion HAVE_GCC_WFLOAT_CONVERSION)
+    if(HAVE_GCC_WFLOAT_CONVERSION)
+      sdl_target_compile_option_all_languages(${TARGET} "-Wfloat-conversion")
+    endif()
+
     check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING)
     if(HAVE_GCC_NO_STRICT_ALIASING)
       sdl_target_compile_option_all_languages(${TARGET} "-fno-strict-aliasing")
diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c
index 5b567be4eb399..22a08791e55d8 100644
--- a/src/camera/SDL_camera.c
+++ b/src/camera/SDL_camera.c
@@ -966,8 +966,8 @@ static void ChooseBestCameraSpec(SDL_CameraDevice *device, const SDL_CameraSpec
                 const int thisw = thisspec->width;
                 const int thish = thisspec->height;
                 const float thisaspect = ((float)thisw) / ((float)thish);
-                const float aspectdiff = SDL_fabs(wantaspect - thisaspect);
-                const float diff = SDL_fabs(closestaspect - thisaspect);
+                const float aspectdiff = SDL_fabsf(wantaspect - thisaspect);
+                const float diff = SDL_fabsf(closestaspect - thisaspect);
                 const int diffw = SDL_abs(thisw - wantw);
                 if (diff < epsilon) { // matches current closestaspect? See if resolution is closer in size.
                     if (diffw < closestdiffw) {
@@ -1022,7 +1022,7 @@ static void ChooseBestCameraSpec(SDL_CameraDevice *device, const SDL_CameraSpec
                 }
 
                 const float thisfps = thisspec->interval_denominator ? (thisspec->interval_numerator / thisspec->interval_denominator) : 0.0f;
-                const float fpsdiff = SDL_fabs(wantfps - thisfps);
+                const float fpsdiff = SDL_fabsf(wantfps - thisfps);
                 if (fpsdiff < closestfps) {  // this is a closest FPS? Take it until something closer arrives.
                     closestfps = fpsdiff;
                     closest->interval_numerator = thisspec->interval_numerator;
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index b80a641cc3215..f12a9e2355616 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -688,7 +688,7 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src)
         } else if (!src->dir[0]) {
             *dest = (src->dir[1] >= 0 ? 0x8000 : 0);
         } else {
-            float f = SDL_atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
+            float f = SDL_atan2f(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
             /*
               SDL_atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
                - Y-axis-value is the second coordinate (from center to SOUTH)
diff --git a/src/joystick/apple/SDL_mfijoystick.m b/src/joystick/apple/SDL_mfijoystick.m
index 97a3a83f0580e..7ff49d45035b0 100644
--- a/src/joystick/apple/SDL_mfijoystick.m
+++ b/src/joystick/apple/SDL_mfijoystick.m
@@ -1252,14 +1252,14 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
                 GCControllerDirectionPad *dpad;
 
                 dpad = controller.physicalInputProfile.dpads[GCInputDualShockTouchpadOne];
-                if (dpad.xAxis.value || dpad.yAxis.value) {
+                if (dpad.xAxis.value != 0.f || dpad.yAxis.value != 0.f) {
                     SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, SDL_PRESSED, (1.0f + dpad.xAxis.value) * 0.5f, 1.0f - (1.0f + dpad.yAxis.value) * 0.5f, 1.0f);
                 } else {
                     SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0, SDL_RELEASED, 0.0f, 0.0f, 1.0f);
                 }
 
                 dpad = controller.physicalInputProfile.dpads[GCInputDualShockTouchpadTwo];
-                if (dpad.xAxis.value || dpad.yAxis.value) {
+                if (dpad.xAxis.value != 0.f || dpad.yAxis.value != 0.f) {
                     SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, SDL_PRESSED, (1.0f + dpad.xAxis.value) * 0.5f, 1.0f - (1.0f + dpad.yAxis.value) * 0.5f, 1.0f);
                 } else {
                     SDL_SendJoystickTouchpad(timestamp, joystick, 0, 1, SDL_RELEASED, 0.0f, 0.0f, 1.0f);
diff --git a/src/joystick/darwin/SDL_iokitjoystick.c b/src/joystick/darwin/SDL_iokitjoystick.c
index 6ff8fef580b0c..9c830a82a6e2a 100644
--- a/src/joystick/darwin/SDL_iokitjoystick.c
+++ b/src/joystick/darwin/SDL_iokitjoystick.c
@@ -206,7 +206,7 @@ static SDL_bool GetHIDScaledCalibratedState(recDevice *pDevice, recElement *pEle
         if (readScale == 0) {
             returnValue = SDL_TRUE; /* no scaling at all */
         } else {
-            *pValue = ((*pValue - pElement->minReport) * deviceScale / readScale) + min;
+            *pValue = (Sint32)(((*pValue - pElement->minReport) * deviceScale / readScale) + min);
             returnValue = SDL_TRUE;
         }
     }
diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c
index 544cc758d06d5..53f7c081842b2 100644
--- a/src/joystick/psp/SDL_sysjoystick.c
+++ b/src/joystick/psp/SDL_sysjoystick.c
@@ -41,29 +41,23 @@ static const enum PspCtrlButtons button_map[] = {
 };
 static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
 
-typedef struct
-{
-    int x;
-    int y;
-} point;
-
 /* 4 points define the bezier-curve. */
-static point a = { 0, 0 };
-static point b = { 50, 0 };
-static point c = { 78, 32767 };
-static point d = { 128, 32767 };
+static SDL_Point a = { 0, 0 };
+static SDL_Point b = { 50, 0 };
+static SDL_Point c = { 78, 32767 };
+static SDL_Point d = { 128, 32767 };
 
 /* simple linear interpolation between two points */
-static SDL_INLINE void lerp(point *dest, point *pt_a, point *pt_b, float t)
+static SDL_INLINE void lerp(SDL_Point *dest, const SDL_Point *pt_a, const SDL_Point *pt_b, float t)
 {
-    dest->x = pt_a->x + (pt_b->x - pt_a->x) * t;
-    dest->y = pt_a->y + (pt_b->y - pt_a->y) * t;
+    dest->x = pt_a->x + (int)((pt_b->x - pt_a->x) * t);
+    dest->y = pt_a->y + (int)((pt_b->y - pt_a->y) * t);
 }
 
 /* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
 static int calc_bezier_y(float t)
 {
-    point ab, bc, cd, abbc, bccd, dest;
+    SDL_Point ab, bc, cd, abbc, bccd, dest;
     lerp(&ab, &a, &b, t);         /* point between a and b */
     lerp(&bc, &b, &c, t);         /* point between b and c */
     lerp(&cd, &c, &d, t);         /* point between c and d */
diff --git a/src/joystick/vita/SDL_sysjoystick.c b/src/joystick/vita/SDL_sysjoystick.c
index 09b7ab82f9c2c..fcd4f26aadaee 100644
--- a/src/joystick/vita/SDL_sysjoystick.c
+++ b/src/joystick/vita/SDL_sysjoystick.c
@@ -64,30 +64,24 @@ static const unsigned int ext_button_map[] = {
 
 static int analog_map[256]; /* Map analog inputs to -32768 -> 32767 */
 
-typedef struct
-{
-    int x;
-    int y;
-} point;
-
 /* 4 points define the bezier-curve. */
 /* The Vita has a good amount of analog travel, so use a linear curve */
-static point a = { 0, 0 };
-static point b = { 0, 0 };
-static point c = { 128, 32767 };
-static point d = { 128, 32767 };
+static SDL_Point a = { 0, 0 };
+static SDL_Point b = { 0, 0 };
+static SDL_Point c = { 128, 32767 };
+static SDL_Point d = { 128, 32767 };
 
 /* simple linear interpolation between two points */
-static SDL_INLINE void lerp(point *dest, point *first, point *second, float t)
+static SDL_INLINE void lerp(SDL_Point *dest, const SDL_Point *first, const SDL_Point *second, float t)
 {
-    dest->x = first->x + (second->x - first->x) * t;
-    dest->y = first->y + (second->y - first->y) * t;
+    dest->x = first->x + (int)((second->x - first->x) * t);
+    dest->y = first->y + (int)((second->y - first->y) * t);
 }
 
 /* evaluate a point on a bezier-curve. t goes from 0 to 1.0 */
 static int calc_bezier_y(float t)
 {
-    point ab, bc, cd, abbc, bccd, dest;
+    SDL_Point ab, bc, cd, abbc, bccd, dest;
     lerp(&ab, &a, &b, t);         /* point between a and b */
     lerp(&bc, &b, &c, t);         /* point between b and c */
     lerp(&cd, &c, &d, t);         /* point between c and d */
diff --git a/src/power/emscripten/SDL_syspower.c b/src/power/emscripten/SDL_syspower.c
index 05dec175b959e..dad87acb20d00 100644
--- a/src/power/emscripten/SDL_syspower.c
+++ b/src/power/emscripten/SDL_syspower.c
@@ -43,13 +43,14 @@ SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *state, int *seconds, int *p
         return SDL_TRUE;
     }
 
-    if (batteryState.charging)
+    if (batteryState.charging) {
         *state = batteryState.chargingTime == 0.0 ? SDL_POWERSTATE_CHARGED : SDL_POWERSTATE_CHARGING;
-    else
+    } else {
         *state = SDL_POWERSTATE_ON_BATTERY;
+    }
 
-    *seconds = batteryState.dischargingTime;
-    *percent = batteryState.level * 100;
+    *seconds = (int)batteryState.dischargingTime;
+    *percent = (int)batteryState.level * 100;
 
     return SDL_TRUE;
 }
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index e4863d042e36c..f6ebb175a4dc8 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -1047,8 +1047,8 @@ static int SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const
                          viewport->w, viewport->h);
         if (viewport->w && viewport->h) {
             data->glOrtho((GLdouble)0, (GLdouble)viewport->w,
-                          (GLdouble)istarget ? 0 : viewport->h,
-                          (GLdouble)istarget ? viewport->h : 0,
+                          (GLdouble)(istarget ? 0 : viewport->h),
+                          (GLdouble)(istarget ? viewport->h : 0),
                           0.0, 1.0);
         }
         data->glMatrixMode(GL_MODELVIEW);
diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c
index d5a38e4eca1c0..a786975ab5ce6 100644
--- a/src/render/psp/SDL_render_psp.c
+++ b/src/render/psp/SDL_render_psp.c
@@ -128,10 +128,8 @@ typedef struct
     float x, y, z;
 } VertTCV;
 
-#define PI 3.14159265358979f
-
-#define radToDeg(x) ((x)*180.f / PI)
-#define degToRad(x) ((x)*PI / 180.f)
+#define radToDeg(x) ((x)*180.f / SDL_PI_F)
+#define degToRad(x) ((x)*SDL_PI_F / 180.f)
 
 static float MathAbs(float x)
 {
@@ -809,7 +807,7 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex
         float curX = x;
         const float endX = x + width;
         const float slice = 64.0f;
-        const size_t count = SDL_ceilf(width / slice);
+        const size_t count = (size_t)SDL_ceilf(width / slice);
         size_t i;
         float ustep = (u1 - u0) / width * slice;
 
@@ -877,7 +875,7 @@ static int PSP_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_T
 
     cmd->data.draw.count = 1;
 
-    MathSincos(degToRad(360 - angle), &s, &c);
+    MathSincos(degToRad((float)(360 - angle)), &s, &c);
 
     cw1 = c * -centerx;
     sw1 = s * -centerx;
diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c
index c20206dca0bdf..7e3d656940287 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm.c
+++ b/src/render/vitagxm/SDL_render_vita_gxm.c
@@ -838,8 +838,8 @@ static int SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
     if (data->drawstate.viewport_dirty) {
         const SDL_Rect *viewport = &data->drawstate.viewport;
 
-        float sw = viewport->w / 2.;
-        float sh = viewport->h / 2.;
+        float sw = viewport->w / 2.f;
+        float sh = viewport->h / 2.f;
 
         float x_scale = sw;
         float x_off = viewport->x + sw;
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 12b1889fad5a7..a63c0e8e3178f 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -1367,7 +1367,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
             if (state->window_maxW || state->window_maxH) {
                 SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
             }
-            if (state->window_min_aspect || state->window_max_aspect) {
+            if (state->window_min_aspect != 0.f || state->window_max_aspect != 0.f) {
                 SDL_SetWindowAspectRatio(state->windows[i], state->window_min_aspect, state->window_max_aspect);
             }
             SDL_GetWindowSize(state->windows[i], &w, &h);
diff --git a/src/video/SDL_blit_slow.c b/src/video/SDL_blit_slow.c
index 9bd59a752af36..31eb1ae974dc8 100644
--- a/src/video/SDL_blit_slow.c
+++ b/src/video/SDL_blit_slow.c
@@ -796,7 +796,7 @@ void SDL_Blit_Slow_Float(SDL_BlitInfo *info)
         if (tonemap_operator) {
             if (SDL_strncmp(tonemap_operator, "*=", 2) == 0) {
                 tonemap.op = SDL_TONEMAP_LINEAR;
-                tonemap.data.linear.scale = SDL_atof(tonemap_operator + 2);
+                tonemap.data.linear.scale = (float)SDL_atof(tonemap_operator + 2);
             } else if (SDL_strcasecmp(tonemap_operator, "chrome") == 0) {
                 tonemap.op = SDL_TONEMAP_CHROME;
             } else if (SDL_strcasecmp(tonemap_operator, "none") == 0) {
diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m
index 0f70ff85ff3b4..452c6c4763a4b 100644
--- a/src/video/cocoa/SDL_cocoawindow.m
+++ b/src/video/cocoa/SDL_cocoawindow.m
@@ -1497,8 +1497,8 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
     if (focus && ([theEvent window] == ((__bridge SDL_CocoaWindowData *)focus->driverdata).nswindow)) {
         rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
     } else {
-        const int orig_x = mouse->x;
-        const int orig_y = mouse->y;
+        const float orig_x = mouse->x;
+        const float orig_y = mouse->y;
         const NSPoint point = [theEvent locationInWindow];
         mouse->x = (int)point.x;
         mouse->y = (int)(window->h - point.y);
@@ -2376,8 +2376,8 @@ void Cocoa_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int
             viewport = [contentView convertRectToBacking:viewport];
         }
 
-        *w = viewport.size.width;
-        *h = viewport.size.height;
+        *w = (int)viewport.size.width;
+        *h = (int)viewport.size.height;
     }
 }
 
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index a1b1dbdaf4410..bbb6eeeaf0370 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -886,7 +886,7 @@ static EM_BOOL Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *u
                 emscripten_get_element_css_size(window_data->canvas_id, &w, &h);
             }
 
-            emscripten_set_canvas_element_size(window_data->canvas_id, w * window_data->pixel_ratio, h * window_data->pixel_ratio);
+            emscripten_set_canvas_element_size(window_data->canvas_id, SDL_lroundf(w * window_data->pixel_ratio), SDL_lroundf(h * window_data->pixel_ratio));
 
             /* set_canvas_size unsets this */
             if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
@@ -899,7 +899,7 @@ static EM_BOOL Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *u
                 window_data->window->h = 0;
             }
 
-            SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_RESIZED, w, h);
+            SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_RESIZED, SDL_lroundf(w), SDL_lroundf(h));
         }
     }
 
@@ -915,7 +915,7 @@ Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userDat
     if (window_data->fullscreen_resize) {
         double css_w, css_h;
         emscripten_get_element_css_size(window_data->canvas_id, &css_w, &css_h);
-        SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_RESIZED, css_w, css_h);
+        SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_RESIZED, SDL_lroundf(css_w), SDL_lroundf(css_h));
     }
 
     return 0;
diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c
index 497849b035ac2..1ab7391aec014 100644
--- a/src/video/emscripten/SDL_emscriptenvideo.c
+++ b/src/video/emscripten/SDL_emscriptenvideo.c
@@ -215,9 +215,9 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, S
         scaled_w = css_w * wdata->pixel_ratio;
         scaled_h = css_h * wdata->pixel_ratio;
 
-        SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, css_w, css_h);
+        SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, SDL_lroundf(css_w), SDL_lroundf(css_h));
     }
-    emscripten_set_canvas_element_size(wdata->canvas_id, scaled_w, scaled_h);
+    emscripten_set_canvas_element_size(wdata->canvas_id, SDL_lroundf(scaled_w), SDL_lroundf(scaled_h));
 
     /* if the size is not being controlled by css, we need to scale down for hidpi */
     if (!wdata->external_size) {
@@ -252,7 +252,7 @@ static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
         if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
             data->pixel_ratio = emscripten_get_device_pixel_ratio();
         }
-        emscripten_set_canvas_element_size(data->canvas_id, window->floating.w * data->pixel_ratio, window->floating.h * data->pixel_ratio);
+        emscripten_set_canvas_element_size(data->canvas_id, SDL_lroundf(window->floating.w * data->pixel_ratio), SDL_lroundf(window->floating.h * data->pixel_ratio));
 
         /*scale canvas down*/
         if (!data->external_size && data->pixel_ratio != 1.0f) {
@@ -268,8 +268,8 @@ static void Emscripten_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window
     SDL_WindowData *data;
     if (window->driverdata) {
         data = window->driverdata;
-        *w = window->w * data->pixel_ratio;
-        *h = window->h * data->pixel_ratio;
+        *w = SDL_lroundf(window->w * data->pixel_ratio);
+        *h = SDL_lroundf(window->h * data->pixel_ratio);
     }
 }
 
diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c
index 31a3131cb1da7..516d5148fe080 100644
--- a/src/video/kmsdrm/SDL_kmsdrmmouse.c
+++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c
@@ -422,7 +422,7 @@ static int KMSDRM_MoveCursor(SDL_Cursor *cursor)
             return SDL_SetError("Cursor not initialized properly.");
         }
 
-        ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, mouse->x, mouse->y);
+        ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)mouse->x, (int)mouse->y);
 
         if (ret) {
             return SDL_SetError("drmModeMoveCursor() failed.");
diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.c b/src/video/kmsdrm/SDL_kmsdrmvulkan.c
index c41456c05ae2b..1590de1f98944 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvulkan.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.c
@@ -366,7 +366,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
         new_mode_parameters.visibleRegion.height = window->h;
         /* SDL (and DRM, if we look at drmModeModeInfo vrefresh) uses plain integer Hz for
            display mode refresh rate, but Vulkan expects higher precision. */
-        new_mode_parameters.refreshRate = window->current_fullscreen_mode.refresh_rate * 1000;
+        new_mode_parameters.refreshRate = (uint32_t)(window->current_fullscreen_mode.refresh_rate * 1000);
 
         SDL_zero(display_mode_create_info);
         display_mode_create_info.sType = VK_STRUCTURE_TYPE_DISPLAY_MODE_CREATE_INFO_KHR;
diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m
index b64a9c3304dce..2c3329c869b53 100644
--- a/src/video/uikit/SDL_uikitmodes.m
+++ b/src/video/uikit/SDL_uikitmodes.m
@@ -386,8 +386,8 @@ int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
 
         for (UIScreenMode *uimode in availableModes) {
             CGSize size = GetUIScreenModeSize(data.uiscreen, uimode);
-            int w = size.width;
-            int h = size.height;
+            int w = (int)size.width;
+            int h = (int)size.height;
 
             /* Make sure the width/height are oriented correctly */
             if (isLandscape != (w > h)) {
@@ -449,10 +449,10 @@ int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
             return -1;
         }
 
-        rect->x += frame.origin.x;
-        rect->y += frame.origin.y;
-        rect->w = frame.size.width;
-        rect->h = frame.size.height;
+        rect->x += (int)frame.origin.x;
+        rect->y += (int)frame.origin.y;
+        rect->w = (int)frame.size.width;
+        rect->h = (int)frame.size.height;
     }
 
     return 0;
diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index 0d0b614f9eb48..f6de072e85cb1 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -522,8 +522,8 @@ - (void)updateKeyboard
 #endif
 
     if (self.keyboardHeight) {
-        int rectbottom = self.textInputRect.y + self.textInputRect.h;
-        int keybottom = self.view.bounds.size.height - self.keyboardHeight;
+        int rectbottom = (int)(self.textInputRect.y + self.textInputRect.h);
+        int keybottom = (int)(self.view.bounds.size.height - self.keyboardHeight);
         if (keybottom < rectbottom) {
             offset.y = keybottom - rectbottom;
         }
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index 38f70c9fc5048..452b90ca8a819 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -376,8 +376,8 @@ void UIKit_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int
 
         /* Integer truncation of fractional values matches SDL_uikitmetalview and
          * SDL_uikitopenglview. */
-        *w = size.width * scale;
-        *h = size.height * scale;
+        *w = (int)(size.width * scale);
+        *h = (int)(size.height * scale);
     }
 }
 
diff --git a/src/video/vita/SDL_vitatouch.c b/src/video/vita/SDL_vitatouch.c
index 8106fd04d615c..fa6d59d16d504 100644
--- a/src/video/vita/SDL_vitatouch.c
+++ b/src/video/vita/SDL_vitatouch.c
@@ -173,11 +173,11 @@ void VITA_ConvertTouchXYToSDLXY(float *sdl_x, float *sdl_y, int vita_x, int vita
         y = (vita_y - area_info[port].y) / (area_info[port].h - 1);
     }
 
-    x = SDL_max(x, 0.0);
-    x = SDL_min(x, 1.0);
+    x = SDL_max(x, 0.0f);
+    x = SDL_min(x, 1.0f);
 
-    y = SDL_max(y, 0.0);
-    y = SDL_min(y, 1.0);
+    y = SDL_max(y, 0.0f);
+    y = SDL_min(y, 1.0f);
 
     *sdl_x = x;
     *sdl_y = y;
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 18f732632c610..fbb9b4de7b228 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -998,12 +998,12 @@ static void touch_handler_down(void *data, struct wl_touch *touch, uint32_t seri
         if (window_data->current.logical_width <= 1) {
             x = 0.5f;
         } else {
-            x = wl_fixed_to_double(fx) / (window_data->current.logical_width - 1);
+            x = (float)wl_fixed_to_double(fx) / (window_data->current.logical_width - 1);
         }
         if (window_data->current.logical_height <= 1) {
             y = 0.5f;
         } else {
-            y = wl_fixed_to_double(fy) / (window_data->current.logical_height - 1);
+            y = (float)wl_fixed_to_double(fy) / (window_data->current.logical_height - 1);
         }
 
         SDL_SetMouseFocus(window_data->sdlwindow);
@@ -1026,8 +1026,8 @@ static void touch_handler_up(void *data, struct wl_touch *touch, uint32_t serial
         SDL_WindowData *window_data = (SDL_WindowData *)wl_surface_get_user_data(surface);
 
         if (window_data) {
-            const float x = wl_fixed_to_double(fx) / window_data->current.logical_width;
-            const float y = wl_fixed_to_double(fy) / window_data->current.logical_height;
+            const float x = (float)wl_fixed_to_double(fx) / window_data->current.logical_width;
+            const float y = (float)wl_fixed_to_double(fy) / window_data->current.logical_height;
 
             SDL_SendTouch(Wayland_GetTouchTimestamp(input, timestamp), (SDL_TouchID)(uintptr_t)touch,
                           (SDL_FingerID)(id + 1), window_data->sdlwindow, SDL_FALSE, x, y, 0.0f);
@@ -1055,8 +1055,8 @@ static void touch_handler_motion(void *data, struct wl_touch *touch, uint32_t ti
         SDL_WindowData *window_data = (SDL_WindowData *)wl_surface_get_user_data(surface);
 
         if (window_data) {
-            const float x = wl_fixed_to_double(fx) / window_data->current.logical_width;
-            const float y = wl_fixed_to_double(fy) / window_data->current.logical_height;
+            const float x = (float)wl_fixed_to_double(fx) / window_data->current.logical_width;
+            const float y = (float)wl_fixed_to_double(fy) / window_data->current.logical_height;
 
             SDL_SendTouchMotion(Wayland_GetPointerTimestamp(input, timestamp), (SDL_TouchID)(uintptr_t)touch,
                                 (SDL_FingerID)(id + 1), window_data->sdlwindow, x, y, 1.0f);
@@ -2783,7 +2783,7 @@ static void tablet_tool_handle_slider(void *data, struct zwp_tablet_tool_v2 *too
 {
     struct SDL_WaylandTool *sdltool = data;
     struct SDL_WaylandTabletInput *input = sdltool->tablet;
-    input->current_pen.update_status.axes[SDL_PEN_AXIS_SLIDER] = position / 65535.0;
+    input->current_pen.update_status.axes[SDL_PEN_AXIS_SLIDER] = position / 65535.f;
 }
 
 static void tablet_tool_handle_wheel(void *data, struct zwp_tablet_tool_v2 *tool, int32_t degrees, int32_t clicks)
diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
index 23f5c7cff27d4..f14cd703abb18 100644
--- a/src/video/wayland/SDL_waylandmouse.c
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -350,7 +350,7 @@ static SDL_bool wayland_get_system_cursor(SDL_VideoData *vdata, struct Wayland_C
 
     /* Cursors use integer scaling. */
     *scale = SDL_ceilf(focusdata->windowed_scale_factor);
-    size *= *scale;
+    size *= (int)*scale;
     for (int i = 0; i < vdata->num_cursor_themes; i += 1) {
         if (vdata->cursor_themes[i].size == size) {
             theme = vdata->cursor_themes[i].theme;
@@ -638,12 +638,12 @@ static int Wayland_ShowCursor(SDL_Cursor *cursor)
             }
         }
 
-        wl_surface_set_buffer_scale(data->surface, scale);
+        wl_surface_set_buffer_scale(data->surface, (int32_t)scale);
         wl_pointer_set_cursor(pointer,
                               input->pointer_enter_serial,
                               data->surface,
-                              data->hot_x / scale,
-                              data->hot_y / scale);
+                              (int32_t)(data->hot_x / scale),
+                              (int32_t)(data->hot_y / scale));
         if (data->is_system_cursor) {
             wl_surface_attach(data->surface, data->cursor_data.system.frames[0].wl_buffer, 0, 0);
 
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index e77d8a978d8a3..54aff97311173 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -846,10 +846,10 @@ static void handle_configure_xdg_toplevel(void *data,
                 /* Aspect correction. */
                 const float aspect = (float)wind->requested.logical_width / (float)wind->requested.logical_height;
 
-                if (window->min_aspect && aspect < window->min_aspect) {
-                    wind->requested.logical_height = SDL_roundf((float)wind->requested.logical_width / window->min_aspect);
-                } else if (window->max_aspect && aspect > window->max_aspect) {
-                    wind->requested.logical_width = SDL_roundf((float)wind->requested.logical_height * window->max_aspect);
+                if (window->min_aspect != 0.f && aspect < window->min_aspect) {
+                    wind->requested.logical_height = SDL_lroundf((float)wind->requested.logical_width / window->min_aspect);
+                } else if (window->max_aspect != 0.f && aspect > window->max_aspect) {
+                    wind->requested.logical_width = SDL_lroundf((float)wind->requested.logical_height * window->max_aspect);
                 }
             } else {
                 if (window->max_w > 0) {
@@ -865,10 +865,10 @@ static void handle_configure_xdg_toplevel(void *data,
                 /* Aspect correction. */
                 const float aspect = (float)wind->requested.pixel_width / (float)wind->requested.pixel_height;
 
-                if (window->min_aspect && aspect < window->min_aspect) {
-                    wind->requested.pixel_height = SDL_roundf((float)wind->requested.pixel_width / window->min_aspect);
-                } else if (window->max_aspect && as

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