Purge SDL_MODERN.

SDL 2.0 differs far more than 1.3 did, and it makes no sense
to support both now.
This commit is contained in:
Themaister 2012-09-12 23:37:25 +02:00
parent 2e538e0eb5
commit a4262fd0d6
4 changed files with 5 additions and 185 deletions

View File

@ -25,7 +25,8 @@
#include <OpenGL/gl.h>
#endif
#include "sdl_ctx.h"
#include "SDL.h"
#include "../math/matrix.h"
// SDL 1.2 is portable, sure, but you still need some platform specific workarounds ;)
@ -33,11 +34,6 @@
// Welcome to #ifdef HELL. :D
//
#if SDL_MODERN
static SDL_Window *g_window;
static SDL_GLContext g_ctx;
#endif
#define GL_SYM_WRAP(symbol, proc) if (!symbol) { \
gfx_ctx_proc_t sym = gfx_ctx_get_proc_address(proc); \
memcpy(&(symbol), &sym, sizeof(sym)); \
@ -51,10 +47,6 @@ void gfx_ctx_set_swap_interval(unsigned interval, bool inited)
g_interval = interval;
bool success = true;
#if SDL_MODERN
if (g_window)
success = SDL_GL_SetSwapInterval(g_interval) == 0;
#else
if (inited)
{
#if defined(_WIN32)
@ -79,7 +71,6 @@ void gfx_ctx_set_swap_interval(unsigned interval, bool inited)
RARCH_WARN("Could not find GLX VSync call.\n");
#endif
}
#endif
if (!success)
RARCH_WARN("Failed to set swap interval.\n");
@ -87,11 +78,7 @@ void gfx_ctx_set_swap_interval(unsigned interval, bool inited)
static void gfx_ctx_wm_set_caption(const char *str)
{
#if SDL_MODERN
SDL_SetWindowTitle(g_window, str);
#else
SDL_WM_SetCaption(str, NULL);
#endif
}
void gfx_ctx_update_window_title(bool reset)
@ -114,101 +101,48 @@ void gfx_ctx_get_video_size(unsigned *width, unsigned *height)
bool gfx_ctx_init(void)
{
#if SDL_MODERN
bool ret = SDL_VideoInit(NULL) == 0;
#else
if (SDL_WasInit(SDL_INIT_VIDEO))
return true;
bool ret = SDL_Init(SDL_INIT_VIDEO) == 0;
#endif
if (!ret)
RARCH_ERR("Failed to init SDL video.\n");
return ret;
}
#if SDL_MODERN
void gfx_ctx_destroy(void)
{
if (g_ctx)
SDL_GL_DeleteContext(g_ctx);
if (g_window)
SDL_DestroyWindow(g_window);
g_ctx = NULL;
g_window = NULL;
SDL_VideoQuit();
}
#else
void gfx_ctx_destroy(void)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
#endif
bool gfx_ctx_set_video_mode(
unsigned width, unsigned height,
unsigned bits, bool fullscreen)
{
#if SDL_MODERN
if (g_window)
return true;
#endif
#if SDL_MODERN
static const int resizable = SDL_WINDOW_RESIZABLE;
#else
#ifndef __APPLE__ // Resizing on OSX is broken in 1.2 it seems :)
static const int resizable = SDL_RESIZABLE;
#else
static const int resizable = 0;
#endif
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#if !SDL_MODERN
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, g_interval);
#endif
#if SDL_MODERN
if (bits == 15)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
}
g_window = SDL_CreateWindow("RetroArch", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | (fullscreen ? SDL_WINDOW_FULLSCREEN : resizable));
if (!g_window)
{
RARCH_ERR("Failed to create SDL window.\n");
return false;
}
g_ctx = SDL_GL_CreateContext(g_window);
#else
if (!SDL_SetVideoMode(width, height, bits,
SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : resizable)))
{
RARCH_ERR("Failed to create SDL window.\n");
return false;
}
#endif
int attr = 0;
#if SDL_MODERN
SDL_GL_SetSwapInterval(g_interval);
#else
SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &attr);
if (attr <= 0 && g_interval)
{
RARCH_WARN("SDL failed to setup VSync, attempting to recover using native calls.\n");
gfx_ctx_set_swap_interval(g_interval, true);
}
#endif
g_fullscreen = fullscreen;
@ -238,50 +172,32 @@ bool gfx_ctx_set_video_mode(
// SDL 1.3 luckily removes this quirk.
void gfx_ctx_set_resize(unsigned width, unsigned height)
{
#if SDL_MODERN
(void)width;
(void)height;
#else
#ifndef __APPLE__ // Resizing on OSX is broken in 1.2 it seems :)
static const int resizable = SDL_RESIZABLE;
#else
static const int resizable = 0;
#endif
SDL_SetVideoMode(width, height, 0, SDL_OPENGL | (g_fullscreen ? SDL_FULLSCREEN : resizable));
#endif
}
void gfx_ctx_swap_buffers(void)
{
#if SDL_MODERN
SDL_GL_SwapWindow(g_window);
#else
SDL_GL_SwapBuffers();
#endif
}
bool gfx_ctx_key_pressed(int key)
{
int num_keys;
#if SDL_MODERN
Uint8 *keymap = SDL_GetKeyboardState(&num_keys);
key = SDL_GetScancodeFromKey(key);
if (key >= num_keys)
return false;
return keymap[key];
#else
Uint8 *keymap = SDL_GetKeyState(&num_keys);
if (key >= num_keys)
return false;
return keymap[key];
#endif
}
// 1.2 specific workaround for tiling WMs. In 1.3 we call GetSize directly, so we don't need to rely on
// proper event handling (I hope).
#if !SDL_MODERN && !defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_X11)
#if !defined(__APPLE__) && defined(SDL_VIDEO_DRIVER_X11)
// This X11 is set on OSX for some reason.
static bool gfx_ctx_get_window_size(unsigned *width, unsigned *height)
{
@ -304,50 +220,7 @@ static bool gfx_ctx_get_window_size(unsigned *width, unsigned *height)
}
#endif
#if SDL_MODERN
static void check_window_modern(bool *quit,
bool *resize, unsigned *width, unsigned *height)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
*quit = true;
return;
case SDL_WINDOWEVENT:
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
*quit = true;
return;
case SDL_WINDOWEVENT_RESIZED:
*resize = true;
*width = event.window.data1;
*height = event.window.data2;
break;
}
break;
}
}
if (!*resize)
{
int w, h;
SDL_GetWindowSize(g_window, &w, &h);
if (*width != (unsigned)w || *height != (unsigned)h)
{
*resize = true;
*width = w;
*height = h;
}
}
}
#else
static void check_window_legacy(bool *quit,
static void check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
SDL_Event event;
@ -388,8 +261,6 @@ static void check_window_legacy(bool *quit,
}
#endif
}
#endif
void gfx_ctx_check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
@ -397,11 +268,7 @@ void gfx_ctx_check_window(bool *quit,
*quit = false;
*resize = false;
#if SDL_MODERN
check_window_modern(quit, resize, width, height);
#else
check_window_legacy(quit, resize, width, height, frame_count);
#endif
check_window(quit, resize, width, height, frame_count);
}
#ifndef __APPLE__
@ -410,12 +277,6 @@ bool gfx_ctx_get_wm_info(SDL_SysWMinfo *info)
#ifdef XENON
(void)info;
return false;
#elif SDL_MODERN
SDL_VERSION(&info->version);
if (g_window)
return SDL_GetWindowWMInfo(g_window, info);
else
return SDL_GetWMInfo(info) == 1;
#else
SDL_VERSION(&info->version);
return SDL_GetWMInfo(info) == 1;
@ -425,13 +286,7 @@ bool gfx_ctx_get_wm_info(SDL_SysWMinfo *info)
bool gfx_ctx_window_has_focus(void)
{
#if SDL_MODERN
Uint32 flags = SDL_GetWindowFlags(g_window);
flags &= SDL_WINDOW_INPUT_FOCUS;
return flags == SDL_WINDOW_INPUT_FOCUS;
#else
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
#endif
}
void gfx_ctx_input_driver(const input_driver_t **input, void **input_data)

View File

@ -1,29 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SDL_CTX_H
#define _SDL_CTX_H
#include "SDL.h"
#include "SDL_version.h"
#if SDL_VERSION_ATLEAST(1, 3, 0)
#define SDL_MODERN 1
#else
#define SDL_MODERN 0
#endif
#endif

View File

@ -33,8 +33,6 @@
#include "../compat/strl.h"
#ifdef HAVE_SDL
#define NO_SDL_GLEXT
#include "context/sdl_ctx.h"
#include "../input/rarch_sdl_input.h"
#endif

View File

@ -112,11 +112,7 @@ sdl_dinput_t* sdl_dinput_init(void)
goto error;
}
#if SDL_MODERN
di->hWnd = info.info.win.window;
#else
di->hWnd = info.window;
#endif
#ifdef __cplusplus
if (FAILED(DirectInput8Create(