]> git.sesse.net Git - vlc/blobdiff - modules/video_output/xcb/glx.c
Set vout_display_info_t::has_event_thread for msw and xcb vouts.
[vlc] / modules / video_output / xcb / glx.c
index 8e5ae3ad48b0db8e0f00bc71910eb86816228495..f67d9f63eb1be713cd78852a7d7f53b78d2fabd2 100644 (file)
@@ -51,11 +51,12 @@ vlc_module_begin ()
     set_description (N_("GLX video output (XCB)"))
     set_category (CAT_VIDEO)
     set_subcategory (SUBCAT_VIDEO_VOUT)
-    set_capability ("vout display", 20)
+    set_capability ("vout display", 50)
     set_callbacks (Open, Close)
 
     add_shortcut ("xcb-glx")
     add_shortcut ("glx")
+    add_shortcut ("opengl")
 vlc_module_end ()
 
 struct vout_display_sys_t
@@ -66,8 +67,6 @@ struct vout_display_sys_t
     xcb_cursor_t cursor; /* blank cursor */
     xcb_window_t window; /* drawable X window */
     xcb_window_t glwin; /* GLX window */
-    uint16_t width; /* render pixel width */
-    uint16_t height; /* render pixel height */
     bool visible; /* whether to draw */
     bool v1_3; /* whether GLX >= 1.3 is available */
 
@@ -77,7 +76,7 @@ struct vout_display_sys_t
     picture_pool_t *pool; /* picture pool */
 };
 
-static picture_t *Get (vout_display_t *);
+static picture_pool_t *Pool (vout_display_t *, unsigned);
 static void PictureRender (vout_display_t *, picture_t *);
 static void PictureDisplay (vout_display_t *, picture_t *);
 static int Control (vout_display_t *, int, va_list);
@@ -91,6 +90,8 @@ static vout_window_t *MakeWindow (vout_display_t *vd)
 
     memset (&wnd_cfg, 0, sizeof (wnd_cfg));
     wnd_cfg.type = VOUT_WINDOW_TYPE_XID;
+    wnd_cfg.x = var_InheritInteger (vd, "video-x");
+    wnd_cfg.y = var_InheritInteger (vd, "video-y");
     wnd_cfg.width  = vd->cfg->display.width;
     wnd_cfg.height = vd->cfg->display.height;
 
