From 9661a675e50a18e0a098a5644e275e7806e910a9 Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 25 Apr 2010 09:52:01 +0000 Subject: Share SDL initialization code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31079 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/gl_common.c | 4 ++-- libvo/sdl_common.c | 24 ++++++++++++++++++++++++ libvo/sdl_common.h | 2 ++ libvo/vo_sdl.c | 20 ++------------------ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/libvo/gl_common.c b/libvo/gl_common.c index 3de2e5450c..c37172b382 100644 --- a/libvo/gl_common.c +++ b/libvo/gl_common.c @@ -1937,7 +1937,7 @@ int init_mpglcontext(MPGLContext *ctx, enum MPGLType type) { ctx->swapGlBuffers = swapGlBuffers_sdl; ctx->check_events = sdl_check_events; ctx->fullscreen = vo_sdl_fullscreen; - return 1; + return vo_sdl_init(); #endif default: return 0; @@ -1959,7 +1959,7 @@ void uninit_mpglcontext(MPGLContext *ctx) { #endif #ifdef CONFIG_GL_SDL case GLTYPE_SDL: - SDL_QuitSubSystem(SDL_INIT_VIDEO); + vo_sdl_uninit(); break; #endif } diff --git a/libvo/sdl_common.c b/libvo/sdl_common.c index d45382698b..6d1944db8c 100644 --- a/libvo/sdl_common.c +++ b/libvo/sdl_common.c @@ -30,6 +30,30 @@ static int old_w; static int old_h; static int mode_flags; +int vo_sdl_init(void) +{ + if (!SDL_WasInit(SDL_INIT_VIDEO) && + SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0) + return 0; + + // Setup Keyrepeats (500/30 are defaults) + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/); + + // We don't want those in our event queue. + SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); + SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); + SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE); + SDL_EventState(SDL_USEREVENT, SDL_IGNORE); + + return 1; +} + +void vo_sdl_uninit(void) +{ + if (SDL_WasInit(SDL_INIT_VIDEO)) + SDL_QuitSubSystem(SDL_INIT_VIDEO); +} + void vo_sdl_fullscreen(void) { if (vo_fs) { diff --git a/libvo/sdl_common.h b/libvo/sdl_common.h index a0fa956db9..be9e254b31 100644 --- a/libvo/sdl_common.h +++ b/libvo/sdl_common.h @@ -28,6 +28,8 @@ #include #endif +int vo_sdl_init(void); +void vo_sdl_uninit(void); void vo_sdl_fullscreen(void); int sdl_set_mode(int bpp, uint32_t flags); int sdl_default_handle_event(SDL_Event *event); diff --git a/libvo/vo_sdl.c b/libvo/vo_sdl.c index 913ff03533..dbf634934e 100644 --- a/libvo/vo_sdl.c +++ b/libvo/vo_sdl.c @@ -397,9 +397,6 @@ static int sdl_open (void *plugin, void *name) priv->sdlflags |= SDL_DOUBLEBUF; #endif - /* Setup Keyrepeats (500/30 are defaults) */ - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/); - /* get information about the graphics adapter */ vidInfo = SDL_GetVideoInfo (); @@ -444,16 +441,6 @@ static int sdl_open (void *plugin, void *name) priv->bpp = 16; } - /* We don't want those in our event queue. - * We use SDL_KEYUP cause SDL_KEYDOWN seems to cause problems - * with keys need to be pressed twice, to be recognized. - */ - SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); - SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); -// SDL_EventState(SDL_QUIT, SDL_IGNORE); - SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE); - SDL_EventState(SDL_USEREVENT, SDL_IGNORE); - /* Success! */ return 0; } @@ -1407,8 +1394,7 @@ uninit(void) sdl_close(); /* Cleanup SDL */ - if(SDL_WasInit(SDL_INIT_VIDEO)) - SDL_QuitSubSystem(SDL_INIT_VIDEO); + vo_sdl_uninit(); mp_msg(MSGT_VO,MSGL_DBG3, "SDL: Closed Plugin\n"); @@ -1458,12 +1444,10 @@ static int preinit(const char *arg) priv->bpp = 0; /* initialize the SDL Video system */ - if (!SDL_WasInit(SDL_INIT_VIDEO)) { - if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)) { + if (!vo_sdl_init()) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SDL_InitializationFailed, SDL_GetError()); return -1; - } } SDL_VideoDriverName(priv->driver, 8); -- cgit v1.2.3