]> git.sesse.net Git - vlc/blobdiff - modules/video_output/glx.c
Fix Metacube header handling with multiple header blocks.
[vlc] / modules / video_output / glx.c
index 8aa1e088b7dd17c8346a099d57eced733c524c46..dc692e9a59c397b44523d8adf4195b7cd481de3f 100644 (file)
@@ -12,7 +12,7 @@
  *
  * This program 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
 #include <vlc_vout_window.h>
 #include <vlc_xlib.h>
 
-static int Open (vlc_object_t *);
-static void Close (vlc_object_t *);
-
-vlc_module_begin ()
-    set_shortname (N_("GLX"))
-    set_description (N_("GLX extension for OpenGL"))
-    set_category (CAT_VIDEO)
-    set_subcategory (SUBCAT_VIDEO_VOUT)
-    set_capability ("opengl", 20)
-    set_callbacks (Open, Close)
-vlc_module_end ()
-
 typedef struct vlc_gl_sys_t
 {
     Display *display;
@@ -54,9 +42,38 @@ typedef struct vlc_gl_sys_t
     GLXContext ctx;
 } vlc_gl_sys_t;
 
-static int MakeCurrent (vlc_gl_t *);
-static void SwapBuffers (vlc_gl_t *);
-static void *GetSymbol(vlc_gl_t *, const char *);
+static int MakeCurrent (vlc_gl_t *gl)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+
+    if (!glXMakeContextCurrent (sys->display, sys->win, sys->win, sys->ctx))
+        return VLC_EGENERIC;
+    return VLC_SUCCESS;
+}
+
+static void ReleaseCurrent (vlc_gl_t *gl)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+
+    glXMakeContextCurrent (sys->display, None, None, NULL);
+}
+
+static void SwapBuffers (vlc_gl_t *gl)
+{
+    vlc_gl_sys_t *sys = gl->sys;
+
+    glXSwapBuffers (sys->display, sys->win);
+}
+
+static void *GetSymbol(vlc_gl_t *gl, const char *procname)
+{
+    (void) gl;
+#ifdef GLX_ARB_get_proc_address
+    return glXGetProcAddressARB ((const GLubyte *)procname);
+#else
+    return NULL;
+#endif
+}
 
 static bool CheckGLX (vlc_object_t *vd, Display *dpy)
 {
@@ -100,7 +117,7 @@ static int Open (vlc_object_t *obj)
 {
     vlc_gl_t *gl = (vlc_gl_t *)obj;
 
-    if (!vlc_xlib_init (obj))
+    if (gl->surface->type != VOUT_WINDOW_TYPE_XID || !vlc_xlib_init (obj))
         return VLC_EGENERIC;
 
     /* Initialize GLX display */
@@ -184,8 +201,18 @@ static int Open (vlc_object_t *obj)
         goto error;
     }
 
+    /* Initialize OpenGL callbacks */
+    gl->sys = sys;
+    gl->makeCurrent = MakeCurrent;
+    gl->releaseCurrent = ReleaseCurrent;
+    gl->resize = NULL;
+    gl->swap = SwapBuffers;
+    gl->getProcAddress = GetSymbol;
+
 #ifdef GLX_ARB_get_proc_address
     bool is_swap_interval_set = false;
+
+    MakeCurrent (gl);
 # ifdef GLX_SGI_swap_control
     if (!is_swap_interval_set
      && CheckGLXext (dpy, snum, "GLX_SGI_swap_control"))
@@ -207,15 +234,9 @@ static int Open (vlc_object_t *obj)
         is_swap_interval_set = true;
     }
 # endif
+    ReleaseCurrent (gl);
 #endif
 
-    /* Initialize OpenGL callbacks */
-    gl->sys = sys;
-    gl->makeCurrent = MakeCurrent;
-    gl->swap = SwapBuffers;
-    gl->getProcAddress = GetSymbol;
-    gl->lock = NULL;
-    gl->unlock = NULL;
     return VLC_SUCCESS;
 
 error:
@@ -236,28 +257,11 @@ static void Close (vlc_object_t *obj)
     free (sys);
 }
 
-static int MakeCurrent (vlc_gl_t *gl)
-{
-    vlc_gl_sys_t *sys = gl->sys;
-
-    if (!glXMakeContextCurrent (sys->display, sys->win, sys->win, sys->ctx))
-        return VLC_EGENERIC;
-    return VLC_SUCCESS;
-}
-
-static void SwapBuffers (vlc_gl_t *gl)
-{
-    vlc_gl_sys_t *sys = gl->sys;
-
-    glXSwapBuffers (sys->display, sys->win);
-}
-
-static void *GetSymbol(vlc_gl_t *gl, const char *procname)
-{
-    (void) gl;
-#ifdef GLX_ARB_get_proc_address
-    return glXGetProcAddressARB ((const GLubyte *)procname);
-#else
-    return NULL;
-#endif
-}
+vlc_module_begin ()
+    set_shortname (N_("GLX"))
+    set_description (N_("GLX extension for OpenGL"))
+    set_category (CAT_VIDEO)
+    set_subcategory (SUBCAT_VIDEO_VOUT)
+    set_capability ("opengl", 20)
+    set_callbacks (Open, Close)
+vlc_module_end ()