From eefcb62588685c4eae4653c5263e2e7c19116414 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 17 Jul 2024 14:03:53 -0700 Subject: [PATCH] SDL_MUSTLOCK() returns true once a surface has the RLE flag set This more closely matches the mental model of people using SDL, and locking a surface that isn't RLE encoded doesn't cause any issues. Fixes https://github.com/libsdl-org/SDL/issues/5594 --- src/video/SDL_RLEaccel.c | 7 +------ src/video/SDL_surface.c | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 6907a281c1..14db1a951f 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -62,7 +62,7 @@ * * Encoding of surfaces with per-pixel alpha: * - * The sequence begins with a struct SDL_PixelFormatDetails describing the target + * The sequence begins with an SDL_PixelFormat value describing the target * pixel format, to provide reliable un-encoding. * * Each scan line is encoded twice: First all completely opaque pixels, @@ -1425,7 +1425,6 @@ int SDL_RLESurface(SDL_Surface *surface) /* The surface is now accelerated */ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; - SDL_UpdateSurfaceLockFlag(surface); return 0; } @@ -1521,7 +1520,6 @@ void SDL_UnRLESurface(SDL_Surface *surface, SDL_bool recode) { if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) { surface->internal->flags &= ~SDL_INTERNAL_SURFACE_RLEACCEL; - SDL_UpdateSurfaceLockFlag(surface); if (recode && !(surface->flags & SDL_SURFACE_PREALLOCATED)) { if (surface->internal->map.info.flags & SDL_COPY_RLE_COLORKEY) { @@ -1532,14 +1530,12 @@ void SDL_UnRLESurface(SDL_Surface *surface, SDL_bool recode) if (SDL_size_mul_overflow(surface->h, surface->pitch, &size)) { /* Memory corruption? */ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; - SDL_UpdateSurfaceLockFlag(surface); return; } surface->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), size); if (!surface->pixels) { /* Oh crap... */ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; - SDL_UpdateSurfaceLockFlag(surface); return; } surface->flags |= SDL_SURFACE_SIMD_ALIGNED; @@ -1556,7 +1552,6 @@ void SDL_UnRLESurface(SDL_Surface *surface, SDL_bool recode) if (!UnRLEAlpha(surface)) { /* Oh crap... */ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; - SDL_UpdateSurfaceLockFlag(surface); return; } } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index e6d5c1f0b6..5714b11b2b 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -46,7 +46,7 @@ SDL_bool SDL_SurfaceValid(SDL_Surface *surface) void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface) { - if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) { + if (SDL_SurfaceHasRLE(surface)) { surface->flags |= SDL_SURFACE_LOCK_NEEDED; } else { surface->flags &= ~SDL_SURFACE_LOCK_NEEDED; @@ -460,6 +460,7 @@ int SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled) if (surface->internal->map.info.flags != flags) { SDL_InvalidateMap(&surface->internal->map); } + SDL_UpdateSurfaceLockFlag(surface); return 0; } @@ -1250,7 +1251,6 @@ int SDL_LockSurface(SDL_Surface *surface) if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) { SDL_UnRLESurface(surface, SDL_TRUE); surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; /* save accel'd state */ - SDL_UpdateSurfaceLockFlag(surface); } #endif }