From 932f61348d6ed278fa8ce1599dc7c8347ee68680 Mon Sep 17 00:00:00 2001
From: Sylvain Becker <[EMAIL REDACTED]>
Date: Thu, 1 Dec 2022 17:04:02 +0100
Subject: [PATCH] Remove mask versions of SDL_CreateRGBSurface* #6701 (#6711)
* Rename SDL_CreateRGBSurface{,From} to SDL_CreateSurface{,From}, which now takes a format parameter
---
WhatsNew.txt | 10 +-
Xcode-iOS/Demos/src/fireworks.c | 10 +-
Xcode-iOS/Demos/src/keyboard.c | 10 +-
docs/README-migration.md | 35 +++++-
include/SDL3/SDL_pixels.h | 2 +-
include/SDL3/SDL_surface.h | 112 ++----------------
src/dynapi/SDL_dynapi_overrides.h | 6 +-
src/dynapi/SDL_dynapi_procs.h | 6 +-
src/events/SDL_mouse.c | 6 +-
src/render/SDL_render.c | 2 +-
src/render/SDL_yuv_sw.c | 17 +--
src/render/software/SDL_render_sw.c | 38 +++---
src/render/software/SDL_rotate.c | 6 +-
src/render/software/SDL_triangle.c | 2 +-
src/test/SDL_test_common.c | 10 +-
src/test/SDL_test_font.c | 3 +-
src/test/SDL_test_imageBlit.c | 51 +-------
src/test/SDL_test_imageBlitBlend.c | 85 ++-----------
src/test/SDL_test_imageFace.c | 16 +--
src/test/SDL_test_imagePrimitives.c | 17 +--
src/test/SDL_test_imagePrimitivesBlend.c | 17 +--
src/video/SDL_bmp.c | 21 +++-
src/video/SDL_surface.c | 92 ++------------
src/video/SDL_video.c | 8 +-
src/video/android/SDL_androidmouse.c | 2 +-
src/video/dummy/SDL_nullframebuffer.c | 2 +-
.../emscripten/SDL_emscriptenframebuffer.c | 5 +-
src/video/n3ds/SDL_n3dsframebuffer.c | 6 +-
src/video/ngage/SDL_ngageframebuffer.cpp | 2 +-
.../offscreen/SDL_offscreenframebuffer.c | 2 +-
src/video/windows/SDL_windowsmouse.c | 2 +-
test/testautomation_render.c | 70 ++++++-----
test/testautomation_surface.c | 82 ++++++-------
test/testoffscreen.c | 11 +-
test/testshader.c | 10 +-
test/testyuv.c | 4 +-
36 files changed, 217 insertions(+), 563 deletions(-)
diff --git a/WhatsNew.txt b/WhatsNew.txt
index 833e28bd4443..44fc5ef13b62 100644
--- a/WhatsNew.txt
+++ b/WhatsNew.txt
@@ -19,13 +19,19 @@ General:
* SDL_RWFromFP()
* SDL_SetWindowBrightness()
* SDL_SetWindowGammaRamp()
+ * SDL_CreateRGBSurface()
+ * SDL_CreateRGBSurfaceWithFormat()
+ * SDL_CreateRGBSurfaceFrom()
+ * SDL_CreateRGBSurfaceWithFormatFrom()
* Removed the following hints from the API, see docs/README-migration.md for details:
* SDL_HINT_IDLE_TIMER_DISABLED
* SDL_HINT_VIDEO_X11_FORCE_EGL
* SDL_HINT_VIDEO_X11_XINERAMA
* SDL_HINT_VIDEO_X11_XVIDMODE
* SDL_stdinc.h no longer includes stdio.h, stdlib.h, etc., it only provides the SDL C runtime functionality
-* Removed unused 'depth' parameter from SDL_CreateRGBSurfaceWithFormat and SDL_CreateRGBSurfaceWithFormatFrom
-* Removed unused 'flags' parameter from SDL_CreateRGBSurface and SDL_CreateRGBSurfaceWithFormat
* Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat
+* Added SDL_CreateSurface() and SDL_CreateSurfaceFrom() which take a format. SDL_CreateRGBSurface*() are removed.
+
+
+
diff --git a/Xcode-iOS/Demos/src/fireworks.c b/Xcode-iOS/Demos/src/fireworks.c
index dbb86f392aff..43427b49e455 100644
--- a/Xcode-iOS/Demos/src/fireworks.c
+++ b/Xcode-iOS/Demos/src/fireworks.c
@@ -327,8 +327,6 @@ void
initializeTexture()
{
- int bpp; /* texture bits per pixel */
- Uint32 Rmask, Gmask, Bmask, Amask; /* masks for pixel format passed into OpenGL */
SDL_Surface *bmp_surface; /* the bmp is loaded here */
SDL_Surface *bmp_surface_rgba8888; /* this serves as a destination to convert the BMP
to format passed into OpenGL */
@@ -338,13 +336,9 @@ initializeTexture()
fatalError("could not load stroke.bmp");
}
- /* Grab info about format that will be passed into OpenGL */
- SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, &bpp, &Rmask, &Gmask,
- &Bmask, &Amask);
/* Create surface that will hold pixels passed into OpenGL */
- bmp_surface_rgba8888 =
- SDL_CreateRGBSurface(bmp_surface->w, bmp_surface->h, bpp, Rmask,
- Gmask, Bmask, Amask);
+ bmp_surface_rgba8888 = SDL_CreateSurface(bmp_surface->w, bmp_surface->h, SDL_PIXELFORMAT_ABGR8888);
+
/* Blit to this surface, effectively converting the format */
SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba8888, NULL);
diff --git a/Xcode-iOS/Demos/src/keyboard.c b/Xcode-iOS/Demos/src/keyboard.c
index e9896977d9b5..2d0ae841c8d3 100644
--- a/Xcode-iOS/Demos/src/keyboard.c
+++ b/Xcode-iOS/Demos/src/keyboard.c
@@ -173,13 +173,9 @@ loadFont(void)
SDL_SetColorKey(surface, 1, SDL_MapRGB(surface->format, 238, 0, 252));
/* now we convert the surface to our desired pixel format */
int format = SDL_PIXELFORMAT_ABGR8888; /* desired texture format */
- Uint32 Rmask, Gmask, Bmask, Amask; /* masks for desired format */
- int bpp; /* bits per pixel for desired format */
- SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask,
- &Amask);
- SDL_Surface *converted =
- SDL_CreateRGBSurface(surface->w, surface->h, bpp, Rmask, Gmask,
- Bmask, Amask);
+
+ SDL_Surface *converted = SDL_CreateSurface(surface->w, surface->h, format);
+
SDL_BlitSurface(surface, NULL, converted, NULL);
/* create our texture */
texture = SDL_CreateTextureFromSurface(renderer, converted);
diff --git a/docs/README-migration.md b/docs/README-migration.md
index d7aeb5c085ca..1016004c3c0c 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -162,9 +162,38 @@ M_PI is no longer defined in SDL_stdinc.h, you can use the new symbols SDL_PI_D
## SDL_surface.h
-Removed unused 'depth' parameter from SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom()
-Removed unused 'flags' parameter from SDL_CreateRGBSurface() and SDL_CreateRGBSurfaceWithFormat()
-Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat
+Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat.
+
+
+Added SDL_CreateSurface() and SDL_CreateSurfaceFrom() which take a format.
+SDL_CreateRGBSurface(), SDL_CreateRGBSurfaceFrom(), SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom() are removed.
+
+This code:
+
+```c
+SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 0, Rmask, Gmask, Bmask, Amask);
+```
+
+can be replaced with this:
+
+```c
+Uint32 format = SDL_MasksToPixelFormatEnum(0, Rmask, Gmask, Bmask, Amask);
+SDL_Surface *surface = SDL_CreateSurface(width, height, format);
+```
+
+but in general, you probably have a format that you know you're using, possibly one of these:
+
+
+```c
+// Various mask (R, G, B, A) in little endian and their corresponding format:
+0xFF000000 0x00FF0000 0x0000FF00 0x000000FF => SDL_PIXELFORMAT_RGBA8888
+0x000000FF 0x0000FF00 0x00FF0000 0xFF000000 => SDL_PIXELFORMAT_ABGR8888
+0x00FF0000 0x0000FF00 0x000000FF 0xFF000000 => SDL_PIXELFORMAT_ARGB8888
+0x00FF0000 0x0000FF00 0x000000FF 0x00000000 => SDL_PIXELFORMAT_BGR24
+0x000000FF 0x0000FF00 0x000000FF 0x00000000 => SDL_PIXELFORMAT_RGB24
+0x00007C00 00000x03E0 00000x001F 0x00000000 => SDL_PIXELFORMAT_RGB555
+0x00007C00 00000x03E0 00000x001F 0x00008000 => SDL_PIXELFORMAT_ARGB1555
+```
## SDL_syswm.h
diff --git a/include/SDL3/SDL_pixels.h b/include/SDL3/SDL_pixels.h
index 0f041e84604d..39045094f8d3 100644
--- a/include/SDL3/SDL_pixels.h
+++ b/include/SDL3/SDL_pixels.h
@@ -468,7 +468,7 @@ extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AllocPalette
- * \sa SDL_CreateRGBSurface
+ * \sa SDL_CreateSurface
*/
extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette,
const SDL_Color * colors,
diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h
index c2d832b49130..32d833137c20 100644
--- a/include/SDL3/SDL_surface.h
+++ b/include/SDL3/SDL_surface.h
@@ -113,61 +113,9 @@ typedef enum
SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */
} SDL_YUV_CONVERSION_MODE;
-/**
- * Allocate a new RGB surface.
- *
- * If `depth` is 4 or 8 bits, an empty palette is allocated for the surface.
- * If `depth` is greater than 8 bits, the pixel format is set using the
- * [RGBA]mask parameters.
- *
- * The [RGBA]mask parameters are the bitmasks used to extract that color from
- * a pixel. For instance, `Rmask` being 0xFF000000 means the red data is
- * stored in the most significant byte. Using zeros for the RGB masks sets a
- * default value, based on the depth. For example:
- *
- * ```c++
- * SDL_CreateRGBSurface(0,w,h,32,0,0,0,0);
- * ```
- *
- * However, using zero for the Amask results in an Amask of 0.
- *
- * By default surfaces with an alpha mask are set up for blending as with:
- *
- * ```c++
- * SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)
- * ```
- *
- * You can change this by calling SDL_SetSurfaceBlendMode() and selecting a
- * different `blendMode`.
- *
- * \param width the width of the surface
- * \param height the height of the surface
- * \param depth the depth of the surface in bits
- * \param Rmask the red mask for the pixels
- * \param Gmask the green mask for the pixels
- * \param Bmask the blue mask for the pixels
- * \param Amask the alpha mask for the pixels
- * \returns the new SDL_Surface structure that is created or NULL if it fails;
- * call SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_CreateRGBSurfaceFrom
- * \sa SDL_CreateRGBSurfaceWithFormat
- * \sa SDL_FreeSurface
- */
-extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
- (int width, int height, int depth,
- Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
-
-
/**
* Allocate a new RGB surface with a specific pixel format.
*
- * This function operates mostly like SDL_CreateRGBSurface(), except instead
- * of providing pixel color masks, you provide it with a predefined format
- * from SDL_PixelFormatEnum.
- *
* \param width the width of the surface
* \param height the height of the surface
* \param format the SDL_PixelFormatEnum for the new surface's pixel format.
@@ -176,59 +124,16 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
*
* \since This function is available since SDL 3.0.0.
*
- * \sa SDL_CreateRGBSurface
- * \sa SDL_CreateRGBSurfaceFrom
+ * \sa SDL_CreateSurfaceFrom
* \sa SDL_FreeSurface
*/
-extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface
(int width, int height, Uint32 format);
-/**
- * Allocate a new RGB surface with existing pixel data.
- *
- * This function operates mostly like SDL_CreateRGBSurface(), except it does
- * not allocate memory for the pixel data, instead the caller provides an
- * existing buffer of data for the surface to use.
- *
- * No copy is made of the pixel data. Pixel data is not managed automatically;
- * you must free the surface before you free the pixel data.
- *
- * \param pixels a pointer to existing pixel data
- * \param width the width of the surface
- * \param height the height of the surface
- * \param depth the depth of the surface in bits
- * \param pitch the pitch of the surface in bytes
- * \param Rmask the red mask for the pixels
- * \param Gmask the green mask for the pixels
- * \param Bmask the blue mask for the pixels
- * \param Amask the alpha mask for the pixels
- * \returns the new SDL_Surface structure that is created or NULL if it fails;
- * call SDL_GetError() for more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_CreateRGBSurface
- * \sa SDL_CreateRGBSurfaceWithFormat
- * \sa SDL_FreeSurface
- */
-extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
- int width,
- int height,
- int depth,
- int pitch,
- Uint32 Rmask,
- Uint32 Gmask,
- Uint32 Bmask,
- Uint32 Amask);
-
/**
* Allocate a new RGB surface with with a specific pixel format and existing
* pixel data.
*
- * This function operates mostly like SDL_CreateRGBSurfaceFrom(), except
- * instead of providing pixel color masks, you provide it with a predefined
- * format from SDL_PixelFormatEnum.
- *
* No copy is made of the pixel data. Pixel data is not managed automatically;
* you must free the surface before you free the pixel data.
*
@@ -242,11 +147,10 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels,
*
* \since This function is available since SDL 3.0.0.
*
- * \sa SDL_CreateRGBSurfaceFrom
- * \sa SDL_CreateRGBSurfaceWithFormat
+ * \sa SDL_CreateSurface
* \sa SDL_FreeSurface
*/
-extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
+extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom
(void *pixels, int width, int height, int pitch, Uint32 format);
/**
@@ -258,8 +162,8 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom
*
* \since This function is available since SDL 3.0.0.
*
- * \sa SDL_CreateRGBSurface
- * \sa SDL_CreateRGBSurfaceFrom
+ * \sa SDL_CreateSurface
+ * \sa SDL_CreateSurfaceFrom
* \sa SDL_LoadBMP
* \sa SDL_LoadBMP_RW
*/
@@ -660,7 +564,7 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface)
*
* \sa SDL_AllocFormat
* \sa SDL_ConvertSurfaceFormat
- * \sa SDL_CreateRGBSurface
+ * \sa SDL_CreateSurface
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
(SDL_Surface * src, const SDL_PixelFormat * fmt);
@@ -683,7 +587,7 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
*
* \sa SDL_AllocFormat
* \sa SDL_ConvertSurface
- * \sa SDL_CreateRGBSurface
+ * \sa SDL_CreateSurface
*/
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat
(SDL_Surface * src, Uint32 pixel_format);
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index f2c4d0c54438..a021787a6191 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -437,8 +437,6 @@
#define SDL_iconv_close SDL_iconv_close_REAL
#define SDL_iconv SDL_iconv_REAL
#define SDL_iconv_string SDL_iconv_string_REAL
-#define SDL_CreateRGBSurface SDL_CreateRGBSurface_REAL
-#define SDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom_REAL
#define SDL_FreeSurface SDL_FreeSurface_REAL
#define SDL_SetSurfacePalette SDL_SetSurfacePalette_REAL
#define SDL_LockSurface SDL_LockSurface_REAL
@@ -592,8 +590,8 @@
#define SDL_RenderGetIntegerScale SDL_RenderGetIntegerScale_REAL
#define SDL_DequeueAudio SDL_DequeueAudio_REAL
#define SDL_SetWindowResizable SDL_SetWindowResizable_REAL
-#define SDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat_REAL
-#define SDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom_REAL
+#define SDL_CreateSurface SDL_CreateSurface_REAL
+#define SDL_CreateSurfaceFrom SDL_CreateSurfaceFrom_REAL
#define SDL_GetHintBoolean SDL_GetHintBoolean_REAL
#define SDL_JoystickGetDeviceVendor SDL_JoystickGetDeviceVendor_REAL
#define SDL_JoystickGetDeviceProduct SDL_JoystickGetDeviceProduct_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 2e704ebfbb18..389c3b35d10a 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -464,8 +464,6 @@ SDL_DYNAPI_PROC(SDL_iconv_t,SDL_iconv_open,(const char *a, const char *b),(a,b),
SDL_DYNAPI_PROC(int,SDL_iconv_close,(SDL_iconv_t a),(a),return)
SDL_DYNAPI_PROC(size_t,SDL_iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(char*,SDL_iconv_string,(const char *a, const char *b, const char *c, size_t d),(a,b,c,d),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurface,(int a, int b, int c, Uint32 d, Uint32 e, Uint32 f, Uint32 g),(a,b,c,d,e,f,g),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceFrom,(void *a, int b, int c, int d, int e, Uint32 f, Uint32 g, Uint32 h, Uint32 i),(a,b,c,d,e,f,g,h,i),return)
SDL_DYNAPI_PROC(void,SDL_FreeSurface,(SDL_Surface *a),(a),)
SDL_DYNAPI_PROC(int,SDL_SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return)
@@ -625,8 +623,8 @@ SDL_DYNAPI_PROC(int,SDL_RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b),(a,b
SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGetIntegerScale,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return)
SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormat,(int a, int b, Uint32 c),(a,b,c),return)
-SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurface,(int a, int b, Uint32 c),(a,b,c),return)
+SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurfaceFrom,(void *a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceVendor,(int a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceProduct,(int a),(a),return)
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index cded60d0411f..b9d7bf02ed7c 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -1221,11 +1221,7 @@ SDL_CreateCursor(const Uint8 *data, const Uint8 *mask,
w = ((w + 7) & ~7);
/* Create the surface from a bitmap */
- surface = SDL_CreateRGBSurface(w, h, 32,
- 0x00FF0000,
- 0x0000FF00,
- 0x000000FF,
- 0xFF000000);
+ surface = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_ARGB8888);
if (surface == NULL) {
return NULL;
}
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 0962bbe385c2..21b51f6c0042 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -2077,7 +2077,7 @@ int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect,
return ret;
}
- texture->locked_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, real_rect.w, real_rect.h, pitch, texture->format);
+ texture->locked_surface = SDL_CreateSurfaceFrom(pixels, real_rect.w, real_rect.h, pitch, texture->format);
if (texture->locked_surface == NULL) {
SDL_UnlockTexture(texture);
return -1;
diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c
index d5a3f46dd55f..403bed504954 100644
--- a/src/render/SDL_yuv_sw.c
+++ b/src/render/SDL_yuv_sw.c
@@ -377,32 +377,19 @@ int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect,
stretch = 1;
}
if (stretch) {
- int bpp;
- Uint32 Rmask, Gmask, Bmask, Amask;
-
if (swdata->display) {
swdata->display->w = w;
swdata->display->h = h;
swdata->display->pixels = pixels;
swdata->display->pitch = pitch;
} else {
- /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
- SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
- &Bmask, &Amask);
- swdata->display =
- SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask,
- Gmask, Bmask, Amask);
+ swdata->display = SDL_CreateSurfaceFrom(pixels, w, h, pitch, target_format);
if (!swdata->display) {
return -1;
}
}
if (!swdata->stretch) {
- /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */
- SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask,
- &Bmask, &Amask);
- swdata->stretch =
- SDL_CreateRGBSurface(swdata->w, swdata->h, bpp, Rmask,
- Gmask, Bmask, Amask);
+ swdata->stretch = SDL_CreateSurface(swdata->w, swdata->h, target_format);
if (!swdata->stretch) {
return -1;
}
diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c
index 973674363651..1241683ba5e4 100644
--- a/src/render/software/SDL_render_sw.c
+++ b/src/render/software/SDL_render_sw.c
@@ -99,16 +99,12 @@ static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
{
- int bpp;
- Uint32 Rmask, Gmask, Bmask, Amask;
+ SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format);
- if (!SDL_PixelFormatEnumToMasks(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
- return SDL_SetError("Unknown texture format");
+ if (surface == NULL) {
+ return SDL_SetError("Cannot create surface");
}
-
- texture->driverdata =
- SDL_CreateRGBSurface(texture->w, texture->h, bpp, Rmask, Gmask,
- Bmask, Amask);
+ texture->driverdata = surface;
SDL_SetSurfaceColorMod(texture->driverdata, texture->color.r, texture->color.g, texture->color.b);
SDL_SetSurfaceAlphaMod(texture->driverdata, texture->color.a);
SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
@@ -116,7 +112,7 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
/* Only RLE encode textures without an alpha channel since the RLE coder
* discards the color values of pixels with an alpha value of zero.
*/
- if (texture->access == SDL_TEXTUREACCESS_STATIC && !Amask) {
+ if (texture->access == SDL_TEXTUREACCESS_STATIC && !surface->format->Amask) {
SDL_SetSurfaceRLE(texture->driverdata, 1);
}
@@ -342,9 +338,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
/* Clone the source surface but use its pixel buffer directly.
* The original source surface must be treated as read-only.
*/
- src_clone = SDL_CreateRGBSurfaceFrom(src->pixels, src->w, src->h, src->format->BitsPerPixel, src->pitch,
- src->format->Rmask, src->format->Gmask,
- src->format->Bmask, src->format->Amask);
+ src_clone = SDL_CreateSurfaceFrom(src->pixels, src->w, src->h, src->pitch, src->format->format);
if (src_clone == NULL) {
if (SDL_MUSTLOCK(src)) {
SDL_UnlockSurface(src);
@@ -387,8 +381,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
* to clear the pixels in the destination surface. The other steps are explained below.
*/
if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) {
- mask = SDL_CreateRGBSurface(final_rect->w, final_rect->h, 32,
- 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
+ mask = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
if (mask == NULL) {
retval = -1;
} else {
@@ -401,8 +394,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
*/
if (!retval && (blitRequired || applyModulation)) {
SDL_Rect scale_rect = tmp_rect;
- src_scaled = SDL_CreateRGBSurface(final_rect->w, final_rect->h, 32,
- 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
+ src_scaled = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
if (src_scaled == NULL) {
retval = -1;
} else {
@@ -482,10 +474,14 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
* to be created. This makes all source pixels opaque and the colors get copied correctly.
*/
SDL_Surface *src_rotated_rgb;
- src_rotated_rgb = SDL_CreateRGBSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h,
- src_rotated->format->BitsPerPixel, src_rotated->pitch,
- src_rotated->format->Rmask, src_rotated->format->Gmask,
- src_rotated->format->Bmask, 0);
+ int f = SDL_MasksToPixelFormatEnum(src_rotated->format->BitsPerPixel,
+ src_rotated->format->Rmask,
+ src_rotated->format->Gmask,
+ src_rotated->format->Bmask,
+ 0);
+
+ src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h,
+ src_rotated->pitch, f);
if (src_rotated_rgb == NULL) {
retval = -1;
} else {
@@ -816,7 +812,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
/* Prevent to do scaling + clipping on viewport boundaries as it may lose proportion */
if (dstrect->x < 0 || dstrect->y < 0 || dstrect->x + dstrect->w > surface->w || dstrect->y + dstrect->h > surface->h) {
- SDL_Surface *tmp = SDL_CreateRGBSurfaceWithFormat(dstrect->w, dstrect->h, src->format->format);
+ SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, src->format->format);
/* Scale to an intermediate surface, then blit */
if (tmp) {
SDL_Rect r;
diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c
index 77786ba044a3..9b80292d4765 100644
--- a/src/render/software/SDL_rotate.c
+++ b/src/render/software/SDL_rotate.c
@@ -523,7 +523,7 @@ SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int
rz_dst = NULL;
if (is8bit) {
/* Target surface is 8 bit */
- rz_dst = SDL_CreateRGBSurfaceWithFormat(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
+ rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
if (rz_dst != NULL) {
if (src->format->palette) {
for (i = 0; i < src->format->palette->ncolors; i++) {
@@ -534,9 +534,7 @@ SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int
}
} else {
/* Target surface is 32 bit with source RGBA ordering */
- rz_dst = SDL_CreateRGBSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, 32,
- src->format->Rmask, src->format->Gmask,
- src->format->Bmask, src->format->Amask);
+ rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format);
}
/* Check target */
diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c
index 5d2a70f6f6c3..093d27740116 100644
--- a/src/render/software/SDL_triangle.c
+++ b/src/render/software/SDL_triangle.c
@@ -270,7 +270,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
}
/* Use an intermediate surface */
- tmp = SDL_CreateRGBSurfaceWithFormat(dstrect.w, dstrect.h, format);
+ tmp = SDL_CreateSurface(dstrect.w, dstrect.h, format);
if (tmp == NULL) {
ret = -1;
goto end;
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index e75be2bf6581..e7753595dcfd 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -1749,13 +1749,9 @@ static void SDLTest_ScreenShot(SDL_Renderer *renderer)
}
SDL_RenderGetViewport(renderer, &viewport);
- surface = SDL_CreateRGBSurface(viewport.w, viewport.h, 24,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN
- 0x00FF0000, 0x0000FF00, 0x000000FF,
-#else
- 0x000000FF, 0x0000FF00, 0x00FF0000,
-#endif
- 0x00000000);
+
+ surface = SDL_CreateSurface(viewport.w, viewport.h, SDL_PIXELFORMAT_BGR24);
+
if (surface == NULL) {
SDL_Log("Couldn't create surface: %s\n", SDL_GetError());
return;
diff --git a/src/test/SDL_test_font.c b/src/test/SDL_test_font.c
index 6840cbc0d6c6..b6cd5b9b2bf1 100644
--- a/src/test/SDL_test_font.c
+++ b/src/test/SDL_test_font.c
@@ -3185,8 +3185,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c)
/*
* Redraw character into surface
*/
- character = SDL_CreateRGBSurface(charWidth, charHeight, 32,
- 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
+ character = SDL_CreateSurface(charWidth, charHeight, SDL_PIXELFORMAT_RGBA8888);
if (character == NULL) {
return -1;
}
diff --git a/src/test/SDL_test_imageBlit.c b/src/test/SDL_test_imageBlit.c
index 7a226e636d17..e5a9ce861467 100644
--- a/src/test/SDL_test_imageBlit.c
+++ b/src/test/SDL_test_imageBlit.c
@@ -540,24 +540,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
*/
SDL_Surface *SDLTest_ImageBlit()
{
- SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(
+ SDL_Surface *surface = SDL_CreateSurfaceFrom(
(void *)SDLTest_imageBlit.pixel_data,
SDLTest_imageBlit.width,
SDLTest_imageBlit.height,
- SDLTest_imageBlit.bytes_per_pixel * 8,
- SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel,
-#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
- 0xff000000, /* Red bit mask. */
- 0x00ff0000, /* Green bit mask. */
- 0x0000ff00, /* Blue bit mask. */
- 0x000000ff /* Alpha bit mask. */
-#else
- 0x000000ff, /* Red bit mask. */
- 0x0000ff00, /* Green bit mask. */
- 0x00ff0000, /* B
(Patch may be truncated, please check the link at the top of this post.)