SDL: Backed out the viewport and cliprect changes in 9fb5a9ccac0a6bb6af02e72644c1c56dc6ab6f3e

From 80a907e0e688268083af4f9eb5661c792e1158aa Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 12 Jun 2024 19:08:06 -0700
Subject: [PATCH] Backed out the viewport and cliprect changes in
 9fb5a9ccac0a6bb6af02e72644c1c56dc6ab6f3e

This ended up being lots of application code churn without any real benefit in practice.
---
 docs/README-migration.md                 |   9 --
 include/SDL3/SDL_render.h                |  34 +++---
 src/dynapi/SDL_dynapi_procs.h            |  16 +--
 src/render/SDL_render.c                  | 139 ++++++++++++-----------
 src/render/SDL_sysrender.h               |  10 +-
 src/render/opengl/SDL_render_gl.c        |   6 +-
 src/render/opengles2/SDL_render_gles2.c  |   6 +-
 src/render/vitagxm/SDL_render_vita_gxm.c |   6 +-
 src/test/SDL_test_common.c               |  21 ++--
 test/gamepadutils.c                      |   6 +-
 test/testautomation_keyboard.c           |   2 +-
 test/testautomation_render.c             |  61 ++++------
 test/testcamera.c                        |   3 +-
 test/testcontroller.c                    |   2 +-
 test/testdraw.c                          |  34 +++---
 test/testdrawchessboard.c                |  10 +-
 test/testffmpeg.c                        |   8 +-
 test/testgeometry.c                      |   4 +-
 test/testintersections.c                 |  16 +--
 test/testmanymouse.c                     |   4 +-
 test/testnative.c                        |   2 +-
 test/testrelative.c                      |   2 +-
 test/testrendercopyex.c                  |  13 +--
 test/testrendertarget.c                  |  21 ++--
 test/testscale.c                         |  11 +-
 test/testsprite.c                        |   8 +-
 test/testviewport.c                      |  52 ++++-----
 test/testwm.c                            |   7 +-
 28 files changed, 238 insertions(+), 275 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 8ee219d360e2c..8079ca1ce093d 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1165,15 +1165,6 @@ SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been renamed SD
 
 The viewport, clipping state, and scale for render targets are now persistent and will remain set whenever they are active.
 
-The following functions have been changed to take floating point values to make them easier to use with the rest of the rendering API:
-* SDL_GetCurrentRenderOutputSize()
-* SDL_GetRenderClipRect()
-* SDL_GetRenderLogicalPresentation()
-* SDL_GetRenderOutputSize()
-* SDL_GetRenderViewport()
-* SDL_SetRenderLogicalPresentation()
-* SDL_SetRenderViewport()
-
 SDL_Vertex has been changed to use floating point colors, in the range of [0..1] for SDR content.
 
 SDL_RenderReadPixels() returns a surface instead of filling in preallocated memory.
diff --git a/include/SDL3/SDL_render.h b/include/SDL3/SDL_render.h
index 92086ecdc1622..5ac227b595602 100644
--- a/include/SDL3/SDL_render.h
+++ b/include/SDL3/SDL_render.h
@@ -459,7 +459,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Rende
  *
  * \sa SDL_GetCurrentRenderOutputSize
  */
-extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, float *w, float *h);
+extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
 
 /**
  * Get the current output size in pixels of a rendering context.
@@ -479,7 +479,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer,
  *
  * \sa SDL_GetRenderOutputSize
  */
-extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, float *w, float *h);
+extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
 
 /**
  * Create a texture for a rendering context.
@@ -512,8 +512,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *rendere
  * `SDL_TEXTUREACCESS_STATIC`.
  *
  * The pixel format of the created texture may be different from the pixel
- * format of the surface, and can be queried using the
- * SDL_PROP_TEXTURE_FORMAT_NUMBER property.
+ * format of the surface, and can be queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
  *
  * \param renderer the rendering context
  * \param surface the SDL_Surface structure containing pixel data used to fill
@@ -669,8 +668,8 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureWithProperties(SDL_Ren
  *
  * The following read-only properties are provided by SDL:
  *
- * - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
- *   the texture colorspace.
+ * - `SDL_PROP_TEXTURE_COLORSPACE_NUMBER`: an SDL_ColorSpace value
+ *   describing the texture colorspace.
  * - `SDL_PROP_TEXTURE_FORMAT_NUMBER`: one of the enumerated values in
  *   SDL_PixelFormatEnum.
  * - `SDL_PROP_TEXTURE_ACCESS_NUMBER`: one of the enumerated values in
@@ -1057,8 +1056,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SD
 /**
  * Update the given texture rectangle with new pixel data.
  *
- * The pixel data must be in the pixel format of the texture, which can be
- * queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
+ * The pixel data must be in the pixel format of the texture, which can be queried using the SDL_PROP_TEXTURE_FORMAT_NUMBER property.
  *
  * This is a fairly slow function, intended for use with static textures that
  * do not change often.
@@ -1298,7 +1296,7 @@ extern SDL_DECLSPEC SDL_Texture *SDLCALL SDL_GetRenderTarget(SDL_Renderer *rende
  * \sa SDL_ConvertEventToRenderCoordinates
  * \sa SDL_GetRenderLogicalPresentation
  */
-extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, float w, float h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
+extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
 
 /**
  * Get device independent resolution and presentation mode for rendering.
@@ -1318,7 +1316,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *r
  *
  * \sa SDL_SetRenderLogicalPresentation
  */
-extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, float *w, float *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
+extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
 
 /**
  * Get a point in render coordinates when given a point in window coordinates.
@@ -1381,7 +1379,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer
  * Set the drawing area for rendering on the current target.
  *
  * \param renderer the rendering context
- * \param rect the SDL_FRect structure representing the drawing area, or NULL
+ * \param rect the SDL_Rect structure representing the drawing area, or NULL
  *             to set the viewport to the entire target
  * \returns 0 on success or a negative error code on failure; call
  *          SDL_GetError() for more information.
@@ -1391,13 +1389,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer
  * \sa SDL_GetRenderViewport
  * \sa SDL_RenderViewportSet
  */
-extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_FRect *rect);
+extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);
 
 /**
  * Get the drawing area for the current target.
  *
  * \param renderer the rendering context
- * \param rect an SDL_FRect structure filled in with the current drawing area
+ * \param rect an SDL_Rect structure filled in with the current drawing area
  * \returns 0 on success or a negative error code on failure; call
  *          SDL_GetError() for more information.
  *
@@ -1406,7 +1404,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, co
  * \sa SDL_RenderViewportSet
  * \sa SDL_SetRenderViewport
  */
-extern SDL_DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_FRect *rect);
+extern SDL_DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect);
 
 /**
  * Return whether an explicit rectangle was set as the viewport.
@@ -1430,7 +1428,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *rendere
  * Set the clip rectangle for rendering on the specified target.
  *
  * \param renderer the rendering context
- * \param rect an SDL_FRect structure representing the clip area, relative to
+ * \param rect an SDL_Rect structure representing the clip area, relative to
  *             the viewport, or NULL to disable clipping
  * \returns 0 on success or a negative error code on failure; call
  *          SDL_GetError() for more information.
@@ -1440,13 +1438,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *rendere
  * \sa SDL_GetRenderClipRect
  * \sa SDL_RenderClipEnabled
  */
-extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_FRect *rect);
+extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect);
 
 /**
  * Get the clip rectangle for the current target.
  *
  * \param renderer the rendering context
- * \param rect an SDL_FRect structure filled in with the current clipping area
+ * \param rect an SDL_Rect structure filled in with the current clipping area
  *             or an empty rectangle if clipping is disabled
  * \returns 0 on success or a negative error code on failure; call
  *          SDL_GetError() for more information.
@@ -1456,7 +1454,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, co
  * \sa SDL_RenderClipEnabled
  * \sa SDL_SetRenderClipRect
  */
