Only set the colorspace if it's not the default

This avoids property hash table allocation in most cases
This commit is contained in:
Sam Lantinga
2024-02-03 11:36:44 -08:00
parent c0b27ccef9
commit 200f87ea0b

View File

@@ -276,6 +276,9 @@ int SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace)
return SDL_InvalidParamError("surface"); return SDL_InvalidParamError("surface");
} }
if (colorspace == SDL_GetDefaultColorspaceForFormat(surface->format->format)) {
return 0;
}
return SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace); return SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace);
} }
@@ -1537,7 +1540,7 @@ static SDL_bool SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_for
blitmap->info.a = 0xFF; blitmap->info.a = 0xFF;
surface->map = blitmap; surface->map = blitmap;
SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace); SDL_SetSurfaceColorspace(surface, colorspace);
/* The surface is ready to go */ /* The surface is ready to go */
surface->refcount = 1; surface->refcount = 1;
@@ -1549,7 +1552,9 @@ static void SDL_DestroySurfaceOnStack(SDL_Surface *surface)
/* Free blitmap reference, after blitting between stack'ed surfaces */ /* Free blitmap reference, after blitting between stack'ed surfaces */
SDL_InvalidateMap(surface->map); SDL_InvalidateMap(surface->map);
if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
SDL_DestroyProperties(SDL_GetSurfaceProperties(surface)); SDL_DestroyProperties(SDL_GetSurfaceProperties(surface));
}
} }
SDL_Surface *SDL_DuplicatePixels(int width, int height, Uint32 format, SDL_Colorspace colorspace, void *pixels, int pitch) SDL_Surface *SDL_DuplicatePixels(int width, int height, Uint32 format, SDL_Colorspace colorspace, void *pixels, int pitch)
@@ -1566,9 +1571,7 @@ SDL_Surface *SDL_DuplicatePixels(int width, int height, Uint32 format, SDL_Color
src += pitch; src += pitch;
} }
if (colorspace != SDL_GetDefaultColorspaceForFormat(format)) { SDL_SetSurfaceColorspace(surface, colorspace);
SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace);
}
} }
return surface; return surface;
} }