aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl
diff options
context:
space:
mode:
authorJohannes Schickel2015-01-25 01:34:57 +0100
committerJohannes Schickel2015-01-25 20:23:25 +0100
commit8530997fff7b5b9d558f7dd6a0d07c236e4de16f (patch)
tree3ded3cc11bae7b50138f35be7626cdae9c400af2 /backends/platform/sdl
parentdefe71792dfc0ab4bcb14a64a9fc8eab9a638e69 (diff)
downloadscummvm-rg350-8530997fff7b5b9d558f7dd6a0d07c236e4de16f.tar.gz
scummvm-rg350-8530997fff7b5b9d558f7dd6a0d07c236e4de16f.tar.bz2
scummvm-rg350-8530997fff7b5b9d558f7dd6a0d07c236e4de16f.zip
SDL: Add experimental support for SDL2.
This is based upon skristiansson's change set to make ScummVM work with SDL2.
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r--backends/platform/sdl/sdl-sys.h45
-rw-r--r--backends/platform/sdl/sdl.cpp47
2 files changed, 92 insertions, 0 deletions
diff --git a/backends/platform/sdl/sdl-sys.h b/backends/platform/sdl/sdl-sys.h
index eec3741ed6..1ae43dbd8b 100644
--- a/backends/platform/sdl/sdl-sys.h
+++ b/backends/platform/sdl/sdl-sys.h
@@ -74,5 +74,50 @@ typedef struct { int FAKE; } FAKE_FILE;
#define strncasecmp FORBIDDEN_SYMBOL_REPLACEMENT
#endif
+// 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)
+
+// Type names which changed between SDL 1.2 and SDL 2.
+#define SDLKey SDL_Keycode
+#define SDLMod SDL_Keymod
+#define SDL_keysym SDL_Keysym
+
+// Key code constants which got renamed.
+#define SDLK_SCROLLOCK SDLK_SCROLLLOCK
+#define SDLK_NUMLOCK SDLK_NUMLOCKCLEAR
+#define SDLK_LSUPER SDLK_LGUI
+#define SDLK_RSUPER SDLK_RGUI
+#define SDLK_PRINT SDLK_PRINTSCREEN
+#define SDLK_COMPOSE SDLK_APPLICATION
+#define SDLK_KP0 SDLK_KP_0
+#define SDLK_KP1 SDLK_KP_1
+#define SDLK_KP2 SDLK_KP_2
+#define SDLK_KP3 SDLK_KP_3
+#define SDLK_KP4 SDLK_KP_4
+#define SDLK_KP5 SDLK_KP_5
+#define SDLK_KP6 SDLK_KP_6
+#define SDLK_KP7 SDLK_KP_7
+#define SDLK_KP8 SDLK_KP_8
+#define SDLK_KP9 SDLK_KP_9
+
+// Meta key constants which got renamed.
+#define KMOD_META KMOD_GUI
+
+// SDL surface flags which got removed.
+#define SDL_SRCCOLORKEY 0
+#define SDL_SRCALPHA 0
+#define SDL_FULLSCREEN 0x40000000
+
+// Compatability 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 d3a6e5e658..434a4ce18a 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -126,8 +126,10 @@ void OSystem_SDL::init() {
// Initialize SDL
initSDL();
+#if !SDL_VERSION_ATLEAST(2, 0, 0)
// Enable unicode support if possible
SDL_EnableUNICODE(1);
+#endif
// Disable OS cursor
SDL_ShowCursor(SDL_DISABLE);
@@ -158,10 +160,14 @@ void OSystem_SDL::initBackend() {
// Check if backend has not been initialized
assert(!_inited);
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ const char *sdlDriverName = SDL_GetCurrentVideoDriver();
+#else
const int maxNameLen = 20;
char sdlDriverName[maxNameLen];
sdlDriverName[0] = '\0';
SDL_VideoDriverName(sdlDriverName, maxNameLen);
+#endif
// Using printf rather than debug() here as debug()/logging
// is not active by this point.
debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);
@@ -172,6 +178,13 @@ void OSystem_SDL::initBackend() {
_eventSource = new SdlEventSource();
#ifdef USE_OPENGL
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_DisplayMode displayMode;
+ if (!SDL_GetDesktopDisplayMode(0, &displayMode)) {
+ _desktopWidth = displayMode.w;
+ _desktopHeight = displayMode.h;
+ }
+#else
// Query the desktop resolution. We simply hope nothing tried to change
// the resolution so far.
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
@@ -180,6 +193,7 @@ void OSystem_SDL::initBackend() {
_desktopHeight = videoInfo->current_h;
}
#endif
+#endif
if (_graphicsManager == 0) {
#ifdef USE_OPENGL
@@ -681,5 +695,38 @@ void OSystem_SDL::setupGraphicsModes() {
mode++;
}
}
+#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
+