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
This commit is contained in:
Sam Lantinga
2024-07-17 14:03:53 -07:00
parent de6595bda6
commit eefcb62588
2 changed files with 3 additions and 8 deletions

View File

@@ -62,7 +62,7 @@
* *
* Encoding of surfaces with per-pixel alpha: * 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. * pixel format, to provide reliable un-encoding.
* *
* Each scan line is encoded twice: First all completely opaque pixels, * 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 */ /* The surface is now accelerated */
surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
SDL_UpdateSurfaceLockFlag(surface);
return 0; return 0;
} }
@@ -1521,7 +1520,6 @@ void SDL_UnRLESurface(SDL_Surface *surface, SDL_bool recode)
{ {
if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) { if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
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 (recode && !(surface->flags & SDL_SURFACE_PREALLOCATED)) {
if (surface->internal->map.info.flags & SDL_COPY_RLE_COLORKEY) { 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)) { if (SDL_size_mul_overflow(surface->h, surface->pitch, &size)) {
/* Memory corruption? */ /* Memory corruption? */
surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
SDL_UpdateSurfaceLockFlag(surface);
return; return;
} }
surface->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), size); surface->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), size);
if (!surface->pixels) { if (!surface->pixels) {
/* Oh crap... */ /* Oh crap... */
surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
SDL_UpdateSurfaceLockFlag(surface);
return; return;
} }
surface->flags |= SDL_SURFACE_SIMD_ALIGNED; surface->flags |= SDL_SURFACE_SIMD_ALIGNED;
@@ -1556,7 +1552,6 @@ void SDL_UnRLESurface(SDL_Surface *surface, SDL_bool recode)
if (!UnRLEAlpha(surface)) { if (!UnRLEAlpha(surface)) {
/* Oh crap... */ /* Oh crap... */
surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
SDL_UpdateSurfaceLockFlag(surface);
return; return;
} }
} }

View File

@@ -46,7 +46,7 @@ SDL_bool SDL_SurfaceValid(SDL_Surface *surface)
void SDL_UpdateSurfaceLockFlag(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; surface->flags |= SDL_SURFACE_LOCK_NEEDED;
} else { } else {
surface->flags &= ~SDL_SURFACE_LOCK_NEEDED; 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) { if (surface->internal->map.info.flags != flags) {
SDL_InvalidateMap(&surface->internal->map); SDL_InvalidateMap(&surface->internal->map);
} }
SDL_UpdateSurfaceLockFlag(surface);
return 0; return 0;
} }
@@ -1250,7 +1251,6 @@ int SDL_LockSurface(SDL_Surface *surface)
if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) { if (surface->internal->flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
SDL_UnRLESurface(surface, SDL_TRUE); SDL_UnRLESurface(surface, SDL_TRUE);
surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; /* save accel'd state */ surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; /* save accel'd state */
SDL_UpdateSurfaceLockFlag(surface);
} }
#endif #endif
} }