[vlc-devel] commit: XCB: don' t bother X server with drawing requests if we are not visible ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Sep 27 14:32:01 CEST 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Sep 27 15:31:18 2009 +0300| [e44eb2ad52416489206110fb6ce08a964956e8ec] | committer: Rémi Denis-Courmont 

XCB: don't bother X server with drawing requests if we are not visible

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

 modules/video_output/xcb/events.c  |   28 +++++++++++++++++-----------
 modules/video_output/xcb/x11.c     |    9 +++++++--
 modules/video_output/xcb/xcb_vlc.h |    2 +-
 modules/video_output/xcb/xvideo.c  |   10 +++++++---
 4 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/modules/video_output/xcb/events.c b/modules/video_output/xcb/events.c
index 3a9b67d..16a4893 100644
--- a/modules/video_output/xcb/events.c
+++ b/modules/video_output/xcb/events.c
@@ -74,6 +74,13 @@ static void HandleMotionNotify (vout_display_t *vd,
         vout_display_SendEventMouseMoved (vd, x, y);
 }
 
+static void HandleVisibilityNotify (vout_display_t *vd, bool *visible,
+                                    const xcb_visibility_notify_event_t *ev)
+{
+    *visible = ev->state != XCB_VISIBILITY_FULLY_OBSCURED;
+    msg_Dbg (vd, "display is %svisible", *visible ? "" : "not ");
+}
+
 static void
 HandleParentStructure (vout_display_t *vd,
                        const xcb_configure_notify_event_t *ev)
