surface: patched to compile.

This commit is contained in:
Ryan C. Gordon 2026-06-05 00:36:39 -04:00
parent 2f6c37ce13
commit 9ba2af2d34
No known key found for this signature in database
GPG key ID: FA148B892AB48044

View file

@ -51,22 +51,22 @@ static bool SDL_create_surface_malloc_hint = false; // tracks "SDL_SURFACE_MALL
static void SDLCALL SDL_CreateSurfaceZeroedChanged(void *userdata, const char *name, const char *oldValue, const char *newValue) static void SDLCALL SDL_CreateSurfaceZeroedChanged(void *userdata, const char *name, const char *oldValue, const char *newValue)
{ {
create_surface_zeroed_hint = SDL_GetStringBoolean(newValue, true); SDL_create_surface_zeroed_hint = SDL_GetStringBoolean(newValue, true);
} }
static void SDLCALL SDL_SurfaceMallocChanged(void *userdata, const char *name, const char *oldValue, const char *newValue) static void SDLCALL SDL_SurfaceMallocChanged(void *userdata, const char *name, const char *oldValue, const char *newValue)
{ {
create_surface_malloc_hint = SDL_GetStringBoolean(newValue, false); SDL_create_surface_malloc_hint = SDL_GetStringBoolean(newValue, false);
} }
// Public routines // Public routines
void SDL_QuitSurfaceHints(void) void SDL_QuitSurfaceHints(void)
{ {
if (SDL_ShouldQuit(&create_surface_hints_init)) { if (SDL_ShouldQuit(&SDL_create_surface_hints_init)) {
SDL_RemoveHintCallback(SDL_HINT_CREATE_SURFACE_ZEROED, SDL_SurfaceClearHintWatcher, NULL); SDL_RemoveHintCallback(SDL_HINT_CREATE_SURFACE_ZEROED, SDL_CreateSurfaceZeroedChanged, NULL);
SDL_RemoveHintCallback("SDL_SURFACE_MALLOC", SDL_SurfaceMallocHintWatcher, NULL); SDL_RemoveHintCallback("SDL_SURFACE_MALLOC", SDL_SurfaceMallocChanged, NULL);
SDL_SetInitialized(&create_surface_hints_init, false); SDL_SetInitialized(&SDL_create_surface_hints_init, false);
} }
} }
@ -255,15 +255,15 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format)
} }
if (surface->w && surface->h && format != SDL_PIXELFORMAT_MJPG) { if (surface->w && surface->h && format != SDL_PIXELFORMAT_MJPG) {
if (SDL_ShouldInit(&create_surface_hints_init)) { if (SDL_ShouldInit(&SDL_create_surface_hints_init)) {
SDL_AddHintCallback(SDL_HINT_CREATE_SURFACE_ZEROED, SDL_SurfaceClearHintWatcher, NULL); SDL_AddHintCallback(SDL_HINT_CREATE_SURFACE_ZEROED, SDL_CreateSurfaceZeroedChanged, NULL);
SDL_AddHintCallback("SDL_SURFACE_MALLOC", SDL_SurfaceMallocHintWatcher, NULL); SDL_AddHintCallback("SDL_SURFACE_MALLOC", SDL_SurfaceMallocChanged, NULL);
SDL_SetInitialized(&create_surface_hints_init, true); SDL_SetInitialized(&SDL_create_surface_hints_init, true);
} }
bool clear_surface = create_surface_zeroed_hint; // SDL_HINT_CREATE_SURFACE_ZEROED, tracked by callback. bool clear_surface = SDL_create_surface_zeroed_hint; // SDL_HINT_CREATE_SURFACE_ZEROED, tracked by callback.
surface->flags &= ~SDL_SURFACE_PREALLOCATED; surface->flags &= ~SDL_SURFACE_PREALLOCATED;
if (create_surface_malloc_hint) { // "SDL_SURFACE_MALLOC" hint, tracked by callback. if (SDL_create_surface_malloc_hint) { // "SDL_SURFACE_MALLOC" hint, tracked by callback.
if (clear_surface) { if (clear_surface) {
surface->pixels = SDL_calloc(1, size); surface->pixels = SDL_calloc(1, size);
clear_surface = false; // SDL_calloc already did it, don't memset again, below. clear_surface = false; // SDL_calloc already did it, don't memset again, below.