changeset 36219:673719da1a92

Extract window creation code to common file.
author reimar
date Sun, 09 Jun 2013 18:33:21 +0000
parents c2ca616ffd53
children d1a2f89d0ba6
files libvo/gl_common.c libvo/gl_common.h libvo/video_out.h libvo/vo_gl.c libvo/vo_gl_tiled.c libvo/vo_matrixview.c
diffstat 6 files changed, 71 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/gl_common.c	Sun Jun 09 14:16:37 2013 +0000
+++ b/libvo/gl_common.c	Sun Jun 09 18:33:21 2013 +0000
@@ -2700,6 +2700,61 @@
   }
 }
 
+int mpglcontext_create_window(MPGLContext *ctx, uint32_t d_width, uint32_t d_height,
+                              uint32_t flags, const char *title)
+{
+#ifdef CONFIG_GL_WIN32
+  if (ctx->type == GLTYPE_W32 && !vo_w32_config(d_width, d_height, flags))
+    return -1;
+#endif
+#ifdef CONFIG_GL_OSX
+  if (ctx->type == GLTYPE_OSX && !vo_osx_config(d_width, d_height, flags))
+    return -1;
+#endif
+#ifdef CONFIG_GL_EGL_X11
+  if (ctx->type == GLTYPE_EGL_X11) {
+    XVisualInfo vinfo = { .visual = CopyFromParent, .depth = CopyFromParent };
+    vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
+            CopyFromParent, "gl", title);
+  }
+#endif
+#ifdef CONFIG_GL_X11
+  if (ctx->type == GLTYPE_X11) {
+    int default_glx_attribs[] = {
+      GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
+      GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, (flags & VOFLAG_DEPTH) ? 1 : 0, None
+    };
+    static const int stereo_glx_attribs[]  = {
+      GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
+      GLX_DOUBLEBUFFER, GLX_STEREO, None
+    };
+    XVisualInfo *vinfo = NULL;
+    if (flags & VOFLAG_STEREO) {
+      vinfo = glXChooseVisual(mDisplay, mScreen, stereo_glx_attribs);
+      if (!vinfo)
+        mp_msg(MSGT_VO, MSGL_ERR, "[gl] Could not find a stereo visual, "
+                                  "3D will probably not work!\n");
+    }
+    if (!vinfo)
+      vinfo = glXChooseVisual(mDisplay, mScreen, default_glx_attribs);
+    if (!vinfo) {
+      mp_msg(MSGT_VO, MSGL_ERR, "[gl] no GLX support present\n");
+      return -1;
+    }
+    mp_msg(MSGT_VO, MSGL_V, "[gl] GLX chose visual with ID 0x%x\n", (int)vinfo->visualid);
+
+    vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
+            XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone),
+            "gl", title);
+  }
+#endif
+#ifdef CONFIG_GL_SDL
+  if (ctx->type == GLTYPE_SDL && !vo_sdl_config(d_width, d_height, flags, title))
+    return -1;
+#endif
+  return 0;
+}
+
 void uninit_mpglcontext(MPGLContext *ctx) {
   ctx->releaseGlContext(ctx);
   switch (ctx->type) {
--- a/libvo/gl_common.h	Sun Jun 09 14:16:37 2013 +0000
+++ b/libvo/gl_common.h	Sun Jun 09 18:33:21 2013 +0000
@@ -231,6 +231,7 @@
 } MPGLContext;
 
 int init_mpglcontext(MPGLContext *ctx, enum MPGLType type);
+int mpglcontext_create_window(MPGLContext *ctx, uint32_t d_width, uint32_t d_height, uint32_t flags, const char *title);
 void uninit_mpglcontext(MPGLContext *ctx);
 
 extern GLenum (GLAPIENTRY *mpglGetError)(void);
--- a/libvo/video_out.h	Sun Jun 09 14:16:37 2013 +0000
+++ b/libvo/video_out.h	Sun Jun 09 18:33:21 2013 +0000
@@ -115,6 +115,7 @@
 #define VOFLAG_FLIPPING           0x08
 #define VOFLAG_HIDDEN             0x10  //< Use to create a hidden window
 #define VOFLAG_STEREO             0x20  //< Use to create a stereo-capable window
+#define VOFLAG_DEPTH              0x40  //< Request a depth buffer
 #define VOFLAG_XOVERLAY_SUB_VO 0x10000
 
 typedef struct vo_info_s
--- a/libvo/vo_gl.c	Sun Jun 09 14:16:37 2013 +0000
+++ b/libvo/vo_gl.c	Sun Jun 09 18:33:21 2013 +0000
@@ -663,51 +663,6 @@
 {
   if (stereo_mode == GL_3D_QUADBUFFER)
     flags |= VOFLAG_STEREO;
-#ifdef CONFIG_GL_WIN32
-  if (glctx.type == GLTYPE_W32 && !vo_w32_config(d_width, d_height, flags))
-    return -1;
-#endif
-#ifdef CONFIG_GL_OSX
-  if (glctx.type == GLTYPE_OSX && !vo_osx_config(d_width, d_height, flags))
-    return -1;
-#endif
-#ifdef CONFIG_GL_EGL_X11
-  if (glctx.type == GLTYPE_EGL_X11) {
-    XVisualInfo vinfo = { .visual = CopyFromParent, .depth = CopyFromParent };
-    vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height, flags,
-            CopyFromParent, "gl", title);
-  }
-#endif
-#ifdef CONFIG_GL_X11
-  if (glctx.type == GLTYPE_X11) {
-    static int default_glx_attribs[] = {
-      GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
-      GLX_DOUBLEBUFFER, None
-    };
-    static int stereo_glx_attribs[]  = {
-      GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
-      GLX_DOUBLEBUFFER, GLX_STEREO, None
-    };
-    XVisualInfo *vinfo = NULL;
-    if (stereo_mode == GL_3D_QUADBUFFER) {
-      vinfo = glXChooseVisual(mDisplay, mScreen, stereo_glx_attribs);
-      if (!vinfo)
-        mp_msg(MSGT_VO, MSGL_ERR, "[gl] Could not find a stereo visual, "
-                                  "3D will probably not work!\n");
-    }
-    if (!vinfo)
-      vinfo = glXChooseVisual(mDisplay, mScreen, default_glx_attribs);
-    if (!vinfo) {
-      mp_msg(MSGT_VO, MSGL_ERR, "[gl] no GLX support present\n");
-      return -1;
-    }
-    mp_msg(MSGT_VO, MSGL_V, "[gl] GLX chose visual with ID 0x%x\n", (int)vinfo->visualid);
-
-    vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
-            XCreateColormap(mDisplay, mRootWin, vinfo->visual, AllocNone),
-            "gl", title);
-  }
-#endif
 #ifdef CONFIG_GL_SDL
   if (glctx.type == GLTYPE_SDL) {
     // Ugly to do this here, but SDL ignores it if set later
@@ -718,11 +673,9 @@
       SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, swap_interval);
 #endif
     }
