|
|
@@ -192,7 +192,7 @@ static bool SDL_InitializeSurface(SDL_Surface *surface, int width, int height, S
|
|
|
/*
|
|
|
* Create an empty surface of the appropriate depth using the given format
|
|
|
*/
|
|
|
-SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
|
|
|
+static SDL_Surface *SDL_CreateSurfaceInternal(int width, int height, SDL_PixelFormat format, bool clear_surface)
|
|
|
{
|
|
|
size_t pitch, size;
|
|
|
SDL_Surface *surface;
|
|
|
@@ -240,12 +240,29 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- // This is important for bitmaps
|
|
|
- SDL_memset(surface->pixels, 0, size);
|
|
|
+ if (clear_surface) {
|
|
|
+ SDL_memset(surface->pixels, 0, size);
|
|
|
+ }
|
|
|
}
|
|
|
return surface;
|
|
|
}
|
|
|
|
|
|
+SDL_Surface *SDL_CreateSurfaceZeroed(int width, int height, SDL_PixelFormat format)
|
|
|
+{
|
|
|
+ return SDL_CreateSurfaceInternal(width, height, format, true);
|
|
|
+}
|
|
|
+
|
|
|
+SDL_Surface *SDL_CreateSurfaceUninitialized(int width, int height, SDL_PixelFormat format)
|
|
|
+{
|
|
|
+ return SDL_CreateSurfaceInternal(width, height, format, false);
|
|
|
+}
|
|
|
+
|
|
|
+SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
|
|
|
+{
|
|
|
+ return SDL_CreateSurfaceZeroed(width, height, format);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/*
|
|
|
* Create an RGB surface from an existing memory buffer using the given
|
|
|
* enum SDL_PIXELFORMAT_* format
|
|
|
@@ -1336,7 +1353,7 @@ bool SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, S
|
|
|
// Intermediate scaling
|
|
|
if (is_complex_copy_flags || src->format != dst->format) {
|
|
|
SDL_Rect tmprect;
|
|
|
- SDL_Surface *tmp2 = SDL_CreateSurface(dstrect->w, dstrect->h, src->format);
|
|
|
+ SDL_Surface *tmp2 = SDL_CreateSurfaceUninitialized(dstrect->w, dstrect->h, src->format);
|
|
|
SDL_StretchSurface(src, &srcrect2, tmp2, NULL, SDL_SCALEMODE_LINEAR);
|
|
|
|
|
|
SDL_SetSurfaceColorMod(tmp2, r, g, b);
|
|
|
@@ -1927,7 +1944,7 @@ static SDL_Surface *SDL_ConvertSurfaceRectAndColorspace(SDL_Surface *surface, co
|
|
|
|
|
|
// Create a new surface with the desired format
|
|
|
if (surface->pixels || SDL_MUSTLOCK(surface)) {
|
|
|
- convert = SDL_CreateSurface(rect->w, rect->h, format);
|
|
|
+ convert = SDL_CreateSurfaceUninitialized(rect->w, rect->h, format);
|
|
|
} else {
|
|
|
convert = SDL_CreateSurfaceFrom(rect->w, rect->h, format, NULL, 0);
|
|
|
}
|
|
|
@@ -2089,7 +2106,7 @@ static SDL_Surface *SDL_ConvertSurfaceRectAndColorspace(SDL_Surface *surface, co
|
|
|
int converted_colorkey = 0;
|
|
|
|
|
|
// Create a dummy surface to get the colorkey converted
|
|
|
- tmp = SDL_CreateSurface(1, 1, surface->format);
|
|
|
+ tmp = SDL_CreateSurfaceUninitialized(1, 1, surface->format);
|
|
|
if (!tmp) {
|
|
|
goto error;
|
|
|
}
|
|
|
@@ -2265,7 +2282,7 @@ SDL_Surface *SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_S
|
|
|
|
|
|
// Create a new surface with the desired size
|
|
|
if (surface->pixels || SDL_MUSTLOCK(surface)) {
|
|
|
- convert = SDL_CreateSurface(width, height, surface->format);
|
|
|
+ convert = SDL_CreateSurfaceUninitialized(width, height, surface->format);
|
|
|
} else {
|
|
|
convert = SDL_CreateSurfaceFrom(width, height, surface->format, NULL, 0);
|
|
|
}
|
|
|
@@ -2342,7 +2359,7 @@ SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormat format,
|
|
|
{
|
|
|
SDL_Surface *surface;
|
|
|
if (pixels) {
|
|
|
- surface = SDL_CreateSurface(width, height, format);
|
|
|
+ surface = SDL_CreateSurfaceUninitialized(width, height, format);
|
|
|
} else {
|
|
|
surface = SDL_CreateSurfaceFrom(width, height, format, NULL, 0);
|
|
|
}
|
|
|
@@ -2607,7 +2624,7 @@ static bool SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_P
|
|
|
}
|
|
|
|
|
|
if (src_format != format || src_colorspace != colorspace) {
|
|
|
- convert = SDL_CreateSurface(width, height, format);
|
|
|
+ convert = SDL_CreateSurfaceUninitialized(width, height, format);
|
|
|
if (!convert) {
|
|
|
goto done;
|
|
|
}
|
|
|
@@ -2621,7 +2638,7 @@ static bool SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_P
|
|
|
dst_pitch = convert->pitch;
|
|
|
|
|
|
} else if (dst_format != format || dst_colorspace != colorspace) {
|
|
|
- convert = SDL_CreateSurface(width, height, format);
|
|
|
+ convert = SDL_CreateSurfaceUninitialized(width, height, format);
|
|
|
if (!convert) {
|
|
|
goto done;
|
|
|
}
|
|
|
@@ -2708,7 +2725,7 @@ bool SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
|
|
|
result = SDL_FillSurfaceRect(surface, NULL, color);
|
|
|
} else if (SDL_ISPIXELFORMAT_FOURCC(surface->format)) {
|
|
|
// We can't directly set an RGB value on a YUV surface
|
|
|
- SDL_Surface *tmp = SDL_CreateSurface(surface->w, surface->h, SDL_PIXELFORMAT_ARGB8888);
|
|
|
+ SDL_Surface *tmp = SDL_CreateSurfaceUninitialized(surface->w, surface->h, SDL_PIXELFORMAT_ARGB8888);
|
|
|
if (!tmp) {
|
|
|
goto done;
|
|
|
}
|
|
|
@@ -2719,7 +2736,7 @@ bool SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
|
|
|
SDL_DestroySurface(tmp);
|
|
|
} else {
|
|
|
// Take advantage of blit color conversion
|
|
|
- SDL_Surface *tmp = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA128_FLOAT);
|
|
|
+ SDL_Surface *tmp = SDL_CreateSurfaceUninitialized(1, 1, SDL_PIXELFORMAT_RGBA128_FLOAT);
|
|
|
if (!tmp) {
|
|
|
goto done;
|
|
|
}
|