diff --git a/gemrb/core/Sprite2D.cpp b/gemrb/core/Sprite2D.cpp index 7d64b3b6ae..7871bc483f 100644 --- a/gemrb/core/Sprite2D.cpp +++ b/gemrb/core/Sprite2D.cpp @@ -32,6 +32,7 @@ Sprite2D::Sprite2D(int Width, int Height, int Bpp, const void* pixels) : Width(Width), Height(Height), Bpp(Bpp), pixels(pixels) { BAM = false; + RLE = false; XPos = 0; YPos = 0; RefCount = 1; @@ -41,6 +42,7 @@ Sprite2D::Sprite2D(int Width, int Height, int Bpp, const void* pixels) Sprite2D::Sprite2D(const Sprite2D &obj) { BAM = false; + RLE = false; RefCount = 1; XPos = obj.XPos; diff --git a/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.cpp b/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.cpp index 89bf1a1456..c896b93e82 100644 --- a/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.cpp +++ b/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.cpp @@ -32,9 +32,7 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(int Width, int Height, int Bpp, void* pix surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ), 0, 0, 0, 0 ); freePixels = true; -#if SDL_VERSION_ATLEAST(1,3,0) - SDL_SetSurfaceRLE(surface, SDL_TRUE); -#endif + SetSurfaceRLE(true); } SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pixels, @@ -44,9 +42,7 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pi surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ), rmask, gmask, bmask, amask ); freePixels = true; -#if SDL_VERSION_ATLEAST(1,3,0) - SDL_SetSurfaceRLE(surface, SDL_TRUE); -#endif + SetSurfaceRLE(true); } SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj) @@ -55,9 +51,7 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj) surface = SDL_ConvertSurface(obj.surface, obj.surface->format, obj.surface->flags); pixels = surface->pixels; freePixels = false; -#if SDL_VERSION_ATLEAST(1,3,0) - SDL_SetSurfaceRLE(surface, SDL_TRUE); -#endif + SetSurfaceRLE(obj.RLE); } SDLSurfaceSprite2D* SDLSurfaceSprite2D::copy() const @@ -114,6 +108,7 @@ ieDword SDLSurfaceSprite2D::GetColorKey() const void SDLSurfaceSprite2D::SetColorKey(ieDword ck) { #if SDL_VERSION_ATLEAST(1,3,0) + // SDL 2 will enforce SDL_RLEACCEL SDL_SetColorKey(surface, SDL_TRUE, ck); #else SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, ck); @@ -190,6 +185,24 @@ bool SDLSurfaceSprite2D::ConvertFormatTo(int bpp, ieDword rmask, ieDword gmask, return false; } +void SDLSurfaceSprite2D::SetSurfaceRLE(bool rle) +{ +#if SDL_VERSION_ATLEAST(1,3,0) + SDL_SetSurfaceRLE(surface, rle); +#else + if (rle) { + surface->flags |= SDL_RLEACCEL; + } else { + surface->flags &= ~SDL_RLEACCEL; + } +#endif + // regardless of rle or the success of SDL_SetSurfaceRLE + // we must keep RLE false because SDL hides the actual RLE data from us (see SDL_BlitMap) + // and we are left to access the pixels in decoded form (updated by SDL_UnlockSurface). + // SDL Blits will make use of RLE acceleration, but our internal blitters cannot. + assert(RLE == false); +} + void SDLSurfaceSprite2D::SetSurfacePalette(SDL_Surface* surf, SDL_Color* pal, int numcolors) { #if SDL_VERSION_ATLEAST(1,3,0) diff --git a/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.h b/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.h index e5b3e97347..ea2490a294 100644 --- a/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.h +++ b/gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.h @@ -32,6 +32,8 @@ class SDLSurfaceSprite2D : public Sprite2D { private: bool freePixels; SDL_Surface* surface; +private: + void SetSurfaceRLE(bool); public: SDLSurfaceSprite2D(int Width, int Height, int Bpp, void* pixels); SDLSurfaceSprite2D(int Width, int Height, int Bpp, void* pixels,