SDL: Simplified internal SDL_Surface structure

From 3234a3b9028b1fe9ce078c7a3205a5a17b102387 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 30 Sep 2024 22:15:38 -0700
Subject: [PATCH] Simplified internal SDL_Surface structure

---
 include/SDL3/SDL_surface.h                    |  16 +-
 src/SDL.c                                     |   1 +
 src/SDL_internal.h                            |   1 +
 src/SDL_properties.c                          |   2 +-
 src/SDL_utils.c                               |   2 -
 src/SDL_utils_c.h                             |   3 +-
 src/audio/SDL_sysaudio.h                      |   2 -
 src/camera/SDL_camera.c                       |   1 +
 src/camera/SDL_syscamera.h                    |   2 +-
 src/camera/android/SDL_camera_android.c       |   1 +
 src/camera/emscripten/SDL_camera_emscripten.c |   1 +
 src/camera/v4l2/SDL_camera_v4l2.c             |   1 +
 src/events/SDL_keymap.c                       |   1 -
 src/gpu/d3d12/SDL_gpu_d3d12.c                 |   1 -
 src/gpu/vulkan/SDL_gpu_vulkan.c               |   1 -
 src/joystick/SDL_gamepad.c                    |   1 -
 src/render/SDL_sysrender.h                    |   2 +
 src/render/SDL_yuv_sw.c                       |   2 +-
 src/render/gpu/SDL_pipeline_gpu.h             |   2 -
 src/render/opengles2/SDL_render_gles2.c       |   1 -
 src/render/software/SDL_blendfillrect.c       |  36 +-
 src/render/software/SDL_blendline.c           |  14 +-
 src/render/software/SDL_blendpoint.c          |  44 +-
 src/render/software/SDL_draw.h                |  10 +-
 src/render/software/SDL_drawline.c            |  18 +-
 src/render/software/SDL_drawpoint.c           |  22 +-
 src/render/software/SDL_render_sw.c           |  10 +-
 src/render/software/SDL_rotate.c              |   8 +-
 src/render/software/SDL_triangle.c            |  22 +-
 src/stdlib/SDL_getenv.c                       |   1 -
 src/video/SDL_RLEaccel.c                      |  80 +--
 src/video/SDL_blit.c                          |  24 +-
 src/video/SDL_blit.h                          |   4 -
 src/video/SDL_blit_0.c                        |  12 +-
 src/video/SDL_blit_1.c                        |  10 +-
 src/video/SDL_blit_A.c                        |  16 +-
 src/video/SDL_blit_N.c                        |  10 +-
 src/video/SDL_blit_auto.c                     |   1 -
 src/video/SDL_blit_copy.c                     |   2 +-
 src/video/SDL_blit_slow.c                     |   6 +-
 src/video/SDL_bmp.c                           |  33 +-
 src/video/SDL_fillrect.c                      |   6 +-
 src/video/SDL_pixels.c                        |  39 +-
 src/video/SDL_stretch.c                       |   6 +-
 src/video/SDL_surface.c                       | 511 +++++++++---------
 src/video/SDL_surface_c.h                     |  29 +-
 src/video/SDL_sysvideo.h                      |   2 +
 src/video/SDL_video.c                         |   8 +-
 src/video/sdlgenblit.pl                       |   2 +-
 src/video/windows/SDL_windowsmouse.c          |   1 -
 src/video/windows/SDL_windowsshape.c          |   2 -
 src/video/x11/SDL_x11shape.c                  |   2 -
 52 files changed, 515 insertions(+), 520 deletions(-)

diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h
index 6855613f4e015..0e47d3c49c401 100644
--- a/include/SDL3/SDL_surface.h
+++ b/include/SDL3/SDL_surface.h
@@ -86,9 +86,7 @@ typedef enum SDL_FlipMode
     SDL_FLIP_VERTICAL       /**< flip vertically */
 } SDL_FlipMode;
 
-/* Internal surface data */
-typedef struct SDL_SurfaceData SDL_SurfaceData;
-
+#ifndef SDL_INTERNAL
 /**
  * A collection of pixels used in software blitting.
  *
@@ -105,8 +103,11 @@ typedef struct SDL_SurfaceData SDL_SurfaceData;
  * alignment, and have undefined contents.
  *
  * \since This struct is available since SDL 3.0.0.
+ *
+ * \sa SDL_CreateSurface
+ * \sa SDL_DestroySurface
  */
