Added SDL_CreateSurfaceUninitialized()

Currently this is an internal API, but we can expose it in the future.
This commit is contained in:
Sam Lantinga
2026-06-05 07:46:31 -07:00
parent 2fd15d9e0d
commit fa2a726cc3
27 changed files with 65 additions and 48 deletions

View File

@@ -1651,7 +1651,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
return NULL;
}
} else if (SDL_ISPIXELFORMAT_INDEXED(texture->format)) {
texture->palette_surface = SDL_CreateSurface(w, h, texture->format);
texture->palette_surface = SDL_CreateSurfaceZeroed(w, h, texture->format);
if (!texture->palette_surface) {
SDL_DestroyTexture(texture);
return NULL;
@@ -5956,7 +5956,7 @@ static bool CreateDebugTextAtlas(SDL_Renderer *renderer)
// actually make each glyph two pixels taller/wider, to prevent scaling artifacts.
const int rows = (SDL_DEBUG_FONT_NUM_GLYPHS / SDL_DEBUG_FONT_GLYPHS_PER_ROW) + 1;
SDL_Surface *atlas = SDL_CreateSurface((charWidth + 2) * SDL_DEBUG_FONT_GLYPHS_PER_ROW, rows * (charHeight + 2), SDL_PIXELFORMAT_INDEX8);
SDL_Surface *atlas = SDL_CreateSurfaceZeroed((charWidth + 2) * SDL_DEBUG_FONT_GLYPHS_PER_ROW, rows * (charHeight + 2), SDL_PIXELFORMAT_INDEX8);
if (!atlas) {
return false;
}

View File

@@ -372,7 +372,7 @@ bool SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, SDL
swdata->target_format = target_format;
}
if (!swdata->stretch) {
swdata->stretch = SDL_CreateSurface(swdata->w, swdata->h, target_format);
swdata->stretch = SDL_CreateSurfaceUninitialized(swdata->w, swdata->h, target_format);
if (!swdata->stretch) {
return false;
}

View File

@@ -1397,7 +1397,7 @@ static SDL_Surface *GPU_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
return NULL;
}
SDL_Surface *surface = SDL_CreateSurface(rect->w, rect->h, pixfmt);
SDL_Surface *surface = SDL_CreateSurfaceUninitialized(rect->w, rect->h, pixfmt);
if (!surface) {
return NULL;

View File

@@ -2063,7 +2063,7 @@ static SDL_Surface *METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
SDL_SetError("Unknown framebuffer pixel format");
return NULL;
}
surface = SDL_CreateSurface(read_rect.w, read_rect.h, format);
surface = SDL_CreateSurfaceUninitialized(read_rect.w, read_rect.h, format);
if (surface) {
[mtltexture getBytes:surface->pixels bytesPerRow:surface->pitch fromRegion:mtlregion mipmapLevel:0];
if (SDL_RenderingLinearSpace(renderer) &&

View File

@@ -1630,7 +1630,7 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
return NULL;
}
surface = SDL_CreateSurface(rect->w, rect->h, format);
surface = SDL_CreateSurfaceUninitialized(rect->w, rect->h, format);
if (!surface) {
return NULL;
}

View File

@@ -958,7 +958,7 @@ static SDL_Surface *GLES_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect
SDL_PixelFormat format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
SDL_Surface *surface;
surface = SDL_CreateSurface(rect->w, rect->h, format);
surface = SDL_CreateSurfaceUninitialized(rect->w, rect->h, format);
if (!surface) {
return NULL;
}

View File

@@ -2235,7 +2235,7 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
SDL_PixelFormat format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
SDL_Surface *surface;
surface = SDL_CreateSurface(rect->w, rect->h, format);
surface = SDL_CreateSurfaceUninitialized(rect->w, rect->h, format);
if (!surface) {
return NULL;
}

View File

@@ -135,7 +135,7 @@ static bool SW_ChangeTexturePalette(SDL_Renderer *renderer, SDL_Texture *texture
static bool SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props)
{
SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format);
SDL_Surface *surface = SDL_CreateSurfaceUninitialized(texture->w, texture->h, texture->format);
if (!surface) {
return SDL_SetError("Can't create surface");
}
@@ -438,7 +438,7 @@ static bool SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Te
* to clear the pixels in the destination surface. The other steps are explained below.
*/
if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) {
mask = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
mask = SDL_CreateSurfaceZeroed(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
if (!mask) {
result = false;
} else {
@@ -451,7 +451,7 @@ static bool SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Te
*/
if (result && (blitRequired || applyModulation)) {
SDL_Rect scale_rect = tmp_rect;
src_scaled = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
src_scaled = SDL_CreateSurfaceUninitialized(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
if (!src_scaled) {
result = false;
} else {
@@ -871,7 +871,7 @@ static bool SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
// 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_PixelFormat tmp_format = SDL_ISPIXELFORMAT_ALPHA(src->format) ? SDL_PIXELFORMAT_ARGB8888 : surface->format;
SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, tmp_format);
SDL_Surface *tmp = SDL_CreateSurfaceUninitialized(dstrect->w, dstrect->h, tmp_format);
// Scale to an intermediate surface, then blit
if (tmp) {
SDL_Rect r;

View File

@@ -299,7 +299,7 @@ bool SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poi
}
// Use an intermediate surface
tmp = SDL_CreateSurface(dstrect.w, dstrect.h, format);
tmp = SDL_CreateSurfaceZeroed(dstrect.w, dstrect.h, format);
if (!tmp) {
result = false;
goto end;

View File

@@ -1172,7 +1172,7 @@ static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_
return NULL;
}
surface = SDL_CreateSurface(rect->w, rect->h, format);
surface = SDL_CreateSurfaceUninitialized(rect->w, rect->h, format);
if (!surface) {
return NULL;
}