XCB_x11: wait until picture is displayed
authorRémi Denis-Courmont <remi@remlab.net>
Wed, 2 Sep 2009 16:22:26 +0000 (19:22 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Wed, 2 Sep 2009 16:22:26 +0000 (19:22 +0300)
modules/video_output/xcb/x11.c

index c9b4078..3c93a1b 100644 (file)
@@ -389,9 +389,10 @@ static void Display (vout_display_t *vd, picture_t *pic)
 {
     vout_display_sys_t *p_sys = vd->sys;
     xcb_shm_seg_t segment = pic->p_sys->segment;
+    xcb_void_cookie_t ck;
 
     if (segment != 0)
-        xcb_shm_put_image (p_sys->conn, p_sys->window, p_sys->gc,
+        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,
          /* real height */ pic->p->i_lines,
                    /* x */ vd->fmt.i_x_offset,
@@ -405,13 +406,23 @@ static void Display (vout_display_t *vd, picture_t *pic)
         const size_t offset = vd->fmt.i_y_offset * pic->p->i_pitch;
         const unsigned lines = pic->p->i_lines - vd->fmt.i_y_offset;
 
-        xcb_put_image (p_sys->conn, XCB_IMAGE_FORMAT_Z_PIXMAP,
+        ck = xcb_put_image_checked (p_sys->conn, XCB_IMAGE_FORMAT_Z_PIXMAP,
                        p_sys->window, p_sys->gc,
                        pic->p->i_pitch / pic->p->i_pixel_pitch,
                        lines, -vd->fmt.i_x_offset, 0, 0, p_sys->depth,
                        pic->p->i_pitch * lines, pic->p->p_pixels + offset);
     }
-    xcb_flush (p_sys->conn);
+
+    /* Wait for reply. This makes sure that the X server gets CPU time to
+     * display the picture. xcb_flush() is *not* sufficient: especially with
+     * shared memory the PUT requests are so short that many of them can fit in
+     * X11 socket output buffer before the kernel preempts VLC. */
+    xcb_generic_error_t *e = xcb_request_check (p_sys->conn, ck);
+    if (e != NULL)
+    {
+        msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code);
+        free (e);
+    }
 
     /* FIXME might be WAY better to wait in some case (be carefull with
      * VOUT_DISPLAY_RESET_PICTURES if done) + does not work with