@@ -86,8 +93,8 @@ HandleParentStructure (vout_display_t *vd,
 /**
  * Process an X11 event.
  */
-static int ProcessEvent (vout_display_t *vd,
-                         xcb_window_t window, xcb_generic_event_t *ev)
+static int ProcessEvent (vout_display_t *vd, bool *visible,
+                         xcb_generic_event_t *ev)
 {
     switch (ev->response_type & 0x7f)
     {
@@ -103,15 +110,14 @@ static int ProcessEvent (vout_display_t *vd,
             HandleMotionNotify (vd, (xcb_motion_notify_event_t *)ev);
             break;
 
-        case XCB_CONFIGURE_NOTIFY:
-        {
-            xcb_configure_notify_event_t *cn =
-                (xcb_configure_notify_event_t *)ev;
+        case XCB_VISIBILITY_NOTIFY:
+            HandleVisibilityNotify (vd, visible,
+                                    (xcb_visibility_notify_event_t *)ev);
+            break;
 
-            assert (cn->window != window);
-            HandleParentStructure (vd, cn);
+        case XCB_CONFIGURE_NOTIFY:
+            HandleParentStructure (vd, (xcb_configure_notify_event_t *)ev);
             break;
-        }
 
         /* FIXME I am not sure it is the right one */
         case XCB_DESTROY_NOTIFY:
@@ -132,12 +138,12 @@ static int ProcessEvent (vout_display_t *vd,
 /**
  * Process incoming X events.
  */
-int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, xcb_window_t window)
+int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, bool *visible)
 {
     xcb_generic_event_t *ev;
 
     while ((ev = xcb_poll_for_event (conn)) != NULL)
-        ProcessEvent (vd, window, ev);
+        ProcessEvent (vd, visible, ev);
 
     if (xcb_connection_has_error (conn))
     {
diff --git a/modules/video_output/xcb/x11.c b/modules/video_output/xcb/x11.c
index 3f61d66..5e908e2 100644
--- a/modules/video_output/xcb/x11.c
+++ b/modules/video_output/xcb/x11.c
@@ -79,6 +79,7 @@ struct vout_display_sys_t
     xcb_window_t window; /* drawable X window */
     xcb_gcontext_t gc; /* context to put images */
     bool shm; /* whether to use MIT-SHM */
+    bool visible; /* whether to draw */
     uint8_t bpp; /* bits per pixel */
     uint8_t pad; /* scanline pad */
     uint8_t depth; /* useful bits per pixel */
@@ -256,7 +257,7 @@ static int Open (vlc_object_t *obj)
         const uint32_t values[] = {
             /* XCB_CW_EVENT_MASK */
             XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
-            XCB_EVENT_MASK_POINTER_MOTION,
+            XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_VISIBILITY_CHANGE,
             /* XCB_CW_COLORMAP */
             cmap,
         };
@@ -276,6 +277,7 @@ static int Open (vlc_object_t *obj)
     }
     msg_Dbg (vd, "using X11 window %08"PRIx32, p_sys->window);
     msg_Dbg (vd, "using X11 graphic context %08"PRIx32, p_sys->gc);
+    p_sys->visible = false;
 
     /* */
     vout_display_info_t info = vd->info;
@@ -391,6 +393,8 @@ static void Display (vout_display_t *vd, picture_t *pic)
     xcb_shm_seg_t segment = pic->p_sys->segment;
     xcb_void_cookie_t ck;
 
+    if (!p_sys->visible)
+        goto out;
     if (segment != 0)
         ck = xcb_shm_put_image_checked (p_sys->conn, p_sys->window, p_sys->gc,
           /* real width */ pic->p->i_pitch / pic->p->i_pixel_pitch,
@@ -427,6 +431,7 @@ static void Display (vout_display_t *vd, picture_t *pic)
     /* FIXME might be WAY better to wait in some case (be carefull with
      * VOUT_DISPLAY_RESET_PICTURES if done) + does not work with
      * vout_display wrapper. */
+out:
     picture_Release (pic);
 }
 
@@ -516,7 +521,7 @@ static void Manage (vout_display_t *vd)
 {
     vout_display_sys_t *p_sys = vd->sys;
 
-    ManageEvent (vd, p_sys->conn, p_sys->window);
+    ManageEvent (vd, p_sys->conn, &p_sys->visible);
 }
 
 static void ResetPictures (vout_display_t *vd)
diff --git a/modules/video_output/xcb/xcb_vlc.h b/modules/video_output/xcb/xcb_vlc.h
index 88e7374..6f11ba7 100644
--- a/modules/video_output/xcb/xcb_vlc.h
+++ b/modules/video_output/xcb/xcb_vlc.h
@@ -29,7 +29,7 @@
 #include <vlc_picture.h>
 #include <vlc_vout_display.h>
 
-int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, xcb_window_t window);
+int ManageEvent (vout_display_t *vd, xcb_connection_t *conn, bool *);
 
 /* keys.c */
 typedef struct key_handler_t key_handler_t;
diff --git a/modules/video_output/xcb/xvideo.c b/modules/video_output/xcb/xvideo.c
index a418d57..65c15e9 100644
--- a/modules/video_output/xcb/xvideo.c
+++ b/modules/video_output/xcb/xvideo.c
@@ -93,6 +93,7 @@ struct vout_display_sys_t
     uint16_t height;     /* display height */
     uint32_t data_size;  /* picture byte size (for non-SHM) */
     bool shm;            /* whether to use MIT-SHM */
+    bool visible;        /* whether it makes sense to draw at all */
 
     xcb_xv_query_image_attributes_reply_t *att;
     picture_pool_t *pool; /* picture pool */
@@ -440,7 +441,7 @@ static int Open (vlc_object_t *obj)
         const uint32_t mask =
             /* XCB_CW_EVENT_MASK */
             XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
-            XCB_EVENT_MASK_POINTER_MOTION;
+            XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_VISIBILITY_CHANGE;
         xcb_void_cookie_t c;
         xcb_window_t window = xcb_generate_id (conn);
 
@@ -468,6 +469,7 @@ static int Open (vlc_object_t *obj)
                               XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
                               values);
     }
+    p_sys->visible = false;
 
     /* Create graphic context */
     p_sys->gc = xcb_generate_id (conn);
@@ -613,6 +615,8 @@ static void Display (vout_display_t *vd, picture_t *pic)
     xcb_shm_seg_t segment = pic->p_sys->segment;
     xcb_void_cookie_t ck;
 
+    if (!p_sys->visible)
+        goto out;
     if (segment)
         ck = xcb_xv_shm_put_image_checked (p_sys->conn, p_sys->port,
                               p_sys->window, p_sys->gc, segment, p_sys->id, 0,
@@ -642,7 +646,7 @@ static void Display (vout_display_t *vd, picture_t *pic)
         msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code);
         free (e);
     }
-
+out:
     picture_Release (pic);
 }
 
@@ -727,6 +731,6 @@ static void Manage (vout_display_t *vd)
 {
     vout_display_sys_t *p_sys = vd->sys;
 
-    ManageEvent (vd, p_sys->conn, p_sys->window);
+    ManageEvent (vd, p_sys->conn, &p_sys->visible);
 }
 




More information about the vlc-devel mailing list