@@ -109,7 +110,7 @@ FindWindow (vout_display_t *vd, xcb_connection_t *conn,
 
     xcb_get_geometry_reply_t *geo =
         xcb_get_geometry_reply (conn,
-            xcb_get_geometry (conn, sys->embed->xid), NULL);
+            xcb_get_geometry (conn, sys->embed->handle.xid), NULL);
     if (geo == NULL)
     {
         msg_Err (vd, "parent window not valid");
@@ -172,7 +173,8 @@ static bool CheckGLX (vout_display_t *vd, Display *dpy, bool *restrict pv13)
 }
 
 static int CreateWindow (vout_display_t *vd, xcb_connection_t *conn,
-                         uint_fast8_t depth, xcb_visualid_t vid)
+                         uint_fast8_t depth, xcb_visualid_t vid,
+                         uint_fast16_t width, uint_fast16_t height)
 {
     vout_display_sys_t *sys = vd->sys;
     const uint32_t mask = XCB_CW_EVENT_MASK;
@@ -183,8 +185,8 @@ static int CreateWindow (vout_display_t *vd, xcb_connection_t *conn,
     xcb_void_cookie_t cc, cm;
 
     cc = xcb_create_window_checked (conn, depth, sys->window,
-                                    sys->embed->xid, 0, 0,
-                                    sys->width, sys->height, 0,
+                                    sys->embed->handle.xid, 0, 0,
+                                    width, height, 0,
                                     XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                     vid, mask, values);
     cm = xcb_map_window_checked (conn, sys->window);
@@ -201,6 +203,9 @@ static int CreateWindow (vout_display_t *vd, xcb_connection_t *conn,
  */
 static int Open (vlc_object_t *obj)
 {
+    if (!XInitThreads ())
+        return VLC_EGENERIC;
+
     vout_display_t *vd = (vout_display_t *)obj;
     vout_display_sys_t *sys = malloc (sizeof (*sys));
 
@@ -220,7 +225,7 @@ static int Open (vlc_object_t *obj)
     }
 
     /* Connect to X server */
-    Display *dpy = XOpenDisplay (sys->embed->x11_display);
+    Display *dpy = XOpenDisplay (sys->embed->display.x11);
     if (dpy == NULL)
     {
         vout_display_DeleteWindow (vd, sys->embed);
@@ -236,13 +241,14 @@ static int Open (vlc_object_t *obj)
 
     xcb_connection_t *conn = XGetXCBConnection (dpy);
     assert (conn);
-    RegisterMouseEvents (obj, conn, sys->embed->xid);
+    RegisterMouseEvents (obj, conn, sys->embed->handle.xid);
 
     /* Find window parameters */
     unsigned snum;
     uint8_t depth;
+    uint16_t width, height;
     const xcb_screen_t *scr = FindWindow (vd, conn, &snum, &depth,
-                                          &sys->width, &sys->height);
+                                          &width, &height);
     if (scr == NULL)
         goto error;
 
@@ -260,6 +266,15 @@ static int Open (vlc_object_t *obj)
             GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
             None };
 
+        xcb_get_window_attributes_reply_t *wa =
+            xcb_get_window_attributes_reply (conn,
+                xcb_get_window_attributes (conn, sys->embed->handle.xid),
+                NULL);
+        if (wa == NULL)
+            goto error;
+        xcb_visualid_t visual = wa->visual;
+        free (wa);
+
         int nelem;
         GLXFBConfig *confs = glXChooseFBConfig (dpy, snum, attr, &nelem);
         if (confs == NULL)
@@ -268,29 +283,48 @@ static int Open (vlc_object_t *obj)
             goto error;
         }
 
-        /*XVisualInfo *vi = glXGetVisualFromFBConfig (dpy, confs[0]);*/
-        CreateWindow (vd, conn, depth, 0 /* ??? */);
-        /*XFree (vi);*/
+        GLXFBConfig conf;
+        bool found = false;
+
+        for (int i = 0; i < nelem && !found; i++)
+        {
+            conf = confs[i];
+
+            XVisualInfo *vi = glXGetVisualFromFBConfig (dpy, conf);
+            if (vi == NULL)
+                continue;
+
+            if (vi->visualid == visual)
+                found = true;
+            XFree (vi);
+        }
+        XFree (confs);
+
+        if (!found)
+        {
+            msg_Err (vd, "no matching GLX frame buffer configuration");
+            goto error;
+        }
 
-        sys->glwin = glXCreateWindow (dpy, confs[0], sys->window, NULL );
+        sys->glwin = None;
+        if (!CreateWindow (vd, conn, depth, 0 /* ??? */, width, height))
+            sys->glwin = glXCreateWindow (dpy, conf, sys->window, NULL );
         if (sys->glwin == None)
         {
             msg_Err (vd, "cannot create GLX window");
-            XFree (confs);
             goto error;
         }
 
         /* Create an OpenGL context */
-        sys->ctx = glXCreateNewContext (dpy, confs[0], GLX_RGBA_TYPE, NULL,
+        sys->ctx = glXCreateNewContext (dpy, conf, GLX_RGBA_TYPE, NULL,
                                         True);
-        XFree (confs);
         if (sys->ctx == NULL)
         {
             msg_Err (vd, "cannot create GLX context");
             goto error;
         }
 
-        if (glXMakeContextCurrent (dpy, sys->glwin, sys->glwin, sys->ctx))
+        if (!glXMakeContextCurrent (dpy, sys->glwin, sys->glwin, sys->ctx))
             goto error;
     }
     else
@@ -311,7 +345,7 @@ static int Open (vlc_object_t *obj)
         }
         msg_Dbg (vd, "using GLX visual ID 0x%"PRIx32, (uint32_t)vi->visualid);
 
-        if (CreateWindow (vd, conn, depth, 0 /* ??? */) == 0)
+        if (CreateWindow (vd, conn, depth, 0 /* ??? */, width, height) == 0)
             sys->ctx = glXCreateContext (dpy, vi, 0, True);
         XFree (vi);
         if (sys->ctx == NULL)
@@ -343,19 +377,23 @@ static int Open (vlc_object_t *obj)
     /* */
     vout_display_info_t info = vd->info;
     info.has_pictures_invalid = false;
+    info.has_event_thread = true;
 
     /* Setup vout_display_t once everything is fine */
     vd->info = info;
 
-    vd->get = Get;
+    vd->pool = Pool;
     vd->prepare = PictureRender;
     vd->display = PictureDisplay;
     vd->control = Control;
     vd->manage = Manage;
 
     /* */