-extern SDL_DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_FRect *rect);
+extern SDL_DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect);
 
 /**
  * Get whether clipping is enabled on the given renderer.
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index e695212a951a6..e283c175913dc 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -243,7 +243,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return)
 SDL_DYNAPI_PROC(const char*,SDL_GetCurrentCameraDriver,(void),(),return)
 SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
 SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetCurrentDisplayOrientation,(SDL_DisplayID a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetCurrentThreadID,(void),(),return)
 SDL_DYNAPI_PROC(int,SDL_GetCurrentTime,(SDL_Time *a),(a),return)
 SDL_DYNAPI_PROC(const char*,SDL_GetCurrentVideoDriver,(void),(),return)
@@ -430,20 +430,20 @@ SDL_DYNAPI_PROC(int,SDL_GetRectUnion,(const SDL_Rect *a, const SDL_Rect *b, SDL_
 SDL_DYNAPI_PROC(int,SDL_GetRectUnionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_GetRelativeMouseMode,(void),(),return)
 SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetRelativeMouseState,(float *a, float *b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_FRect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_Rect *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColorFloat,(SDL_Renderer *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(const char*,SDL_GetRenderDriver,(int a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, float *b, float *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, int *b, int *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalCommandEncoder,(SDL_Renderer *a),(a),return)
 SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalLayer,(SDL_Renderer *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_GetRenderOutputSize,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_GetRenderScale,(SDL_Renderer *a, float *b, float *c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_Texture*,SDL_GetRenderTarget,(SDL_Renderer *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_GetRenderViewport,(SDL_Renderer *a, SDL_FRect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderViewport,(SDL_Renderer *a, SDL_Rect *b),(a,b),return)
 SDL_DYNAPI_PROC(SDL_Window*,SDL_GetRenderWindow,(SDL_Renderer *a),(a),return)
 SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRenderer,(SDL_Window *a),(a),return)
 SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRendererFromTexture,(SDL_Texture *a),(a),return)
@@ -757,16 +757,16 @@ SDL_DYNAPI_PROC(int,SDL_SetPrimarySelectionText,(const char *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_SetProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_SetPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, SDL_CleanupPropertyCallback d, void *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_SetRelativeMouseMode,(SDL_bool a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_SetRenderClipRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetRenderClipRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderColorScale,(SDL_Renderer *a, float b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColor,(SDL_Renderer *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColorFloat,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return)
-SDL_DYNAPI_PROC(int,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, float b, float c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, int b, int c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderScale,(SDL_Renderer *a, float b, float c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderTarget,(SDL_Renderer *a, SDL_Texture *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetRenderVSync,(SDL_Renderer *a, int b),(a,b),return)
-SDL_DYNAPI_PROC(int,SDL_SetRenderViewport,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_SetRenderViewport,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return)
 SDL_DYNAPI_PROC(int,SDL_SetSurfaceAlphaMod,(SDL_Surface *a, Uint8 b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_SetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode b),(a,b),return)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index ecc12cfde99f6..c9a37780a51ec 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -409,12 +409,12 @@ static void UpdatePixelViewport(SDL_Renderer *renderer, SDL_RenderViewState *vie
     if (view->viewport.w >= 0) {
         view->pixel_viewport.w = (int)SDL_ceilf(view->viewport.w * view->scale.x);
     } else {
-        view->pixel_viewport.w = (int)SDL_ceilf(view->pixel_w);
+        view->pixel_viewport.w = view->pixel_w;
     }
     if (view->viewport.h >= 0) {
         view->pixel_viewport.h = (int)SDL_ceilf(view->viewport.h * view->scale.y);
     } else {
-        view->pixel_viewport.h = (int)SDL_ceilf(view->pixel_h);
+        view->pixel_viewport.h = view->pixel_h;
     }
 }
 
@@ -448,10 +448,10 @@ static int QueueCmdSetViewport(SDL_Renderer *renderer)
 
 static void UpdatePixelClipRect(SDL_Renderer *renderer, SDL_RenderViewState *view)
 {
-    view->pixel_cliprect.x = (int)SDL_floorf(view->clip_rect.x * view->scale.x);
-    view->pixel_cliprect.y = (int)SDL_floorf(view->clip_rect.y * view->scale.y);
-    view->pixel_cliprect.w = (int)SDL_ceilf(view->clip_rect.w * view->scale.x);
-    view->pixel_cliprect.h = (int)SDL_ceilf(view->clip_rect.h * view->scale.y);
+    view->pixel_clip_rect.x = (int)SDL_floorf(view->clip_rect.x * view->scale.x);
+    view->pixel_clip_rect.y = (int)SDL_floorf(view->clip_rect.y * view->scale.y);
+    view->pixel_clip_rect.w = (int)SDL_ceilf(view->clip_rect.w * view->scale.x);
+    view->pixel_clip_rect.h = (int)SDL_ceilf(view->clip_rect.h * view->scale.y);
 }
 
 static int QueueCmdSetClipRect(SDL_Renderer *renderer)
@@ -459,7 +459,7 @@ static int QueueCmdSetClipRect(SDL_Renderer *renderer)
     SDL_Rect clip_rect;
     int retval = 0;
 
-    clip_rect = renderer->view->pixel_cliprect;
+    clip_rect = renderer->view->pixel_clip_rect;
 
     if (!renderer->cliprect_queued ||
         renderer->view->clipping_enabled != renderer->last_queued_cliprect_enabled ||
@@ -726,8 +726,8 @@ static void UpdateMainViewDimensions(SDL_Renderer *renderer)
     }
     SDL_GetRenderOutputSize(renderer, &renderer->main_view.pixel_w, &renderer->main_view.pixel_h);
     if (window_w > 0 && window_h > 0) {
-        renderer->dpi_scale.x = renderer->main_view.pixel_w / window_w;
-        renderer->dpi_scale.y = renderer->main_view.pixel_h / window_h;
+        renderer->dpi_scale.x = (float)renderer->main_view.pixel_w / window_w;
+        renderer->dpi_scale.y = (float)renderer->main_view.pixel_h / window_h;
     } else {
         renderer->dpi_scale.x = 1.0f;
         renderer->dpi_scale.y = 1.0f;
@@ -1029,8 +1029,8 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props)
     renderer->window = window;
     renderer->target_mutex = SDL_CreateMutex();
     if (surface) {
-        renderer->main_view.pixel_w = (float)surface->w;
-        renderer->main_view.pixel_h = (float)surface->h;
+        renderer->main_view.pixel_w = surface->w;
+        renderer->main_view.pixel_h = surface->h;
     }
     renderer->main_view.viewport.w = -1;
     renderer->main_view.viewport.h = -1;
@@ -1189,35 +1189,21 @@ SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)
     return renderer->props;
 }
 
-int SDL_GetRenderOutputSize(SDL_Renderer *renderer, float *w, float *h)
+int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
-    int output_w = 0;
-    int output_h = 0;
 
     if (renderer->GetOutputSize) {
-        if (renderer->GetOutputSize(renderer, &output_w, &output_h) < 0) {
-            return -1;
-        }
+        return renderer->GetOutputSize(renderer, w, h);
     } else if (renderer->window) {
-        if (SDL_GetWindowSizeInPixels(renderer->window, &output_w, &output_h) < 0) {
-            return -1;
-        }
+        return SDL_GetWindowSizeInPixels(renderer->window, w, h);
     } else {
         SDL_assert(!"This should never happen");
         return SDL_SetError("Renderer doesn't support querying output size");
     }
-
-    if (w) {
-        *w = (float)output_w;
-    }
-    if (h) {
-        *h = (float)output_h;
-    }
-    return 0;
 }
 
-int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, float *w, float *h)
+int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h)
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
@@ -1348,8 +1334,8 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
     texture->color.b = 1.0f;
     texture->color.a = 1.0f;
     texture->scaleMode = SDL_SCALEMODE_LINEAR;
-    texture->view.pixel_w = (float)w;
-    texture->view.pixel_h = (float)h;
+    texture->view.pixel_w = w;
+    texture->view.pixel_h = h;
     texture->view.viewport.w = -1;
     texture->view.viewport.h = -1;
     texture->view.scale.x = 1.0f;
@@ -2434,8 +2420,8 @@ SDL_Texture *SDL_GetRenderTarget(SDL_Renderer *renderer)
 static int UpdateLogicalPresentation(SDL_Renderer *renderer)
 {
     float logical_w = 1.0f, logical_h = 1.0f;
-    float output_w = renderer->main_view.pixel_w;
-    float output_h = renderer->main_view.pixel_h;
+    float output_w = (float)renderer->main_view.pixel_w;
+    float output_h = (float)renderer->main_view.pixel_h;
     float want_aspect = 1.0f;
     float real_aspect = 1.0f;
     float scale;
@@ -2529,34 +2515,34 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer)
     return 0;
 
 error:
-    SDL_SetRenderLogicalPresentation(renderer, 0.0f, 0.0f, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
+    SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
     return -1;
 }
 
-int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, float w, float h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode)
+int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode)
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
-    w = SDL_ceilf(w);
-    h = SDL_ceilf(h);
-
     if (mode == SDL_LOGICAL_PRESENTATION_DISABLED) {
         if (renderer->logical_target) {
             SDL_DestroyTexture(renderer->logical_target);
         }
     } else {
         if (renderer->logical_target) {
-            float existing_w = 0.0f, existing_h = 0.0f;
-
-            if (SDL_GetTextureSize(renderer->logical_target, &existing_w, &existing_h) < 0) {
+            SDL_PropertiesID props = SDL_GetTextureProperties(renderer->logical_target);
+            if (!props) {
                 goto error;
             }
+
+            int existing_w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
+            int existing_h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
+
             if (w != existing_w || h != existing_h) {
                 SDL_DestroyTexture(renderer->logical_target);
             }
         }
         if (!renderer->logical_target) {
-            renderer->logical_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_TARGET, (int)w, (int)h);
+            renderer->logical_target = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UNKNOWN, SDL_TEXTUREACCESS_TARGET, w, h);
             if (!renderer->logical_target) {
                 goto error;
             }
@@ -2570,24 +2556,38 @@ int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, float w, float h, S
     return UpdateLogicalPresentation(renderer);
 
 error:
-    SDL_SetRenderLogicalPresentation(renderer, 0.0f, 0.0f, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
+    SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
     return -1;
 }
 
-int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, float *w, float *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode)
+int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode)
 {
+    if (w) {
+        *w = 0;
+    }
+    if (h) {
+        *h = 0;
+    }
+    if (mode) {
+        *mode = SDL_LOGICAL_PRESENTATION_DISABLED;
+    }
+    if (scale_mode) {
+        *scale_mode = SDL_SCALEMODE_NEAREST;
+    }
+
     CHECK_RENDERER_MAGIC(renderer, -1);
 
     if (renderer->logical_target) {
-        if (SDL_GetTextureSize(renderer->logical_target, w, h) < 0) {
+        SDL_PropertiesID props = SDL_GetTextureProperties(renderer->logical_target);
+        if (!props) {
             return -1;
         }
-    } else {
+
         if (w) {
-            *w = 0.0f;
+            *w = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
         }
         if (h) {
-            *h = 0.0f;
+            *h = (int)SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
         }
     }
 
@@ -2597,6 +2597,7 @@ int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, float *w, float *h,
     if (scale_mode) {
         *scale_mode = renderer->logical_scale_mode;
     }
+
     return 0;
 }
 
@@ -2617,11 +2618,11 @@ static void SDL_RenderLogicalBorders(SDL_Renderer *renderer)
             rect.x = 0.0f;
             rect.y = 0.0f;
             rect.w = dst->x;
-            rect.h = renderer->view->pixel_h;
+            rect.h = (float)renderer->view->pixel_h;
             SDL_RenderFillRect(renderer, &rect);
 
             rect.x = dst->x + dst->w;
-            rect.w = renderer->view->pixel_w - rect.x;
+            rect.w = (float)renderer->view->pixel_w - rect.x;
             SDL_RenderFillRect(renderer, &rect);
         }
 
@@ -2630,12 +2631,12 @@ static void SDL_RenderLogicalBorders(SDL_Renderer *renderer)
 
             rect.x = 0.0f;
             rect.y = 0.0f;
-            rect.w = renderer->view->pixel_w;
+            rect.w = (float)renderer->view->pixel_w;
             rect.h = dst->y;
             SDL_RenderFillRect(renderer, &rect);
 
             rect.y = dst->y + dst->h;
-            rect.h = renderer->view->pixel_h - rect.y;
+            rect.h = (float)renderer->view->pixel_h - rect.y;
             SDL_RenderFillRect(renderer, &rect);
         }
 
@@ -2820,24 +2821,24 @@ int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event
     return 0;
 }
 
-int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_FRect *rect)
+int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
     if (rect) {
         SDL_copyp(&renderer->view->viewport, rect);
     } else {
-        renderer->view->viewport.x = 0.0f;
-        renderer->view->viewport.y = 0.0f;
-        renderer->view->viewport.w = -1.0f;
-        renderer->view->viewport.h = -1.0f;
+        renderer->view->viewport.x = 0;
+        renderer->view->viewport.y = 0;
+        renderer->view->viewport.w = -1;
+        renderer->view->viewport.h = -1;
     }
     UpdatePixelViewport(renderer, renderer->view);
 
     return QueueCmdSetViewport(renderer);
 }
 
-int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_FRect *rect)
+int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect)
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
@@ -2847,12 +2848,12 @@ int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_FRect *rect)
         if (renderer->view->viewport.w >= 0) {
             rect->w = renderer->view->viewport.w;
         } else {
-            rect->w = SDL_ceilf(renderer->view->pixel_w / renderer->view->scale.x);
+            rect->w = (int)SDL_ceilf(renderer->view->pixel_w / renderer->view->scale.x);
         }
         if (renderer->view->viewport.h >= 0) {
             rect->h = renderer->view->viewport.h;
         } else {
-            rect->h = SDL_ceilf(renderer->view->pixel_h / renderer->view->scale.y);
+            rect->h = (int)SDL_ceilf(renderer->view->pixel_h / renderer->view->scale.y);
         }
     }
     return 0;
@@ -2862,8 +2863,8 @@ SDL_bool SDL_RenderViewportSet(SDL_Renderer *renderer)
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
-    if (renderer->view->viewport.w >= 0.0f &&
-        renderer->view->viewport.h >= 0.0f) {
+    if (renderer->view->viewport.w >= 0 &&
+        renderer->view->viewport.h >= 0) {
         return SDL_TRUE;
     }
     return SDL_FALSE;
@@ -2873,19 +2874,19 @@ static void GetRenderViewportSize(SDL_Renderer *renderer, SDL_FRect *rect)
 {
     rect->x = 0.0f;
     rect->y = 0.0f;
-    if (renderer->view->viewport.w >= 0.0f) {
-        rect->w = renderer->view->viewport.w;
+    if (renderer->view->viewport.w >= 0) {
+        rect->w = (float)renderer->view->viewport.w;
     } else {
         rect->w = renderer->view->pixel_w / renderer->view->scale.x;
     }
-    if (renderer->view->viewport.h >= 0.0f) {
-        rect->h = renderer->view->viewport.h;
+    if (renderer->view->viewport.h >= 0) {
+        rect->h = (float)renderer->view->viewport.h;
     } else {
         rect->h = renderer->view->pixel_h / renderer->view->scale.y;
     }
 }
 
-int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_FRect *rect)
+int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect)
 {
     CHECK_RENDERER_MAGIC(renderer, -1)
 
@@ -2901,7 +2902,7 @@ int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_FRect *rect)
     return QueueCmdSetClipRect(renderer);
 }
 
-int SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_FRect *rect)
+int SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect)
 {
     CHECK_RENDERER_MAGIC(renderer, -1)
 
@@ -3142,7 +3143,7 @@ int SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y
 
 static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, int y2, SDL_bool draw_last)
 {
-    const int MAX_PIXELS = (int)SDL_max(renderer->view->pixel_w, renderer->view->pixel_h) * 4;
+    const int MAX_PIXELS = SDL_max(renderer->view->pixel_w, renderer->view->pixel_h) * 4;
     int i, deltax, deltay, numpixels;
     int d, dinc1, dinc2;
     int x, xinc1, xinc2;
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index e1ba26d1478dd..22dd0e714022d 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -48,12 +48,12 @@ typedef struct SDL_RenderDriver SDL_RenderDriver;
 /* Rendering view state */
 typedef struct SDL_RenderViewState
 {
-    float pixel_w;
-    float pixel_h;
-    SDL_FRect viewport;
+    int pixel_w;
+    int pixel_h;
+    SDL_Rect viewport;
     SDL_Rect pixel_viewport;
-    SDL_FRect clip_rect;
-    SDL_Rect pixel_cliprect;
+    SDL_Rect clip_rect;
+    SDL_Rect pixel_clip_rect;
     SDL_bool clipping_enabled;
     SDL_FPoint scale;
 
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index bd570bbf3ae19..5f09a2dec726e 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -1453,7 +1453,7 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
     SDL_PixelFormatEnum format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
     GLint internalFormat;
     GLenum targetFormat, type;
-    float h;
+    int w, h;
     SDL_Surface *surface;
 
     GL_ActivateRenderer(renderer);
@@ -1468,12 +1468,12 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
         return NULL;
     }
 
-    SDL_GetCurrentRenderOutputSize(renderer, NULL, &h);
+    SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
 
     data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
     data->glPixelStorei(GL_PACK_ROW_LENGTH, (surface->pitch / SDL_BYTESPERPIXEL(format)));
 
-    data->glReadPixels(rect->x, renderer->target ? rect->y : ((int)h - rect->y) - rect->h,
+    data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
                        rect->w, rect->h, targetFormat, type, surface->pixels);
 
     if (GL_CheckError("glReadPixels()", renderer) < 0) {
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/openg

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