-typedef struct SDL_Surface
+struct SDL_Surface
 {
     SDL_SurfaceFlags flags;     /**< The flags of the surface, read-only */
     SDL_PixelFormat format;     /**< The format of the surface, read-only */
@@ -117,10 +118,11 @@ typedef struct SDL_Surface
 
     int refcount;               /**< Application reference count, used when freeing surface */
 
-    SDL_SurfaceData *internal;  /**< Private */
-
-} SDL_Surface;
+    void *reserved;             /**< Reserved for internal use */
+};
+#endif /* !SDL_INTERNAL */
 
+typedef struct SDL_Surface SDL_Surface;
 
 /**
  * Allocate a new surface with a specific pixel format.
diff --git a/src/SDL.c b/src/SDL.c
index 6875d968d55a8..11623a3403e4c 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -52,6 +52,7 @@
 #include "stdlib/SDL_getenv_c.h"
 #include "thread/SDL_thread_c.h"
 #include "video/SDL_pixels_c.h"
+#include "video/SDL_surface_c.h"
 #include "video/SDL_video_c.h"
 #include "filesystem/SDL_filesystem_c.h"
 
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index 498021849c4f8..75fa957a5f138 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -237,6 +237,7 @@ extern "C" {
 #endif
 
 #include "SDL_utils_c.h"
+#include "SDL_hashtable.h"
 
 // Do any initialization that needs to happen before threads are started
 extern void SDL_InitMainThread(void);
diff --git a/src/SDL_properties.c b/src/SDL_properties.c
index 802717104423a..5612fd72ee27d 100644
--- a/src/SDL_properties.c
+++ b/src/SDL_properties.c
@@ -19,7 +19,7 @@
   3. This notice may not be removed or altered from any source distribution.
 */
 #include "SDL_internal.h"
-#include "SDL_hashtable.h"
+
 #include "SDL_hints_c.h"
 #include "SDL_properties_c.h"
 
diff --git a/src/SDL_utils.c b/src/SDL_utils.c
index d6de998a93c8b..b1fb89af6892f 100644
--- a/src/SDL_utils.c
+++ b/src/SDL_utils.c
@@ -20,8 +20,6 @@
 */
 #include "SDL_internal.h"
 
-#include "SDL_hashtable.h"
-
 #if defined(SDL_PLATFORM_UNIX) || defined(SDL_PLATFORM_APPLE)
 #include <unistd.h>
 #endif
diff --git a/src/SDL_utils_c.h b/src/SDL_utils_c.h
index 500f804fe372a..adb150a92271d 100644
--- a/src/SDL_utils_c.h
+++ b/src/SDL_utils_c.h
@@ -18,7 +18,8 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
-#include "SDL_internal.h"
+// This is included in SDL_internal.h
+//#include "SDL_internal.h"
 
 #ifndef SDL_utils_h_
 #define SDL_utils_h_
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index fc8ddd03252bf..8adfe9ab836a8 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -24,8 +24,6 @@
 #ifndef SDL_sysaudio_h_
 #define SDL_sysaudio_h_
 
-#include "../SDL_hashtable.h"
-
 #define DEBUG_AUDIOSTREAM 0
 #define DEBUG_AUDIO_CONVERT 0
 
diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c
index a76a095b2d062..86e1fbab82876 100644
--- a/src/camera/SDL_camera.c
+++ b/src/camera/SDL_camera.c
@@ -23,6 +23,7 @@
 #include "SDL_syscamera.h"
 #include "SDL_camera_c.h"
 #include "../video/SDL_pixels_c.h"
+#include "../video/SDL_surface_c.h"
 #include "../thread/SDL_systhread.h"
 
 
diff --git a/src/camera/SDL_syscamera.h b/src/camera/SDL_syscamera.h
index cff81a5b003c5..51b88355ed049 100644
--- a/src/camera/SDL_syscamera.h
+++ b/src/camera/SDL_syscamera.h
@@ -23,7 +23,7 @@
 #ifndef SDL_syscamera_h_
 #define SDL_syscamera_h_
 
-#include "../SDL_hashtable.h"
+#include "../video/SDL_surface_c.h"
 
 #define DEBUG_CAMERA 0
 
