[Scummvm-git-logs] scummvm master -> 5fd8aed04750a82b8eb717e2e27fc4826767dada

bluegr bluegr at gmail.com
Mon Mar 9 20:15:49 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
5fd8aed047 SDL: Move the compatibility functions into SurfaceSdlGraphicsManager


Commit: 5fd8aed04750a82b8eb717e2e27fc4826767dada
    https://github.com/scummvm/scummvm/commit/5fd8aed04750a82b8eb717e2e27fc4826767dada
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-03-09T22:15:45+02:00

Commit Message:
SDL: Move the compatibility functions into SurfaceSdlGraphicsManager

Changed paths:
    backends/graphics/surfacesdl/surfacesdl-graphics.cpp
    backends/graphics/surfacesdl/surfacesdl-graphics.h
    backends/platform/sdl/sdl-sys.h
    backends/platform/sdl/sdl.cpp


diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index e3d436445b..b0ccee4c47 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -49,6 +49,13 @@
 #include "common/text-to-speech.h"
 #endif
 
+// SDL surface flags which got removed in SDL2.
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#define SDL_SRCCOLORKEY 0
+#define SDL_SRCALPHA    0
+#define SDL_FULLSCREEN  0x40000000
+#endif
+
 static const OSystem::GraphicsMode s_supportedShaders[] = {
 	{"NONE", "Normal (no shader)", 0},
 	{0, 0, 0}
@@ -2766,6 +2773,37 @@ void SurfaceSdlGraphicsManager::SDL_UpdateRects(SDL_Surface *screen, int numrect
 	SDL_RenderCopy(_renderer, _screenTexture, NULL, &viewport);
 	SDL_RenderPresent(_renderer);
 }
+
+int SurfaceSdlGraphicsManager::SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
+	if (surface->format->palette) {
+		return !SDL_SetPaletteColors(surface->format->palette, colors, firstcolor, ncolors) ? 1 : 0;
+	} else {
+		return 0;
+	}
+}
+
+int SurfaceSdlGraphicsManager::SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha) {
+	if (SDL_SetSurfaceAlphaMod(surface, alpha)) {
+		return -1;
+	}
+
+	if (alpha == 255 || !flag) {
+		if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE)) {
+			return -1;
+		}
+	} else {
+		if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)) {
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+int SurfaceSdlGraphicsManager::SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) {
+	return ::SDL_SetColorKey(surface, SDL_TRUE, key) ? -1 : 0;
+}
+
 #endif // SDL_VERSION_ATLEAST(2, 0, 0)
 
 #endif
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 636619eb38..89dcf92c7c 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -200,6 +200,9 @@ protected:
 
 	virtual SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
 	virtual void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
+	int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
+	int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
+	int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
 #endif
 
 	/** Unseen game screen */
diff --git a/backends/platform/sdl/sdl-sys.h b/backends/platform/sdl/sdl-sys.h
index 6ccac5a7c6..0676905305 100644
--- a/backends/platform/sdl/sdl-sys.h
+++ b/backends/platform/sdl/sdl-sys.h
@@ -274,23 +274,4 @@
 
 #endif // FORBIDDEN_SYMBOL_EXCEPTION_time_h
 
-// SDL 2 has major API changes. We redefine constants which got renamed to
-// ease the transition. This is sometimes dangerous because the values changed
-// too!
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-// SDL surface flags which got removed.
-#define SDL_SRCCOLORKEY 0
-#define SDL_SRCALPHA    0
-#define SDL_FULLSCREEN  0x40000000
-
-// Compatibility implementations for removed functionality.
-int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors);
-int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
-
-#define SDL_SetColorKey SDL_SetColorKey_replacement
-int SDL_SetColorKey_replacement(SDL_Surface *surface, Uint32 flag, Uint32 key);
-
-#endif
-
-
 #endif
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 79b9ae5006..ba10c5d066 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -750,39 +750,6 @@ void OSystem_SDL::setupGraphicsModes() {
 }
 #endif
 
-#if SDL_VERSION_ATLEAST(2, 0, 0)
-int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors, int firstcolor, int ncolors) {
-	if (surface->format->palette) {
-		return !SDL_SetPaletteColors(surface->format->palette, colors, firstcolor, ncolors) ? 1 : 0;
-	} else {
-		return 0;
-	}
-}
-
-int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha) {
-	if (SDL_SetSurfaceAlphaMod(surface, alpha)) {
-		return -1;
-	}
-
-	if (alpha == 255 || !flag) {
-		if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE)) {
-			return -1;
-		}
-	} else {
-		if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)) {
-			return -1;
-		}
-	}
-
-	return 0;
-}
-
-#undef SDL_SetColorKey
-int SDL_SetColorKey_replacement(SDL_Surface *surface, Uint32 flag, Uint32 key) {
-	return SDL_SetColorKey(surface, SDL_TRUE, key) ? -1 : 0;
-}
-#endif
-
 char *OSystem_SDL::convertEncoding(const char *to, const char *from, const char *string, size_t length) {
 #if SDL_VERSION_ATLEAST(1, 2, 10)
 	int zeroBytes = 1;




More information about the Scummvm-git-logs mailing list