Skip to content

Commit

Permalink
Made use of SDL_CreateRGBSurfaceWithFormat* on SDL 2.0.6+
Browse files Browse the repository at this point in the history
These functions were introduced in 2.0.5, but a packaging error meant they weren't properly
included in the VS libs for that release. So I set the minimum to 2.0.6. Not sure if we want
to leave the fallbacks for the other versions or bump the minimum to 2.0.6.
  • Loading branch information
Vultraz committed Nov 21, 2017
1 parent 976f37c commit b51677d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/font/text.cpp
Expand Up @@ -719,8 +719,13 @@ void pango_text::rerender(const bool force)
}
}

#if SDL_VERSION_ATLEAST(2, 0, 6)
surface_.assign(SDL_CreateRGBSurfaceWithFormatFrom(
&surface_buffer_[0], width, height, 32, stride, SDL_PIXELFORMAT_ARGB8888));
#else
surface_.assign(SDL_CreateRGBSurfaceFrom(
&surface_buffer_[0], width, height, 32, stride, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000));
#endif
}
}

Expand Down
41 changes: 29 additions & 12 deletions src/sdl/utils.cpp
Expand Up @@ -48,21 +48,28 @@ bool is_neutral(const surface& surf)
}

static SDL_PixelFormat& get_neutral_pixel_format()
{
static bool first_time = true;
static SDL_PixelFormat format;

if(first_time) {
first_time = false;
surface surf(SDL_CreateRGBSurface(0,1,1,32,SDL_RED_MASK,SDL_GREEN_MASK,
SDL_BLUE_MASK,SDL_ALPHA_MASK));
format = *surf->format;
format.palette = nullptr;
}
{
static bool first_time = true;
static SDL_PixelFormat format;

if(first_time) {
first_time = false;

#if SDL_VERSION_ATLEAST(2, 0, 6)
surface surf(
SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888));
#else
surface surf(
SDL_CreateRGBSurface(0, 1, 1, 32, SDL_RED_MASK, SDL_GREEN_MASK, SDL_BLUE_MASK, SDL_ALPHA_MASK));
#endif

return format;
format = *surf->format;
format.palette = nullptr;
}

return format;
}

surface make_neutral_surface(const surface &surf)
{
if(surf == nullptr) {
Expand All @@ -83,12 +90,17 @@ surface create_neutral_surface(int w, int h)
}

SDL_PixelFormat format = get_neutral_pixel_format();

#if SDL_VERSION_ATLEAST(2, 0, 6)
surface result = SDL_CreateRGBSurfaceWithFormat(0, w, h, format.BitsPerPixel, format.format);
#else
surface result = SDL_CreateRGBSurface(0, w, h,
format.BitsPerPixel,
format.Rmask,
format.Gmask,
format.Bmask,
format.Amask);
#endif

return result;
}
Expand Down Expand Up @@ -2096,8 +2108,13 @@ surface create_compatible_surface(const surface &surf, int width, int height)
if(height == -1)
height = surf->h;

#if SDL_VERSION_ATLEAST(2, 0, 6)
surface s = SDL_CreateRGBSurfaceWithFormat(0, width, height, surf->format->BitsPerPixel, surf->format->format);
#else
surface s = SDL_CreateRGBSurface(0, width, height, surf->format->BitsPerPixel,
surf->format->Rmask, surf->format->Gmask, surf->format->Bmask, surf->format->Amask);
#endif

if (surf->format->palette) {
SDL_SetPaletteColors(s->format->palette, surf->format->palette->colors, 0, surf->format->palette->ncolors);
}
Expand Down
11 changes: 11 additions & 0 deletions src/video.cpp
Expand Up @@ -182,13 +182,24 @@ void CVideo::make_fake()
{
fake_screen_ = true;
refresh_rate_ = 1;

#if SDL_VERSION_ATLEAST(2, 0, 6)
frameBuffer = SDL_CreateRGBSurfaceWithFormat(0, 16, 16, 24, SDL_PIXELFORMAT_BGR888);
#else
frameBuffer = SDL_CreateRGBSurface(0, 16, 16, 24, 0xFF0000, 0xFF00, 0xFF, 0);
#endif

image::set_pixel_format(frameBuffer->format);
}

void CVideo::make_test_fake(const unsigned width, const unsigned height)
{
#if SDL_VERSION_ATLEAST(2, 0, 6)
frameBuffer = SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, SDL_PIXELFORMAT_BGR888);
#else
frameBuffer = SDL_CreateRGBSurface(0, width, height, 32, 0xFF0000, 0xFF00, 0xFF, 0);
#endif

image::set_pixel_format(frameBuffer->format);

fake_interactive = true;
Expand Down

1 comment on commit b51677d

@jyrkive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want to bump the minimum version as long as there are many GNU/Linux users with older SDL versions.

Please sign in to comment.