From b51677d985f2f634cf0687f68855783f2950c55a Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 21 Nov 2017 17:16:49 +1100 Subject: [PATCH] Made use of SDL_CreateRGBSurfaceWithFormat* on SDL 2.0.6+ 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. --- src/font/text.cpp | 5 +++++ src/sdl/utils.cpp | 41 +++++++++++++++++++++++++++++------------ src/video.cpp | 11 +++++++++++ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/font/text.cpp b/src/font/text.cpp index 5beccf601701..b406672dde64 100644 --- a/src/font/text.cpp +++ b/src/font/text.cpp @@ -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 } } diff --git a/src/sdl/utils.cpp b/src/sdl/utils.cpp index 7d88e1f4e433..718985e7ff50 100644 --- a/src/sdl/utils.cpp +++ b/src/sdl/utils.cpp @@ -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) { @@ -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; } @@ -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); } diff --git a/src/video.cpp b/src/video.cpp index 39cd6d6cb054..6f4328aaa991 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -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;