-    if (!vo_sdl_config(d_width, d_height, flags, title))
-        return -1;
   }
 #endif
-  return 0;
+  return mpglcontext_create_window(&glctx, d_width, d_height, flags, title);
 }
 
 #ifdef CONFIG_GL_OSX
--- a/libvo/vo_gl_tiled.c	Sun Jun 09 14:16:37 2013 +0000
+++ b/libvo/vo_gl_tiled.c	Sun Jun 09 18:33:21 2013 +0000
@@ -456,17 +456,6 @@
    draw(w,h,src,srca,stride,ImageData+bpp*(y0*image_width+x0),bpp*image_width);
 }
 
-#ifdef CONFIG_GL_WIN32
-
-static int config_w32(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) {
-  if (!vo_w32_config(d_width, d_height, flags))
-    return -1;
-
-  return 0;
-}
-
-#endif
-
 #ifdef CONFIG_GL_X11
 static int choose_glx_visual(Display *dpy, int scr, XVisualInfo *res_vi)
 {
@@ -614,12 +603,11 @@
 
   int_pause = 0;
 
-#ifdef CONFIG_GL_WIN32
-  if (config_w32(width, height, d_width, d_height, flags, title, format) == -1)
+#ifdef CONFIG_GL_X11
+  if (glctx.type == GLTYPE_X11 && config_glx(width, height, d_width, d_height, flags, title, format) == -1)
+    return -1;
 #endif
-#ifdef CONFIG_GL_X11
-  if (config_glx(width, height, d_width, d_height, flags, title, format) == -1)
-#endif
+  if (glctx.type != GLTYPE_X11 && mpglcontext_create_window(&glctx, d_width, d_height, flags, title) < 0)
     return -1;
 
   if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
@@ -822,11 +810,8 @@
 
 static int preinit(const char *arg)
 {
-  enum MPGLType gltype = GLTYPE_X11;
+  enum MPGLType gltype = GLTYPE_AUTO;
   // set defaults
-#ifdef CONFIG_GL_WIN32
-  gltype = GLTYPE_W32;
-#endif
   use_yuv = -1;
   use_glFinish = 1;
   if (subopt_parse(arg, subopts) != 0) {
@@ -848,13 +833,12 @@
   }
     if(!init_mpglcontext(&glctx, gltype)) goto err_out;
     if (use_yuv == -1) {
-#ifdef CONFIG_GL_WIN32
-      if (config_w32(320, 200, 320, 200, VOFLAG_HIDDEN, "", 0) == -1)
+#ifdef CONFIG_GL_X11
+      if (glctx.type == GLTYPE_X11 && config_glx(320, 200, 320, 200, VOFLAG_HIDDEN, "", 0) == -1)
+        goto err_out;
 #endif
-#ifdef CONFIG_GL_X11
-      if (config_glx(320, 200, 320, 200, VOFLAG_HIDDEN, "", 0) == -1)
-#endif
-        goto err_out;
+      if (glctx.type != GLTYPE_X11 && mpglcontext_create_window(&glctx, 320, 200, VOFLAG_HIDDEN, "") < 0)
+        return -1;
       if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
         goto err_out;
       use_yuv = glAutodetectYUVConversion();
--- a/libvo/vo_matrixview.c	Sun Jun 09 14:16:37 2013 +0000
+++ b/libvo/vo_matrixview.c	Sun Jun 09 18:33:21 2013 +0000
@@ -50,18 +50,6 @@
 
 static MPGLContext glctx;
 
-#ifdef CONFIG_GL_X11
-static int wsGLXAttrib[] = {
-    GLX_RGBA,
-    GLX_RED_SIZE,1,
-    GLX_GREEN_SIZE,1,
-    GLX_BLUE_SIZE,1,
-    GLX_DEPTH_SIZE,1,
-    GLX_DOUBLEBUFFER,
-    None
-};
-#endif
-
 static int int_pause;
 static int eq_contrast;
 static int eq_brightness;
@@ -115,26 +103,9 @@
 
     int_pause = 0;
 
-#ifdef CONFIG_GL_WIN32
-    if (glctx.type == GLTYPE_W32 && !vo_w32_config(d_width, d_height, flags))
+    flags |= VOFLAG_DEPTH;
+    if (mpglcontext_create_window(&glctx, d_width, d_height, flags, title) < 0)
         return -1;
-#endif
-#ifdef CONFIG_GL_X11
-    if (glctx.type == GLTYPE_X11) {
-        XVisualInfo *vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
-        if (vinfo == NULL) {
-            mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] no GLX support present\n");
-            return -1;
-        }
-        mp_msg(MSGT_VO, MSGL_V, "[matrixview] GLX chose visual with ID 0x%x\n",
-               (int)vinfo->visualid);
-
-        vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
-                                XCreateColormap(mDisplay, mRootWin,
-                                                vinfo->visual, AllocNone),
-                                "matrixview", title);
-    }
-#endif /* CONFIG_GL_WIN32 */
     if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
         return -1;
 
@@ -244,10 +215,7 @@
 
 static int preinit(const char *arg)
 {
-    enum MPGLType gltype = GLTYPE_X11;
-#ifdef CONFIG_GL_WIN32
-    gltype = GLTYPE_W32;
-#endif
+    enum MPGLType gltype = GLTYPE_AUTO;
     if (!init_mpglcontext(&glctx, gltype))
         return -1;