Ticket #2213: beastd-mplayer-vo-gl-sdl2-hack.diff

File beastd-mplayer-vo-gl-sdl2-hack.diff, 10.8 KB (added by beastd, 11 years ago)

SDL2 patch for use with vo gl

  • Makefile

    diff --git a/Makefile b/Makefile
    index 027c0bc..ff3ee34 100644
    a b SRCS_MPLAYER-$(PULSE) += libao2/ao_pulse.c  
    545545SRCS_MPLAYER-$(QUARTZ)        += libvo/vo_quartz.c libvo/osx_common.c
    546546SRCS_MPLAYER-$(S3FB)          += libvo/vo_s3fb.c
    547547SRCS_MPLAYER-$(SDL)           += libao2/ao_sdl.c                        \
    548                                  libvo/vo_sdl.c                         \
    549548                                 libvo/sdl_common.c
    550549SRCS_MPLAYER-$(SGIAUDIO)      += libao2/ao_sgi.c
    551550SRCS_MPLAYER-$(SNDIO)         += libao2/ao_sndio.c
  • configure

    diff --git a/configure b/configure
    index b6b7d7c..5d1ebcc 100755
    a b ld_tmp=""  
    53745374def_sdl_sdl_h="#undef CONFIG_SDL_SDL_H"
    53755375if test -z "$_sdlconfig" ; then
    53765376  if ( sdl-config --version ) >>"$TMPLOG" 2>&1 ; then
    5377     _sdlconfig="sdl-config"
     5377    _sdlconfig="pkg-config sdl2"
    53785378  else
    53795379    _sdlconfig=false
    53805380  fi
    if test "$_sdl" = auto || test "$_sdl" = yes ; then  
    53915391#undef main
    53925392#endif
    53935393int main(int argc, char *argv[]) {
    5394   SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE);
    5395   return 0;
     5394  SDL_Init(SDL_INIT_VIDEO);
     5395  return SDLK_KP_0; // will only be defined in SDL2
    53965396}
    53975397EOF
    53985398  _sdl=no
    EOF  
    54035403      break
    54045404    fi
    54055405  done
    5406   if test "$_sdl" = no && "$_sdlconfig" --version >>"$TMPLOG" 2>&1 ; then
     5406  if test "$_sdl" = no && $_sdlconfig --version >>"$TMPLOG" 2>&1 ; then
    54075407    res_comment="using $_sdlconfig"
    54085408    if cygwin ; then
    54095409      inc_tmp="$($_sdlconfig --cflags | cut -d " " -f 1,5,6 | sed s/no-cygwin/cygwin/)"
    int main(int argc, char *argv[]) {  
    54835483  HDC dc;
    54845484  wglCreateContext(dc);
    54855485#elif defined(GL_SDL)
    5486   SDL_GL_SwapBuffers();
     5486  SDL_GL_SwapWindow(NULL);
    54875487#elif defined(GL_EGL_X11) || defined(GL_EGL_ANDROID)
    54885488  EGLDisplay eglDisplay = EGL_NO_DISPLAY;
    54895489  eglInitialize(eglDisplay, NULL, NULL);
  • libvo/gl_common.c

    diff --git a/libvo/gl_common.c b/libvo/gl_common.c
    index ecf12cb..7c3f8b6 100644
    a b static int x11_check_events(void) {  
    23842384#ifdef CONFIG_GL_SDL
    23852385#include "sdl_common.h"
    23862386
     2387extern SDL_Window *sdl_wnd;
    23872388static void swapGlBuffers_sdl(MPGLContext *ctx) {
    2388   SDL_GL_SwapBuffers();
     2389  SDL_GL_SwapWindow(sdl_wnd);
    23892390}
    23902391
    23912392static void *sdlgpa(const GLubyte *name) {
    23922393  return SDL_GL_GetProcAddress(name);
    23932394}
    23942395
     2396extern SDL_GLContext *sdl_glctx;
    23952397static int setGlWindow_sdl(MPGLContext *ctx) {
    2396   if (!sdl_set_mode(0, SDL_OPENGL | SDL_RESIZABLE))
     2398  if (!sdl_set_mode(0, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE))
    23972399    return SET_WINDOW_FAILED;
    2398   SDL_GL_LoadLibrary(NULL);
     2400  if (!SDL_GL_CreateContext(sdl_wnd)) {
     2401    return SET_WINDOW_FAILED;
     2402  }
    23992403  getFunctions(sdlgpa, NULL);
    24002404  gpu_def_sl_program = 0;
    24012405  gpu_yuv_sl_program = 0;
    static int sdl_check_events(void) {  
    24082412  while (SDL_PollEvent(&event)) {
    24092413    res |= sdl_default_handle_event(&event);
    24102414  }
    2411   // poll "events" from within MPlayer code
    2412   res |= sdl_default_handle_event(NULL);
    24132415  if (res & VO_EVENT_RESIZE)
    2414     sdl_set_mode(0, SDL_OPENGL | SDL_RESIZABLE);
     2416    sdl_set_mode(0, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
    24152417  return res;
    24162418}
    24172419
    static void dummy_update_xinerama_info(void) {  
    26552657  aspect_save_screenres(vo_screenwidth, vo_screenheight);
    26562658}
    26572659
     2660//XXX: There seems to a bug if this function returns -1
    26582661int init_mpglcontext(MPGLContext *ctx, enum MPGLType type) {
    26592662  if (type == GLTYPE_AUTO) {
    26602663    int res = init_mpglcontext(ctx, GLTYPE_W32);
  • libvo/sdl_common.c

    diff --git a/libvo/sdl_common.c b/libvo/sdl_common.c
    index 5cf3a0a..b708d8a 100644
    a b  
    3131static int old_w;
    3232static int old_h;
    3333static int mode_flags;
    34 static int reinit;
     34SDL_Window  *sdl_wnd; //XXX: should rather be private
    3535
    3636/**
    3737 * Update vo_screenwidth and vo_screenheight.
    static int reinit;  
    4343 * update_xinerama_info function.
    4444 */
    4545static void get_screensize(void) {
    46     const SDL_VideoInfo *vi;
    47     // TODO: better to use a check that gets the runtime version instead?
    48 #if SDL_VERSION_ATLEAST(1, 2, 10)
    49     // Keep user-provided settings
     46    SDL_DisplayMode mode;
     47    int num_displays;
     48
    5049    if (vo_screenwidth > 0 || vo_screenheight > 0) return;
    51     vi = SDL_GetVideoInfo();
    52     vo_screenwidth  = vi->current_w;
    53     vo_screenheight = vi->current_h;
    54 #endif
     50
     51    num_displays = SDL_GetNumVideoDisplays();
     52    mp_msg(MSGT_VO, MSGL_INFO, "[sdl] Number of displays: %d\n", num_displays);
     53    if (num_displays <= 0) return;
     54
     55    if (SDL_GetDesktopDisplayMode(0, &mode) < 0) {
     56      mp_msg(MSGT_VO, MSGL_ERR, "[sdl] Could not get display mode: %s\n", SDL_GetError());
     57    }
     58    mp_msg(MSGT_VO, MSGL_INFO, "[sdl] Size of display #0: %dx%d\n", mode.w, mode.h);
     59    vo_screenwidth  = mode.w;
     60    vo_screenheight = mode.h;
    5561}
    5662
    5763int vo_sdl_init(void)
    5864{
    59     reinit = 0;
    60 
    6165    if (!SDL_WasInit(SDL_INIT_VIDEO)) {
    62         // Unfortunately SDL_WINDOWID must be set at SDL_Init
    63         // and is ignored afterwards, thus it cannot work per-file.
    64         // Also, a value of 0 does not work for selecting the root window.
    65         if (WinID > 0) {
    66             char envstr[20];
    67             snprintf(envstr, sizeof(envstr), "0x%"PRIx64, WinID);
    68             setenv("SDL_WINDOWID", envstr, 1);
    69         }
    7066        if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0)
    7167            return 0;
    7268    }
    7369
    74     // Setup Keyrepeats (500/30 are defaults)
    75     SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, 100 /*SDL_DEFAULT_REPEAT_INTERVAL*/);
    76 
    77     // Easiest way to get uppercase characters
    78     SDL_EnableUNICODE(1);
    79 
    8070    // We don't want those in our event queue.
    81     SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE);
    8271    SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
    8372    SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
    8473
    void vo_sdl_uninit(void)  
    9685
    9786int vo_sdl_config(int w, int h, int flags, const char *title)
    9887{
    99     SDL_WM_SetCaption(title, NULL);
     88    SDL_SetWindowTitle(sdl_wnd, title);
    10089    vo_dwidth  = old_w = w;
    10190    vo_dheight = old_h = h;
    10291    vo_fs = !!(flags & VOFLAG_FULLSCREEN);
    int vo_sdl_config(int w, int h, int flags, const char *title)  
    11099
    111100void vo_sdl_fullscreen(void)
    112101{
     102    SDL_SetWindowFullscreen(sdl_wnd, vo_fs ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
     103    SDL_ShowCursor(vo_fs ? SDL_ENABLE : SDL_DISABLE);
    113104    if (vo_fs) {
    114105        vo_dwidth  = old_w;
    115106        vo_dheight = old_h;
    116107    } else {
     108        SDL_DisplayMode mode;
     109        SDL_GetWindowDisplayMode(sdl_wnd, &mode);
     110        vo_screenwidth  = mode.w;
     111        vo_screenheight = mode.h;
    117112        old_w = vo_dwidth;
    118113        old_h = vo_dheight;
    119114        vo_dwidth  = vo_screenwidth;
    120115        vo_dheight = vo_screenheight;
    121116    }
    122117    vo_fs = !vo_fs;
    123     sdl_set_mode(0, mode_flags);
    124     // on OSX at least we now need to do a full reinit.
    125     // TODO: this should only be set if really necessary.
    126     reinit = 1;
    127118}
    128119
    129120SDL_Surface *sdl_set_mode(int bpp, uint32_t flags)
    130121{
    131     SDL_Surface *s;
    132122    mode_flags = flags;
    133     if (vo_fs) flags |= SDL_FULLSCREEN;
    134     // doublebuf with opengl creates flickering
    135 #if !defined( __AMIGAOS4__ ) && !defined( __APPLE__ )
    136     if (vo_doublebuffering && !(flags & SDL_OPENGL))
    137         flags |= SDL_DOUBLEBUF;
    138 #endif
    139123    if (!vo_border)
    140         flags |= SDL_NOFRAME;
     124        flags |= SDL_WINDOW_BORDERLESS;
    141125    if (geometry_xy_changed) {
    142126        char envstr[20];
    143127        snprintf(envstr, sizeof(envstr), "%i,%i", vo_dx, vo_dy);
    144128        setenv("SDL_VIDEO_WINDOW_POS", envstr, 1);
    145129    }
    146     s = SDL_SetVideoMode(vo_dwidth, vo_dheight, bpp, flags);
    147     if (!s) {
     130    if (sdl_wnd)
     131        SDL_DestroyWindow(sdl_wnd);
     132    sdl_wnd = SDL_CreateWindow(
     133      "SDL2",
     134      SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
     135      vo_dwidth, vo_dheight,
     136      flags
     137    );
     138    if (!sdl_wnd) {
    148139      mp_msg(MSGT_VO, MSGL_FATAL, "SDL SetVideoMode failed: %s\n", SDL_GetError());
    149140      return NULL;
    150141    }
    151     vo_dwidth  = s->w;
    152     vo_dheight = s->h;
    153     return s;
     142    SDL_GetWindowSize(sdl_wnd, &vo_dwidth, &vo_dheight);
     143    return (SDL_Surface *)sdl_wnd; // XXX/FIXME: actually plain wrong, but we won't end up in an endless loop initing vo gl
    154144}
    155145
    156146static const struct mp_keymap keysym_map[] = {
    static const struct mp_keymap keysym_map[] = {  
    164154    {SDLK_UP, KEY_UP}, {SDLK_DOWN, KEY_DOWN},
    165155    {SDLK_LEFT, KEY_LEFT}, {SDLK_RIGHT, KEY_RIGHT},
    166156    {SDLK_KP_MULTIPLY, '*'}, {SDLK_KP_DIVIDE, '/'},
    167     {SDLK_KP0, KEY_KP0}, {SDLK_KP1, KEY_KP1}, {SDLK_KP2, KEY_KP2},
    168     {SDLK_KP3, KEY_KP3}, {SDLK_KP4, KEY_KP4}, {SDLK_KP5, KEY_KP5},
    169     {SDLK_KP6, KEY_KP6}, {SDLK_KP7, KEY_KP7}, {SDLK_KP8, KEY_KP8},
    170     {SDLK_KP9, KEY_KP9},
     157    {SDLK_KP_0, KEY_KP0}, {SDLK_KP_1, KEY_KP1}, {SDLK_KP_2, KEY_KP2},
     158    {SDLK_KP_3, KEY_KP3}, {SDLK_KP_4, KEY_KP4}, {SDLK_KP_5, KEY_KP5},
     159    {SDLK_KP_6, KEY_KP6}, {SDLK_KP_7, KEY_KP7}, {SDLK_KP_8, KEY_KP8},
     160    {SDLK_KP_9, KEY_KP9},
    171161    {SDLK_KP_PERIOD, KEY_KPDEC}, {SDLK_KP_ENTER, KEY_KPENTER},
    172162    {0, 0}
    173163};
    static const struct mp_keymap keysym_map[] = {  
    175165int sdl_default_handle_event(SDL_Event *event)
    176166{
    177167    int mpkey;
    178     if (!event) {
    179         int res = reinit ? VO_EVENT_REINIT : 0;
    180         reinit = 0;
    181         return res;
    182     }
    183168    switch (event->type) {
    184     case SDL_VIDEORESIZE:
    185         vo_dwidth  = event->resize.w;
    186         vo_dheight = event->resize.h;
     169    case SDL_WINDOWEVENT_RESIZED:
     170        vo_dwidth  = event->window.data1;
     171        vo_dheight = event->window.data2;
    187172        return VO_EVENT_RESIZE;
    188173
    189     case SDL_VIDEOEXPOSE:
     174    case SDL_WINDOWEVENT_EXPOSED:
    190175        return VO_EVENT_EXPOSE;
    191176
    192177    case SDL_MOUSEMOTION:
    int sdl_default_handle_event(SDL_Event *event)  
    206191    case SDL_KEYDOWN:
    207192        mpkey = lookup_keymap_table(keysym_map, event->key.keysym.sym);
    208193        if (!mpkey &&
    209             event->key.keysym.unicode > 0 &&
    210             event->key.keysym.unicode < 128)
    211             mpkey = event->key.keysym.unicode;
     194            event->key.keysym.sym > 0 &&
     195            event->key.keysym.sym < 128)
     196            mpkey = (char)event->key.keysym.sym;
     197            if (mpkey >= 'a' && mpkey <= 'z' &&
     198                event->key.keysym.mod & KMOD_SHIFT) {
     199                mpkey -= 32;
     200            }
    212201        if (mpkey)
    213202            mplayer_put_key(mpkey);
    214203        break;
  • libvo/sdl_common.h

    diff --git a/libvo/sdl_common.h b/libvo/sdl_common.h
    index d7f81da..bfa8ad9 100644
    a b  
    2424#include "config.h"
    2525#include <stdint.h>
    2626#ifdef CONFIG_SDL_SDL_H
    27 #include <SDL/SDL.h>
     27#include <SDL2/SDL.h>
    2828#else
    2929#include <SDL.h>
    3030#endif
  • libvo/video_out.c

    diff --git a/libvo/video_out.c b/libvo/video_out.c
    index bcf5174..f167293 100644
    a b const vo_functions_t* const video_out_drivers[] =  
    208208        &video_out_x11,
    209209        &video_out_xover,
    210210#endif
    211 #ifdef CONFIG_SDL
    212         &video_out_sdl,
    213 #endif
    214211#ifdef CONFIG_GL
    215212        &video_out_gl,
    216213#endif