diff --git a/src/camera/android/SDL_camera_android.c b/src/camera/android/SDL_camera_android.c
index 1838f9b414e23..7c60bfd69eab9 100644
--- a/src/camera/android/SDL_camera_android.c
+++ b/src/camera/android/SDL_camera_android.c
@@ -23,6 +23,7 @@
 #include "../SDL_syscamera.h"
 #include "../SDL_camera_c.h"
 #include "../../video/SDL_pixels_c.h"
+#include "../../video/SDL_surface_c.h"
 #include "../../thread/SDL_systhread.h"
 
 #ifdef SDL_CAMERA_DRIVER_ANDROID
diff --git a/src/camera/emscripten/SDL_camera_emscripten.c b/src/camera/emscripten/SDL_camera_emscripten.c
index 88f9a85fe6dc6..3662bffce6454 100644
--- a/src/camera/emscripten/SDL_camera_emscripten.c
+++ b/src/camera/emscripten/SDL_camera_emscripten.c
@@ -25,6 +25,7 @@
 #include "../SDL_syscamera.h"
 #include "../SDL_camera_c.h"
 #include "../../video/SDL_pixels_c.h"
+#include "../../video/SDL_surface_c.h"
 
 #include <emscripten/emscripten.h>
 
diff --git a/src/camera/v4l2/SDL_camera_v4l2.c b/src/camera/v4l2/SDL_camera_v4l2.c
index fbe0516aefc77..8a19280924631 100644
--- a/src/camera/v4l2/SDL_camera_v4l2.c
+++ b/src/camera/v4l2/SDL_camera_v4l2.c
@@ -41,6 +41,7 @@ SDL_COMPILE_TIME_ASSERT(v4l2devicecaps, offsetof(struct v4l2_capability,device_c
 #include "../SDL_syscamera.h"
 #include "../SDL_camera_c.h"
 #include "../../video/SDL_pixels_c.h"
+#include "../../video/SDL_surface_c.h"
 #include "../../thread/SDL_systhread.h"
 #include "../../core/linux/SDL_evdev_capabilities.h"
 #include "../../core/linux/SDL_udev.h"
diff --git a/src/events/SDL_keymap.c b/src/events/SDL_keymap.c
index eb1e0973c3b8a..6bd69c50c0019 100644
--- a/src/events/SDL_keymap.c
+++ b/src/events/SDL_keymap.c
@@ -22,7 +22,6 @@
 
 #include "SDL_keymap_c.h"
 #include "SDL_keyboard_c.h"
-#include "../SDL_hashtable.h"
 
 struct SDL_Keymap
 {
diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c
index 6807c8f0115b4..cc002160fa036 100644
--- a/src/gpu/d3d12/SDL_gpu_d3d12.c
+++ b/src/gpu/d3d12/SDL_gpu_d3d12.c
@@ -26,7 +26,6 @@
 #include "../../core/windows/SDL_windows.h"
 #include "../../video/directx/SDL_d3d12.h"
 #include "../SDL_sysgpu.h"
-#include "SDL_hashtable.h"
 
 #ifdef __IDXGIInfoQueue_INTERFACE_DEFINED__
 #define HAVE_IDXGIINFOQUEUE
diff --git a/src/gpu/vulkan/SDL_gpu_vulkan.c b/src/gpu/vulkan/SDL_gpu_vulkan.c
index 0f01e82c34f9d..8409b98e5d906 100644
--- a/src/gpu/vulkan/SDL_gpu_vulkan.c
+++ b/src/gpu/vulkan/SDL_gpu_vulkan.c
@@ -29,7 +29,6 @@
 #define VK_NO_PROTOTYPES
 #include "../../video/khronos/vulkan/vulkan.h"
 
-#include "SDL_hashtable.h"
 #include <SDL3/SDL_vulkan.h>
 
 #include "../SDL_sysgpu.h"
diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c
index 2997b9f786453..e4ad40d80b5e3 100644
--- a/src/joystick/SDL_gamepad.c
+++ b/src/joystick/SDL_gamepad.c
@@ -31,7 +31,6 @@
 #include "usb_ids.h"
 #include "hidapi/SDL_hidapi_nintendo.h"
 #include "../events/SDL_events_c.h"
-#include "../SDL_hashtable.h"
 
 
 #ifdef SDL_PLATFORM_ANDROID
diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h
index 203c7b0f1cd0e..a6320b255b640 100644
--- a/src/render/SDL_sysrender.h
+++ b/src/render/SDL_sysrender.h
@@ -23,6 +23,8 @@
 #ifndef SDL_sysrender_h_
 #define SDL_sysrender_h_
 
+#include "../video/SDL_surface_c.h"
+
 #include "SDL_yuv_sw_c.h"
 
 // Set up for C function definitions, even when using C++
diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c
index 2b08df2192571..e7e9fe4eded91 100644
--- a/src/render/SDL_yuv_sw.c
+++ b/src/render/SDL_yuv_sw.c
@@ -25,7 +25,7 @@
 #if SDL_HAVE_YUV
 
 #include "SDL_yuv_sw_c.h"
-#include "../video/SDL_blit.h"
+#include "../video/SDL_surface_c.h"
 #include "../video/SDL_yuv_c.h"
 
 SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h)
diff --git a/src/render/gpu/SDL_pipeline_gpu.h b/src/render/gpu/SDL_pipeline_gpu.h
index 7bdf4e1bdcb1e..1e7b32e226a07 100644
--- a/src/render/gpu/SDL_pipeline_gpu.h
+++ b/src/render/gpu/SDL_pipeline_gpu.h
@@ -26,8 +26,6 @@
 
 #include "SDL_shaders_gpu.h"
 
-#include "SDL_hashtable.h"
-
 typedef struct GPU_PipelineParameters
 {
     SDL_BlendMode blend_mode;
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 6392c390e92a7..a779ff3122646 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -25,7 +25,6 @@
 #include "../../video/SDL_sysvideo.h" // For SDL_RecreateWindow
 #include <SDL3/SDL_opengles2.h>
 #include "../SDL_sysrender.h"
-#include "../../video/SDL_blit.h"
 #include "../../video/SDL_pixels_c.h"
 #include "SDL_shaders_gles2.h"
 
diff --git a/src/render/software/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c
index 29038b9f7f812..785f62870c95e 100644
--- a/src/render/software/SDL_blendfillrect.c
+++ b/src/render/software/SDL_blendfillrect.c
@@ -144,7 +144,7 @@ static bool SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
 static bool SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
                                  SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned inva = 0xff - a;
 
     switch (fmt->bytes_per_pixel) {
@@ -202,7 +202,7 @@ static bool SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
 static bool SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
                                   SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned inva = 0xff - a;
 
     switch (fmt->bytes_per_pixel) {
@@ -250,12 +250,12 @@ bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode ble
     // If 'rect' == NULL, then fill the whole surface
     if (rect) {
         // Perform clipping
-        if (!SDL_GetRectIntersection(rect, &dst->internal->clip_rect, &clipped)) {
+        if (!SDL_GetRectIntersection(rect, &dst->clip_rect, &clipped)) {
             return true;
         }
         rect = &clipped;
     } else {
-        rect = &dst->internal->clip_rect;
+        rect = &dst->clip_rect;
     }
 
     if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -264,23 +264,23 @@ bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode ble
         b = DRAW_MUL(b, a);
     }
 
-    switch (dst->internal->format->bits_per_pixel) {
+    switch (dst->fmt->bits_per_pixel) {
     case 15:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x7C00:
             return SDL_BlendFillRect_RGB555(dst, rect, blendMode, r, g, b, a);
         }
         break;
     case 16:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0xF800:
             return SDL_BlendFillRect_RGB565(dst, rect, blendMode, r, g, b, a);
         }
         break;
     case 32:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x00FF0000:
-            if (!dst->internal->format->Amask) {
+            if (!dst->fmt->Amask) {
                 return SDL_BlendFillRect_XRGB8888(dst, rect, blendMode, r, g, b, a);
             } else {
                 return SDL_BlendFillRect_ARGB8888(dst, rect, blendMode, r, g, b, a);
@@ -292,7 +292,7 @@ bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode ble
         break;
     }
 
-    if (!dst->internal->format->Amask) {
+    if (!dst->fmt->Amask) {
         return SDL_BlendFillRect_RGB(dst, rect, blendMode, r, g, b, a);
     } else {
         return SDL_BlendFillRect_RGBA(dst, rect, blendMode, r, g, b, a);
@@ -311,7 +311,7 @@ bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_
     }
 
     // This function doesn't work on surfaces < 8 bpp
-    if (dst->internal->format->bits_per_pixel < 8) {
+    if (dst->fmt->bits_per_pixel < 8) {
         return SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
     }
 
@@ -322,23 +322,23 @@ bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_
     }
 
     // FIXME: Does this function pointer slow things down significantly?
-    switch (dst->internal->format->bits_per_pixel) {
+    switch (dst->fmt->bits_per_pixel) {
     case 15:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x7C00:
             func = SDL_BlendFillRect_RGB555;
         }
         break;
     case 16:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0xF800:
             func = SDL_BlendFillRect_RGB565;
         }
         break;
     case 32:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x00FF0000:
-            if (!dst->internal->format->Amask) {
+            if (!dst->fmt->Amask) {
                 func = SDL_BlendFillRect_XRGB8888;
             } else {
                 func = SDL_BlendFillRect_ARGB8888;
@@ -351,7 +351,7 @@ bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_
     }
 
     if (!func) {
-        if (!dst->internal->format->Amask) {
+        if (!dst->fmt->Amask) {
             func = SDL_BlendFillRect_RGB;
         } else {
             func = SDL_BlendFillRect_RGBA;
@@ -360,7 +360,7 @@ bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_
 
     for (i = 0; i < count; ++i) {
         // Perform clipping
-        if (!SDL_GetRectIntersection(&rects[i], &dst->internal->clip_rect, &rect)) {
+        if (!SDL_GetRectIntersection(&rects[i], &dst->clip_rect, &rect)) {
             continue;
         }
         result = func(dst, &rect, blendMode, r, g, b, a);
diff --git a/src/render/software/SDL_blendline.c b/src/render/software/SDL_blendline.c
index 7f1f4f85526d8..18d51c6827ae2 100644
--- a/src/render/software/SDL_blendline.c
+++ b/src/render/software/SDL_blendline.c
@@ -30,7 +30,7 @@ static void SDL_BlendLine_RGB2(SDL_Surface *dst, int x1, int y1, int x2, int y2,
                                SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
                                bool draw_end)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned r, g, b, a, inva;
 
     if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -397,7 +397,7 @@ static void SDL_BlendLine_RGB4(SDL_Surface *dst, int x1, int y1, int x2, int y2,
                                SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
                                bool draw_end)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned r, g, b, a, inva;
 
     if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -520,7 +520,7 @@ static void SDL_BlendLine_RGBA4(SDL_Surface *dst, int x1, int y1, int x2, int y2
                                 SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
                                 bool draw_end)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned r, g, b, a, inva;
 
     if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -927,14 +927,14 @@ bool SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMo
         return SDL_InvalidParamError("SDL_BlendLine(): dst");
     }
 
-    func = SDL_CalculateBlendLineFunc(dst->internal->format);
+    func = SDL_CalculateBlendLineFunc(dst->fmt);
     if (!func) {
         return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
     }
 
     // Perform clipping
     // FIXME: We don't actually want to clip, as it may change line slope
-    if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
+    if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
         return true;
     }
 
@@ -954,7 +954,7 @@ bool SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_Bl
         return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
     }
 
-    func = SDL_CalculateBlendLineFunc(dst->internal->format);
+    func = SDL_CalculateBlendLineFunc(dst->fmt);
     if (!func) {
         return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
     }
@@ -967,7 +967,7 @@ bool SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_Bl
 
         // Perform clipping
         // FIXME: We don't actually want to clip, as it may change line slope
-        if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
+        if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
             continue;
         }
 
diff --git a/src/render/software/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c
index 1ccf21081d56d..8a528efe84e29 100644
--- a/src/render/software/SDL_blendpoint.c
+++ b/src/render/software/SDL_blendpoint.c
@@ -144,7 +144,7 @@ static bool SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMod
 static bool SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
                               Uint8 g, Uint8 b, Uint8 a)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned inva = 0xff - a;
 
     switch (fmt->bytes_per_pixel) {
@@ -202,7 +202,7 @@ static bool SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode ble
 static bool SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
                                Uint8 g, Uint8 b, Uint8 a)
 {
-    const SDL_PixelFormatDetails *fmt = dst->internal->format;
+    const SDL_PixelFormatDetails *fmt = dst->fmt;
     unsigned inva = 0xff - a;
 
     switch (fmt->bytes_per_pixel) {
@@ -246,9 +246,9 @@ bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uin
     }
 
     // Perform clipping
-    if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
-        x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
-        y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
+    if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
+        x >= (dst->clip_rect.x + dst->clip_rect.w) ||
+        y >= (dst->clip_rect.y + dst->clip_rect.h)) {
         return true;
     }
 
@@ -258,23 +258,23 @@ bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uin
         b = DRAW_MUL(b, a);
     }
 
-    switch (dst->internal->format->bits_per_pixel) {
+    switch (dst->fmt->bits_per_pixel) {
     case 15:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x7C00:
             return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
         }
         break;
     case 16:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0xF800:
             return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
         }
         break;
     case 32:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x00FF0000:
-            if (!dst->internal->format->Amask) {
+            if (!dst->fmt->Amask) {
                 return SDL_BlendPoint_XRGB8888(dst, x, y, blendMode, r, g, b, a);
             } else {
                 return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b, a);
@@ -286,7 +286,7 @@ bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uin
         break;
     }
 
-    if (!dst->internal->format->Amask) {
+    if (!dst->fmt->Amask) {
         return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
     } else {
         return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
@@ -307,7 +307,7 @@ bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_B
     }
 
     // This function doesn't work on surfaces < 8 bpp
-    if (dst->internal->format->bits_per_pixel < 8) {
+    if (dst->fmt->bits_per_pixel < 8) {
         return SDL_SetError("SDL_BlendPoints(): Unsupported surface format");
     }
 
@@ -318,25 +318,25 @@ bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_B
     }
 
     // FIXME: Does this function pointer slow things down significantly?
-    switch (dst->internal->format->bits_per_pixel) {
+    switch (dst->fmt->bits_per_pixel) {
     case 15:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x7C00:
             func = SDL_BlendPoint_RGB555;
             break;
         }
         break;
     case 16:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0xF800:
             func = SDL_BlendPoint_RGB565;
             break;
         }
         break;
     case 32:
-        switch (dst->internal->format->Rmask) {
+        switch (dst->fmt->Rmask) {
         case 0x00FF0000:
-            if (!dst->internal->format->Amask) {
+            if (!dst->fmt->Amask) {
                 func = SDL_BlendPoint_XRGB8888;
             } else {
                 func = SDL_BlendPoint_ARGB8888;
@@ -349,17 +349,17 @@ bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_B
     }
 
     if (!func) {
-        if (!dst->internal->format->Amask) {
+        if (!dst->fmt->Amask) {
             func = SDL_BlendPoint_RGB;
         } else {
             func = SDL_BlendPoint_RGBA;
         }
     }
 
-    minx = dst->internal->clip_rect.x;
-    maxx = dst->internal->clip_rect.x + dst->internal->clip_rect.w - 1;
-    miny = dst->internal->clip_rect.y;
-    maxy = dst->internal->clip_rect.y + dst->internal->clip_rect.h - 1;
+    minx = dst->clip_rect.x;
+    maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
+    miny = dst->clip_rect.y;
+    maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
 
     for (i = 0; i < count; ++i) {
         x = points[i].x;
diff --git a/src/render/software/SDL_draw.h b/src/render/software/SDL_draw.h
index e1277f1f45692..2e82793cb1800 100644
--- a/src/render/software/SDL_draw.h
+++ b/src/render/software/SDL_draw.h
@@ -20,7 +20,7 @@
 */
 #include "SDL_internal.h"
 
-#include "../../video/SDL_blit.h"
+#include "../../video/SDL_surface_c.h"
 
 /* This code assumes that r, g, b, a are the source color,
  * and in the blend and add case, the RGB values are premultiplied by a.
@@ -428,7 +428,7 @@
 #define HLINE(type, op, draw_end)                              \
     {                                                          \
         int length;                                            \
-        int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
+        int pitch = (dst->pitch / dst->fmt->bytes_per_pixel); \
         type *pixel;                                           \
         if (x1 <= x2) {                                        \
             pixel = (type *)dst->pixels + y1 * pitch + x1;     \
@@ -450,7 +450,7 @@
 #define VLINE(type, op, draw_end)                              \
     {                                                          \
         int length;                                            \
-        int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
+        int pitch = (dst->pitch / dst->fmt->bytes_per_pixel); \
         type *pixel;                                           \
         if (y1 <= y2) {                                        \
             pixel = (type *)dst->pixels + y1 * pitch + x1;     \
@@ -472,7 +472,7 @@
 #define DLINE(type, op, draw_end)                              \
     {                                                          \
         int length;                                            \
-        int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
+        int pitch = (dst->pitch / dst->fmt->bytes_per_pixel); \
         type *pixel;                                           \
         if (y1 <= y2) {                                        \
             pixel = (type *)dst->pixels + y1 * pitch + x1;     \
@@ -692,7 +692,7 @@
     do {                                                               \
         int width = rect->w;                                           \
         int height = rect->h;                                          \
-        int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel); \
+        int pitch = (dst->pitch / dst->fmt->bytes_per_pixel); \
         int skip = pitch - width;                                      \
         type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \
         while (height--) {                                             \
diff --git a/src/render/software/SDL_drawline.c b/src/render/software/SDL_drawline.c
index 03e8fa23072d7..e43f222cbd75c 100644
--- a/src/render/software/SDL_drawline.c
+++ b/src/render/software/SDL_drawline.c
@@ -31,7 +31,7 @@ static void SDL_DrawLine1(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
 {
     if (y1 == y2) {
         int length;
-        int pitch = (dst->pitch / dst->internal->format->bytes_per_pixel);
+        int pitch = (dst->pitch / dst->fmt->bytes_per_pixel);
         Uint8 *pixel;
         if (x1 <= x2) {
             pixel = (Uint8 *)dst->pixels + y1 * pitch + x1;
@@ -64,8 +64,8 @@ static void SDL_DrawLine2(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
         DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
     } else {
         Uint8 _r, _g, _b, _a;
-        const SDL_PixelFormatDetails *fmt = dst->internal->format;
-        SDL_GetRGBA(color, fmt, dst->internal->palette, &_r, &_g, &_b, &_a);
+        const SDL_PixelFormatDetails *fmt = dst->fmt;
+        SDL_GetRGBA(color, fmt, dst->palette, &_r, &_g, &_b, &_a);
         if (fmt->Rmask == 0x7C00) {
             AALINE(x1, y1, x2, y2,
                    DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
@@ -93,8 +93,8 @@ static void SDL_DrawLine4(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint
         DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
     } else {
         Uint8 _r, _g, _b, _a;
-        const SDL_PixelFormatDetails *fmt = dst->internal->format;
-        SDL_GetRGBA(color, fmt, dst->internal->palette, &_r, &_g, &_b, &_a);
+        const SDL_PixelFormatDetails *fmt = dst->fmt;
+        SDL_GetRGBA(color, fmt, dst->palette, &_r, &_g, &_b, &_a);
         if (fmt->Rmask == 0x00FF0000) {
             if (!fmt->Amask) {
                 AALINE(x1, y1, x2, y2,
@@ -141,14 +141,14 @@ bool SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color
         return SDL_InvalidParamError("SDL_DrawLine(): dst");
     }
 
-    func = SDL_CalculateDrawLineFunc(dst->internal->format);
+    func = SDL_CalculateDrawLineFunc(dst->fmt);
     if (!func) {
         return SDL_SetError("SDL_DrawLine(): Unsupported surface format");
     }
 
     // Perform clipping
     // FIXME: We don't actually want to clip, as it may change line slope
-    if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
+    if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
         return true;
     }
 
@@ -168,7 +168,7 @@ bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32
         return SDL_InvalidParamError("SDL_DrawLines(): dst");
     }
 
-    func = SDL_CalculateDrawLineFunc(dst->internal->format);
+    func = SDL_CalculateDrawLineFunc(dst->fmt);
     if (!func) {
         return SDL_SetError("SDL_DrawLines(): Unsupported surface format");
     }
@@ -181,7 +181,7 @@ bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32
 
         // Perform clipping
         // FIXME: We don't actually want to clip, as it may change line slope
-        if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
+        if (!SDL_GetRectAndLineIntersection(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
             continue;
         }
 
diff --git a/src/render/

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