mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
Store the surface properties in the reserved pointer of a surface
This prevents us from exposing the properties publicly and allows us to repurpose the pointer later if necessary. Fixes https://github.com/libsdl-org/SDL/issues/8758
This commit is contained in:
@@ -104,11 +104,7 @@ typedef struct SDL_Surface
|
|||||||
int pitch; /**< Read-only */
|
int pitch; /**< Read-only */
|
||||||
void *pixels; /**< Read-write */
|
void *pixels; /**< Read-write */
|
||||||
|
|
||||||
/** Application data associated with the surface */
|
void *reserved; /**< Private */
|
||||||
union {
|
|
||||||
void *reserved; /**< For ABI compatibility only, do not use */
|
|
||||||
SDL_PropertiesID props; /**< Read-only */
|
|
||||||
};
|
|
||||||
|
|
||||||
/** information needed for surfaces requiring locks */
|
/** information needed for surfaces requiring locks */
|
||||||
int locked; /**< Read-only */
|
int locked; /**< Read-only */
|
||||||
|
@@ -252,23 +252,28 @@ SDL_Surface *SDL_CreateSurfaceFrom(void *pixels, int width, int height, int pitc
|
|||||||
|
|
||||||
SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
|
SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
|
SDL_PropertiesID props;
|
||||||
|
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
SDL_InvalidParamError("surface");
|
SDL_InvalidParamError("surface");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(surface->flags & SDL_SURFACE_USES_PROPERTIES)) {
|
if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
|
||||||
|
props = (SDL_PropertiesID)(uintptr_t)surface->reserved;
|
||||||
|
} else {
|
||||||
if (surface->reserved != NULL) {
|
if (surface->reserved != NULL) {
|
||||||
SDL_SetError("Surface has userdata, incompatible with properties");
|
SDL_SetError("Surface has userdata, incompatible with properties");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
surface->props = SDL_CreateProperties();
|
props = SDL_CreateProperties();
|
||||||
if (surface->props) {
|
if (props) {
|
||||||
|
surface->reserved = (void *)(uintptr_t)props;
|
||||||
surface->flags |= SDL_SURFACE_USES_PROPERTIES;
|
surface->flags |= SDL_SURFACE_USES_PROPERTIES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return surface->props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
|
int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette)
|
||||||
@@ -1570,7 +1575,8 @@ void SDL_DestroySurface(SDL_Surface *surface)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
|
if (surface->flags & SDL_SURFACE_USES_PROPERTIES) {
|
||||||
SDL_DestroyProperties(surface->props);
|
SDL_PropertiesID props = (SDL_PropertiesID)(uintptr_t)surface->reserved;
|
||||||
|
SDL_DestroyProperties(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_InvalidateMap(surface->map);
|
SDL_InvalidateMap(surface->map);
|
||||||
|
Reference in New Issue
Block a user