Don't set SDL_SURFACE_LOCK_NEEDED until a surface is RLE encoded

Reference https://github.com/libsdl-org/sdl2-compat/issues/476
This commit is contained in:
Sam Lantinga
2025-09-02 21:18:55 -07:00
parent fbbc29159a
commit 437d78499c
3 changed files with 7 additions and 5 deletions

View File

@@ -1434,6 +1434,7 @@ bool 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 true; return true;
} }
@@ -1565,11 +1566,12 @@ void SDL_UnRLESurface(SDL_Surface *surface, bool recode)
} }
} }
} }
surface->map.info.flags &= surface->map.info.flags &= ~(SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY);
~(SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY);
SDL_free(surface->map.data); SDL_free(surface->map.data);
surface->map.data = NULL; surface->map.data = NULL;
SDL_UpdateSurfaceLockFlag(surface);
} }
} }

View File

@@ -191,7 +191,7 @@ bool SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst)
#ifdef SDL_HAVE_RLE #ifdef SDL_HAVE_RLE
// Clean everything out to start // Clean everything out to start
if (surface->flags & SDL_INTERNAL_SURFACE_RLEACCEL) { if (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
SDL_UnRLESurface(surface, true); SDL_UnRLESurface(surface, true);
} }
#endif #endif

View File

@@ -49,7 +49,7 @@ bool SDL_SurfaceValid(SDL_Surface *surface)
void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface) void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface)
{ {
if (SDL_SurfaceHasRLE(surface)) { if (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
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;
@@ -611,7 +611,6 @@ bool SDL_SetSurfaceRLE(SDL_Surface *surface, bool enabled)
if (surface->map.info.flags != flags) { if (surface->map.info.flags != flags) {
SDL_InvalidateMap(&surface->map); SDL_InvalidateMap(&surface->map);
} }
SDL_UpdateSurfaceLockFlag(surface);
return true; return true;
} }
@@ -1760,6 +1759,7 @@ bool SDL_LockSurface(SDL_Surface *surface)
if (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL) { if (surface->internal_flags & SDL_INTERNAL_SURFACE_RLEACCEL) {
SDL_UnRLESurface(surface, true); SDL_UnRLESurface(surface, 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
} }