[vlc-commits] XCB/GLX: reuse windowing code from other XCB plugins

Rémi Denis-Courmont git at videolan.org
Tue Jan 22 22:03:24 CET 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jan 22 22:58:41 2013 +0200| [c7c00fa3b38fa61109f387b2cadd6e6ff98550ee] | committer: Rémi Denis-Courmont

XCB/GLX: reuse windowing code from other XCB plugins

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c7c00fa3b38fa61109f387b2cadd6e6ff98550ee
---

 modules/video_output/xcb/events.c  |    6 +--
 modules/video_output/xcb/glx.c     |   91 ++++++------------------------------
 modules/video_output/xcb/xcb_vlc.h |    1 -
 3 files changed, 16 insertions(+), 82 deletions(-)

diff --git a/modules/video_output/xcb/events.c b/modules/video_output/xcb/events.c
index 7e3cc46..797fdcf 100644
--- a/modules/video_output/xcb/events.c
+++ b/modules/video_output/xcb/events.c
@@ -85,8 +85,8 @@ static xcb_connection_t *Connect (vlc_object_t *obj, const char *display)
 /**
  * (Try to) register to mouse events on a window if needed.
  */
-void RegisterMouseEvents (vlc_object_t *obj, xcb_connection_t *conn,
-                          xcb_window_t wnd)
+static void RegisterEvents (vlc_object_t *obj, xcb_connection_t *conn,
+                            xcb_window_t wnd)
 {
     /* Subscribe to parent window resize events */
     uint32_t value = XCB_EVENT_MASK_POINTER_MOTION
@@ -158,7 +158,7 @@ vout_window_t *GetWindow (vout_display_t *vd,
 
     /* Events must be registered before the window geometry is queried, so as
      * to avoid missing impeding resize events. */
-    RegisterMouseEvents (VLC_OBJECT(vd), conn, wnd->handle.xid);
+    RegisterEvents (VLC_OBJECT(vd), conn, wnd->handle.xid);
 
     xcb_get_geometry_reply_t *geo =
         xcb_get_geometry_reply (conn, xcb_get_geometry (conn, wnd->handle.xid),
diff --git a/modules/video_output/xcb/glx.c b/modules/video_output/xcb/glx.c
index 59ef501..9b5b6bb 100644
--- a/modules/video_output/xcb/glx.c
+++ b/modules/video_output/xcb/glx.c
@@ -84,70 +84,19 @@ static void Manage (vout_display_t *);
 static void SwapBuffers (vlc_gl_t *gl);
 static void *GetProcAddress (vlc_gl_t *gl, const char *);
 
-static vout_window_t *MakeWindow (vout_display_t *vd)
+static unsigned GetScreenNumber (xcb_connection_t *conn,
+                                 const xcb_screen_t *screen)
 {
-    vout_window_cfg_t wnd_cfg;
-
-    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;
-
-    vout_window_t *wnd = vout_display_NewWindow (vd, &wnd_cfg);
-    if (wnd == NULL)
-        msg_Err (vd, "parent window not available");
-    return wnd;
-}
-
-static const xcb_screen_t *
-FindWindow (vout_display_t *vd, xcb_connection_t *conn,
-            unsigned *restrict pnum, uint8_t *restrict pdepth,
-            uint16_t *restrict pwidth, uint16_t *restrict pheight)
-{
-    vout_display_sys_t *sys = vd->sys;
-
-    xcb_get_geometry_reply_t *geo =
-        xcb_get_geometry_reply (conn,
-            xcb_get_geometry (conn, sys->embed->handle.xid), NULL);
-    if (geo == NULL)
-    {
-        msg_Err (vd, "parent window not valid");
-        return NULL;
-    }
-
-    xcb_window_t root = geo->root;
-    *pdepth = geo->depth;
-    *pwidth = geo->width;
-    *pheight = geo->height;
-    free (geo);
-
-    /* Find the selected screen */
     const xcb_setup_t *setup = xcb_get_setup (conn);
-    const xcb_screen_t *screen = NULL;
     unsigned num = 0;
 
-    for (xcb_screen_iterator_t i = xcb_setup_roots_iterator (setup);
-         i.rem > 0;
+    for (xcb_screen_iterator_t i = xcb_setup_roots_iterator (setup);;
          xcb_screen_next (&i))
     {
-        if (i.data->root == root)
-        {
-            screen = i.data;
-            break;
-        }
+        if (i.data->root == screen->root)
+            return num;
         num++;
     }
-
-    if (screen == NULL)
-    {
-        msg_Err (vd, "parent window screen not found");
-        return NULL;
-    }
-    msg_Dbg (vd, "using screen 0x%"PRIx32 " (number: %u)", root, num);
-    *pnum = num;
-    return screen;
 }
 
 static bool CheckGLX (vout_display_t *vd, Display *dpy)
@@ -215,22 +164,20 @@ static int Open (vlc_object_t *obj)
     sys->pool = NULL;
     sys->gl.sys = NULL;
 
-    /* Get window */
-    sys->embed = MakeWindow (vd);
+    /* Get window, connect to X server (via XCB) */
+    xcb_connection_t *conn;
+    const xcb_screen_t *scr;
+    uint16_t width, height;
+    uint8_t depth;
+    sys->embed = GetWindow (vd, &conn, &scr, &depth, &width, &height);
     if (sys->embed == NULL)
     {
         free (sys);
         return VLC_EGENERIC;
     }
+    const unsigned snum = GetScreenNumber (conn, scr);
 
-    /* Connect to X server */
-    xcb_connection_t *conn = xcb_connect (sys->embed->display.x11, NULL);
-    if (unlikely(xcb_connection_has_error (conn)))
-    {
-        vout_display_DeleteWindow (vd, sys->embed);
-        free (sys);
-        return VLC_EGENERIC;
-    }
+    sys->conn = conn;
 
     Display *dpy = XOpenDisplay (sys->embed->display.x11);
     if (dpy == NULL)
@@ -241,23 +188,11 @@ static int Open (vlc_object_t *obj)
         return VLC_EGENERIC;
     }
     sys->display = dpy;
-    sys->conn = conn;
     sys->ctx = NULL;
 
     if (!CheckGLX (vd, dpy))
         goto error;
 
-    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,
-                                          &width, &height);
-    if (scr == NULL)
-        goto error;
-
     sys->window = xcb_generate_id (conn);
 
     /* Determine our pixel format */
diff --git a/modules/video_output/xcb/xcb_vlc.h b/modules/video_output/xcb/xcb_vlc.h
index 467fa16..b2bca35 100644
--- a/modules/video_output/xcb/xcb_vlc.h
+++ b/modules/video_output/xcb/xcb_vlc.h
@@ -47,7 +47,6 @@ struct vout_window_t *GetWindow (vout_display_t *obj, xcb_connection_t **,
                                  uint16_t *width, uint16_t *height);
 bool CheckSHM (vlc_object_t *obj, xcb_connection_t *conn);
 xcb_cursor_t CreateBlankCursor (xcb_connection_t *, const xcb_screen_t *);
-void RegisterMouseEvents (vlc_object_t *, xcb_connection_t *, xcb_window_t);
 
 int CheckError (vout_display_t *, xcb_connection_t *conn,
                 const char *str, xcb_void_cookie_t);



More information about the vlc-commits mailing list