[MPlayer-cvslog] r38260 - in trunk/libvo: gl_common.c sdl_common.c sdl_common.h vo_gl.c
reimar
subversion at mplayerhq.hu
Fri Feb 26 15:40:11 EET 2021
Author: reimar
Date: Fri Feb 26 15:40:10 2021
New Revision: 38260
Log:
vo_gl: very preliminary support for libSDL2
This misses build system support and some features
are missing or not well implemented.
But is is working on a basic level, so preserve
it as a starting base for future work.
Modified:
trunk/libvo/gl_common.c
trunk/libvo/sdl_common.c
trunk/libvo/sdl_common.h
trunk/libvo/vo_gl.c
Modified: trunk/libvo/gl_common.c
==============================================================================
--- trunk/libvo/gl_common.c Thu Feb 25 19:03:17 2021 (r38259)
+++ trunk/libvo/gl_common.c Fri Feb 26 15:40:10 2021 (r38260)
@@ -2389,7 +2389,11 @@ static int x11_check_events(void) {
#include "sdl_common.h"
static void swapGlBuffers_sdl(MPGLContext *ctx) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_GL_SwapWindow(sdl_window);
+#else
SDL_GL_SwapBuffers();
+#endif
}
static void *sdlgpa(const GLubyte *name) {
@@ -2406,6 +2410,16 @@ static int setGlWindow_sdl(MPGLContext *
return SET_WINDOW_OK;
}
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+SDL_GLContext sdl_gl_context;
+#endif
+
+static void releaseGlContext_sdl() {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_GL_DeleteContext(sdl_gl_context);
+#endif
+}
+
static int sdl_check_events(void) {
int res = 0;
SDL_Event event;
@@ -2414,8 +2428,10 @@ static int sdl_check_events(void) {
}
// poll "events" from within MPlayer code
res |= sdl_default_handle_event(NULL);
+#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (res & VO_EVENT_RESIZE)
sdl_set_mode(0, SDL_OPENGL | SDL_RESIZABLE);
+#endif
return res;
}
@@ -2711,6 +2727,7 @@ int init_mpglcontext(MPGLContext *ctx, e
case GLTYPE_SDL:
SDL_Init(SDL_INIT_VIDEO);
ctx->setGlWindow = setGlWindow_sdl;
+ ctx->releaseGlContext = releaseGlContext_sdl;
ctx->swapGlBuffers = swapGlBuffers_sdl;
ctx->check_events = sdl_check_events;
ctx->fullscreen = vo_sdl_fullscreen;
@@ -2813,6 +2830,9 @@ int mpglcontext_create_window(MPGLContex
#ifdef CONFIG_GL_SDL
if (ctx->type == GLTYPE_SDL && !vo_sdl_config(d_width, d_height, flags, title))
return -1;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ sdl_gl_context = SDL_GL_CreateContext(sdl_window);
+#endif
#endif
return 0;
}
Modified: trunk/libvo/sdl_common.c
==============================================================================
--- trunk/libvo/sdl_common.c Thu Feb 25 19:03:17 2021 (r38259)
+++ trunk/libvo/sdl_common.c Fri Feb 26 15:40:10 2021 (r38260)
@@ -32,6 +32,7 @@ static int old_w;
static int old_h;
static int mode_flags;
static int reinit;
+SDL_Window *sdl_window;
/**
* Update vo_screenwidth and vo_screenheight.
@@ -43,11 +44,16 @@ static int reinit;
* update_xinerama_info function.
*/
static void get_screensize(void) {
- const SDL_VideoInfo *vi;
- // TODO: better to use a check that gets the runtime version instead?
-#if SDL_VERSION_ATLEAST(1, 2, 10)
// Keep user-provided settings
if (vo_screenwidth > 0 || vo_screenheight > 0) return;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_DisplayMode m;
+ if (SDL_GetCurrentDisplayMode(0, &m)) return;
+ vo_screenwidth = m.w;
+ vo_screenheight = m.h;
+ // TODO: better to use a check that gets the runtime version instead?
+#elif SDL_VERSION_ATLEAST(1, 2, 10)
+ const SDL_VideoInfo *vi;
vi = SDL_GetVideoInfo();
vo_screenwidth = vi->current_w;
vo_screenheight = vi->current_h;
@@ -69,8 +75,10 @@ int vo_sdl_init(void)
}
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0)
return 0;
+ sdl_window = NULL;
}
+#if !SDL_VERSION_ATLEAST(2, 0, 0)
// Setup Keyrepeats (500/30 are defaults)
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);
@@ -79,6 +87,7 @@ int vo_sdl_init(void)
// We don't want those in our event queue.
SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
+#endif
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
@@ -92,11 +101,14 @@ void vo_sdl_uninit(void)
{
if (SDL_WasInit(SDL_INIT_VIDEO))
SDL_QuitSubSystem(SDL_INIT_VIDEO);
+ sdl_window = NULL;
}
int vo_sdl_config(int w, int h, int flags, const char *title)
{
+#if !SDL_VERSION_ATLEAST(2, 0, 0)
SDL_WM_SetCaption(title, NULL);
+#endif
vo_dwidth = old_w = w;
vo_dheight = old_h = h;
vo_fs = !!(flags & VOFLAG_FULLSCREEN);
@@ -104,6 +116,17 @@ int vo_sdl_config(int w, int h, int flag
vo_dwidth = vo_screenwidth;
vo_dheight = vo_screenheight;
}
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (!sdl_window) {
+ unsigned sdlflags = SDL_OPENGL;
+ if (vo_fs) flags |= SDL_FULLSCREEN;
+ if (!vo_border) flags |= SDL_NOFRAME;
+ sdl_window = SDL_CreateWindow(title,
+ geometry_xy_changed ? vo_dx : SDL_WINDOWPOS_UNDEFINED,
+ geometry_xy_changed ? vo_dy : SDL_WINDOWPOS_UNDEFINED,
+ vo_dwidth, vo_dheight, sdlflags);
+ }
+#endif
SDL_GL_SetAttribute(SDL_GL_STEREO, !!(flags & VOFLAG_STEREO));
return 1;
}
@@ -120,16 +143,33 @@ void vo_sdl_fullscreen(void)
vo_dheight = vo_screenheight;
}
vo_fs = !vo_fs;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ SDL_SetWindowFullscreen(sdl_window, vo_fs ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+#else
sdl_set_mode(0, mode_flags);
+#endif
// on OSX at least we now need to do a full reinit.
// TODO: this should only be set if really necessary.
reinit = 1;
}
-SDL_Surface *sdl_set_mode(int bpp, uint32_t flags)
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+int
+#else
+SDL_Surface *
+#endif
+sdl_set_mode(int bpp, uint32_t flags)
{
SDL_Surface *s;
mode_flags = flags;
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (!sdl_window) return 0;
+ SDL_SetWindowSize(sdl_window, vo_dwidth, vo_dheight);
+ if (geometry_xy_changed) SDL_SetWindowPosition(sdl_window, vo_dx, vo_dy);
+ if (flags & SDL_OPENGL) SDL_GL_GetDrawableSize(sdl_window, &vo_dwidth, &vo_dheight);
+ else SDL_GetWindowSize(sdl_window, &vo_dwidth, &vo_dheight);
+ return 1;
+#else
if (vo_fs) flags |= SDL_FULLSCREEN;
// doublebuf with opengl creates flickering
#if !defined( __AMIGAOS4__ ) && !defined( __APPLE__ )
@@ -151,6 +191,7 @@ SDL_Surface *sdl_set_mode(int bpp, uint3
vo_dwidth = s->w;
vo_dheight = s->h;
return s;
+#endif
}
static const struct mp_keymap keysym_map[] = {
@@ -164,10 +205,17 @@ static const struct mp_keymap keysym_map
{SDLK_UP, KEY_UP}, {SDLK_DOWN, KEY_DOWN},
{SDLK_LEFT, KEY_LEFT}, {SDLK_RIGHT, KEY_RIGHT},
{SDLK_KP_MULTIPLY, '*'}, {SDLK_KP_DIVIDE, '/'},
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ {SDLK_KP_0, KEY_KP0}, {SDLK_KP_1, KEY_KP1}, {SDLK_KP_2, KEY_KP2},
+ {SDLK_KP_3, KEY_KP3}, {SDLK_KP_4, KEY_KP4}, {SDLK_KP_5, KEY_KP5},
+ {SDLK_KP_6, KEY_KP6}, {SDLK_KP_7, KEY_KP7}, {SDLK_KP_8, KEY_KP8},
+ {SDLK_KP_9, KEY_KP9},
+#else
{SDLK_KP0, KEY_KP0}, {SDLK_KP1, KEY_KP1}, {SDLK_KP2, KEY_KP2},
{SDLK_KP3, KEY_KP3}, {SDLK_KP4, KEY_KP4}, {SDLK_KP5, KEY_KP5},
{SDLK_KP6, KEY_KP6}, {SDLK_KP7, KEY_KP7}, {SDLK_KP8, KEY_KP8},
{SDLK_KP9, KEY_KP9},
+#endif
{SDLK_KP_PERIOD, KEY_KPDEC}, {SDLK_KP_ENTER, KEY_KPENTER},
{0, 0}
};
@@ -181,6 +229,19 @@ int sdl_default_handle_event(SDL_Event *
return res;
}
switch (event->type) {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ case SDL_WINDOWEVENT:
+ switch (event->window.event)
+ {
+ case SDL_WINDOWEVENT_SIZE_CHANGED:
+ vo_dwidth = event->window.data1;
+ vo_dheight = event->window.data2;
+ return VO_EVENT_RESIZE;
+ case SDL_WINDOWEVENT_EXPOSED:
+ return VO_EVENT_EXPOSE;
+ }
+ break;
+#else
case SDL_VIDEORESIZE:
vo_dwidth = event->resize.w;
vo_dheight = event->resize.h;
@@ -188,6 +249,7 @@ int sdl_default_handle_event(SDL_Event *
case SDL_VIDEOEXPOSE:
return VO_EVENT_EXPOSE;
+#endif
case SDL_MOUSEMOTION:
vo_mouse_movement(event->motion.x, event->motion.y);
@@ -205,10 +267,15 @@ int sdl_default_handle_event(SDL_Event *
case SDL_KEYDOWN:
mpkey = lookup_keymap_table(keysym_map, event->key.keysym.sym);
- if (!mpkey &&
- event->key.keysym.unicode > 0 &&
- event->key.keysym.unicode < 128)
- mpkey = event->key.keysym.unicode;
+ {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ unsigned code = event->key.keysym.sym;
+#else
+ unsigned code = event->key.keysym.unicode;
+#endif
+ if (!mpkey && code > 0 && code < 128)
+ mpkey = code;
+ }
if (mpkey)
mplayer_put_key(mpkey);
break;
Modified: trunk/libvo/sdl_common.h
==============================================================================
--- trunk/libvo/sdl_common.h Thu Feb 25 19:03:17 2021 (r38259)
+++ trunk/libvo/sdl_common.h Fri Feb 26 15:40:10 2021 (r38260)
@@ -29,11 +29,27 @@
#include <SDL.h>
#endif
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN_DESKTOP
+#define SDL_OPENGL SDL_WINDOW_OPENGL
+#define SDL_NOFRAME SDL_WINDOW_BORDERLESS
+#define SDL_RESIZABLE SDL_WINDOW_RESIZABLE
+#else
+#define SDL_Window void
+#endif
+
+extern SDL_Window *sdl_window;
+
int vo_sdl_init(void);
void vo_sdl_uninit(void);
int vo_sdl_config(int w, int h, int flags, const char *title);
void vo_sdl_fullscreen(void);
-SDL_Surface *sdl_set_mode(int bpp, uint32_t flags);
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+int
+#else
+SDL_Surface *
+#endif
+sdl_set_mode(int bpp, uint32_t flags);
int sdl_default_handle_event(SDL_Event *event);
#endif /* MPLAYER_SDL_COMMON_H */
Modified: trunk/libvo/vo_gl.c
==============================================================================
--- trunk/libvo/vo_gl.c Thu Feb 25 19:03:17 2021 (r38259)
+++ trunk/libvo/vo_gl.c Fri Feb 26 15:40:10 2021 (r38260)
@@ -671,6 +671,7 @@ static int create_window(uint32_t d_widt
if (stereo_mode == GL_3D_QUADBUFFER)
flags |= VOFLAG_STEREO;
#ifdef CONFIG_GL_SDL
+#if !SDL_VERSION_ATLEAST(2, 0, 0)
if (glctx.type == GLTYPE_SDL) {
// Ugly to do this here, but SDL ignores it if set later
if (swap_interval >= 0) {
@@ -682,6 +683,7 @@ static int create_window(uint32_t d_widt
}
}
#endif
+#endif
return mpglcontext_create_window(&glctx, d_width, d_height, flags, title);
}
More information about the MPlayer-cvslog
mailing list