Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SDLSurfaceSprite2D: consolidate SetSurfaceRLE calls into a private fu…

…nction

this is hopefully compatible with SDL 1.2
  • Loading branch information...
commit 1ede2114f9b50ad92e12d77ed18132cd62360a5f 1 parent 43aa7fd
@bradallred bradallred authored
View
2  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;
View
31 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);
@wjp Owner
wjp added a note

It's not a good idea to always force SDL_RLEACCEL. First of all it is meaningless when there is no colourkey or per-pixel alpha, and second some sprites regularly need direct pixel data access (such as TIS tiles via BlitTile), and having to do an SDL_LockSurface each call will be too expensive.

@wjp Owner
wjp added a note

Also note that a few of our internal blitters (BlitTile, BlitGameSprite) currently use surface->pixels without calling SDL_LockSurface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
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;
@wjp Owner
wjp added a note

I strongly doubt you're allowed to set this flag on an SDL_Surface yourself. Use SDL_SetAlpha or SDL_SetColorKey for that.

@bradallred Owner

you are probably correct. IIRC i looked at the SDL source, but could have been SDL2 source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ } 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)
View
2  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,
Please sign in to comment.
Something went wrong with that request. Please try again.