-    vout_display_SendEventFullscreen (vd, false);
-    vout_display_SendEventDisplaySize (vd, sys->width, sys->height, false);
+    bool is_fullscreen = vd->cfg->is_fullscreen;
+    if (is_fullscreen && vout_window_SetFullScreen (sys->embed, true))
+        is_fullscreen = false;
+    vout_display_SendEventFullscreen (vd, is_fullscreen);
+    vout_display_SendEventDisplaySize (vd, width, height, is_fullscreen);
 
     return VLC_SUCCESS;
 
@@ -380,14 +418,20 @@ static void Close (vlc_object_t *obj)
     if (sys->ctx != NULL)
     {
         if (sys->v1_3)
-        {
             glXMakeContextCurrent (dpy, None, None, NULL);
-            glXDestroyWindow (dpy, sys->glwin);
-        }
         else
             glXMakeCurrent (dpy, None, NULL);
         glXDestroyContext (dpy, sys->ctx);
+        if (sys->v1_3)
+            glXDestroyWindow (dpy, sys->glwin);
     }
+
+    /* show the default cursor */
+    xcb_change_window_attributes (XGetXCBConnection (sys->display),
+                                  sys->embed->handle.xid, XCB_CW_CURSOR,
+                                  &(uint32_t) { XCB_CURSOR_NONE });
+    xcb_flush (XGetXCBConnection (sys->display));
+
     XCloseDisplay (dpy);
     vout_display_DeleteWindow (vd, sys->embed);
     free (sys);
@@ -397,24 +441,20 @@ static void SwapBuffers (vout_opengl_t *gl)
 {
     vout_display_sys_t *sys = gl->sys;
 
-    glViewport (0, 0, sys->width, sys->height);
     glXSwapBuffers (sys->display, sys->glwin);
 }
 
 /**
  * Return a direct buffer
  */
-static picture_t *Get (vout_display_t *vd)
+static picture_pool_t *Pool (vout_display_t *vd, unsigned requested_count)
 {
     vout_display_sys_t *sys = vd->sys;
+    (void)requested_count;
 
     if (!sys->pool)
-    {
         sys->pool = vout_display_opengl_GetPool (&sys->vgl);
-        if (!sys->pool)
-            return NULL;
-    }
-    return picture_pool_Get (sys->pool);
+    return sys->pool;
 }
 
 static void PictureRender (vout_display_t *vd, picture_t *pic)
@@ -444,10 +484,10 @@ static int Control (vout_display_t *vd, int query, va_list ap)
         return vout_window_SetFullScreen (sys->embed, c->is_fullscreen);
     }
 
-    case VOUT_DISPLAY_CHANGE_ON_TOP:
+    case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
     {
-        int b_on_top = (int)va_arg (ap, int);
-        return vout_window_SetOnTop (sys->embed, b_on_top);
+        unsigned state = va_arg (ap, unsigned);
+        return vout_window_SetState (sys->embed, state);
     }
 
     case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
@@ -486,17 +526,19 @@ static int Control (vout_display_t *vd, int query, va_list ap)
 
         vout_display_place_t place;
         vout_display_PlacePicture (&place, source, cfg, false);
-        sys->width  = place.width;
-        sys->height = place.height;
 
         /* Move the picture within the window */
         const uint32_t values[] = { place.x, place.y,
                                     place.width, place.height, };
-        xcb_configure_window (conn, sys->window,
-                              XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
-                            | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
+        xcb_void_cookie_t ck =
+            xcb_configure_window_checked (conn, sys->window,
+                            XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
+                          | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
                               values);
-        xcb_flush (conn);
+        if (CheckError (vd, conn, "cannot resize X11 window", ck))
+            return VLC_EGENERIC;
+
+        glViewport (0, 0, place.width, place.height);
         return VLC_SUCCESS;
     }
 
@@ -504,9 +546,17 @@ static int Control (vout_display_t *vd, int query, va_list ap)
      * vout_display_t::info.b_hide_mouse is false */
     case VOUT_DISPLAY_HIDE_MOUSE:
         xcb_change_window_attributes (XGetXCBConnection (sys->display),
-                                      sys->embed->xid,
+                                      sys->embed->handle.xid,
                                     XCB_CW_CURSOR, &(uint32_t){ sys->cursor });
         return VLC_SUCCESS;
+
+    case VOUT_DISPLAY_GET_OPENGL:
+    {
+        vout_opengl_t **gl = va_arg (ap, vout_opengl_t **);
+        *gl = &sys->gl;
+        return VLC_SUCCESS;
+    }
+
     case VOUT_DISPLAY_RESET_PICTURES:
         assert (0);
     default: