Commit e44eb2ad authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

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

parent 904882f2
...@@ -74,6 +74,13 @@ static void HandleMotionNotify (vout_display_t *vd, ...@@ -74,6 +74,13 @@ static void HandleMotionNotify (vout_display_t *vd,
vout_display_SendEventMouseMoved (vd, x, y); 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 static void
HandleParentStructure (vout_display_t *vd, HandleParentStructure (vout_display_t *vd,
const xcb_configure_notify_event_t *ev) const xcb_configure_notify_event_t *ev)
...@@ -86,8 +93,8 @@ HandleParentStructure (vout_display_t *vd, ...@@ -86,8 +93,8 @@ HandleParentStructure (vout_display_t *vd,
/** /**
* Process an X11 event. * Process an X11 event.
*/ */
static int ProcessEvent (vout_display_t *vd, static int ProcessEvent (vout_display_t *vd, bool *visible,
xcb_window_t window, xcb_generic_event_t *ev) xcb_generic_event_t *ev)
{ {
switch (ev->response_type & 0x7f) switch (ev->response_type & 0x7f)
{ {
...@@ -103,15 +110,14 @@ static int ProcessEvent (vout_display_t *vd, ...@@ -103,15 +110,14 @@ static int ProcessEvent (vout_display_t *vd,
HandleMotionNotify (vd, (xcb_motion_notify_event_t *)ev); HandleMotionNotify (vd, (xcb_motion_notify_event_t *)ev);
break; break;
case XCB_CONFIGURE_NOTIFY: case XCB_VISIBILITY_NOTIFY:
{ HandleVisibilityNotify (vd, visible,
xcb_configure_notify_event_t *cn = (xcb_visibility_notify_event_t *)ev);
(xcb_configure_notify_event_t *)ev; break;
assert (cn->window != window); case XCB_CONFIGURE_NOTIFY:
HandleParentStructure (vd, cn); HandleParentStructure (vd, (xcb_configure_notify_event_t *)ev);
break; break;
}
/* FIXME I am not sure it is the right one */ /* FIXME I am not sure it is the right one */
case XCB_DESTROY_NOTIFY: case XCB_DESTROY_NOTIFY:
...@@ -132,12 +138,12 @@ static int ProcessEvent (vout_display_t *vd, ...@@ -132,12 +138,12 @@ static int ProcessEvent (vout_display_t *vd,
/** /**
* Process incoming X events. * 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; xcb_generic_event_t *ev;
while ((ev = xcb_poll_for_event (conn)) != NULL) while ((ev = xcb_poll_for_event (conn)) != NULL)
ProcessEvent (vd, window, ev); ProcessEvent (vd, visible, ev);
if (xcb_connection_has_error (conn)) if (xcb_connection_has_error (conn))
{ {
......
...@@ -79,6 +79,7 @@ struct vout_display_sys_t ...@@ -79,6 +79,7 @@ struct vout_display_sys_t
xcb_window_t window; /* drawable X window */ xcb_window_t window; /* drawable X window */
xcb_gcontext_t gc; /* context to put images */ xcb_gcontext_t gc; /* context to put images */
bool shm; /* whether to use MIT-SHM */ bool shm; /* whether to use MIT-SHM */
bool visible; /* whether to draw */
uint8_t bpp; /* bits per pixel */ uint8_t bpp; /* bits per pixel */
uint8_t pad; /* scanline pad */ uint8_t pad; /* scanline pad */
uint8_t depth; /* useful bits per pixel */ uint8_t depth; /* useful bits per pixel */
...@@ -256,7 +257,7 @@ static int Open (vlc_object_t *obj) ...@@ -256,7 +257,7 @@ static int Open (vlc_object_t *obj)
const uint32_t values[] = { const uint32_t values[] = {
/* XCB_CW_EVENT_MASK */ /* XCB_CW_EVENT_MASK */
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | 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 */ /* XCB_CW_COLORMAP */
cmap, cmap,
}; };
...@@ -276,6 +277,7 @@ static int Open (vlc_object_t *obj) ...@@ -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 window %08"PRIx32, p_sys->window);
msg_Dbg (vd, "using X11 graphic context %08"PRIx32, p_sys->gc); msg_Dbg (vd, "using X11 graphic context %08"PRIx32, p_sys->gc);
p_sys->visible = false;
/* */ /* */
vout_display_info_t info = vd->info; vout_display_info_t info = vd->info;
...@@ -391,6 +393,8 @@ static void Display (vout_display_t *vd, picture_t *pic) ...@@ -391,6 +393,8 @@ static void Display (vout_display_t *vd, picture_t *pic)
xcb_shm_seg_t segment = pic->p_sys->segment; xcb_shm_seg_t segment = pic->p_sys->segment;
xcb_void_cookie_t ck; xcb_void_cookie_t ck;
if (!p_sys->visible)
goto out;
if (segment != 0) if (segment != 0)
ck = xcb_shm_put_image_checked (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 width */ pic->p->i_pitch / pic->p->i_pixel_pitch,
...@@ -427,6 +431,7 @@ static void Display (vout_display_t *vd, picture_t *pic) ...@@ -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 /* 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_RESET_PICTURES if done) + does not work with
* vout_display wrapper. */ * vout_display wrapper. */
out:
picture_Release (pic); picture_Release (pic);
} }
...@@ -516,7 +521,7 @@ static void Manage (vout_display_t *vd) ...@@ -516,7 +521,7 @@ static void Manage (vout_display_t *vd)
{ {
vout_display_sys_t *p_sys = vd->sys; 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) static void ResetPictures (vout_display_t *vd)
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <vlc_picture.h> #include <vlc_picture.h>
#include <vlc_vout_display.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 */ /* keys.c */
typedef struct key_handler_t key_handler_t; typedef struct key_handler_t key_handler_t;
......
...@@ -93,6 +93,7 @@ struct vout_display_sys_t ...@@ -93,6 +93,7 @@ struct vout_display_sys_t
uint16_t height; /* display height */ uint16_t height; /* display height */
uint32_t data_size; /* picture byte size (for non-SHM) */ uint32_t data_size; /* picture byte size (for non-SHM) */
bool shm; /* whether to use MIT-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; xcb_xv_query_image_attributes_reply_t *att;
picture_pool_t *pool; /* picture pool */ picture_pool_t *pool; /* picture pool */
...@@ -440,7 +441,7 @@ static int Open (vlc_object_t *obj) ...@@ -440,7 +441,7 @@ static int Open (vlc_object_t *obj)
const uint32_t mask = const uint32_t mask =
/* XCB_CW_EVENT_MASK */ /* XCB_CW_EVENT_MASK */
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | 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_void_cookie_t c;
xcb_window_t window = xcb_generate_id (conn); xcb_window_t window = xcb_generate_id (conn);
...@@ -468,6 +469,7 @@ static int Open (vlc_object_t *obj) ...@@ -468,6 +469,7 @@ static int Open (vlc_object_t *obj)
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
values); values);
} }
p_sys->visible = false;
/* Create graphic context */ /* Create graphic context */
p_sys->gc = xcb_generate_id (conn); p_sys->gc = xcb_generate_id (conn);
...@@ -613,6 +615,8 @@ static void Display (vout_display_t *vd, picture_t *pic) ...@@ -613,6 +615,8 @@ static void Display (vout_display_t *vd, picture_t *pic)
xcb_shm_seg_t segment = pic->p_sys->segment; xcb_shm_seg_t segment = pic->p_sys->segment;
xcb_void_cookie_t ck; xcb_void_cookie_t ck;
if (!p_sys->visible)
goto out;
if (segment) if (segment)
ck = xcb_xv_shm_put_image_checked (p_sys->conn, p_sys->port, ck = xcb_xv_shm_put_image_checked (p_sys->conn, p_sys->port,
p_sys->window, p_sys->gc, segment, p_sys->id, 0, 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) ...@@ -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); msg_Dbg (vd, "%s: X11 error %d", "cannot put image", e->error_code);
free (e); free (e);
} }
out:
picture_Release (pic); picture_Release (pic);
} }
...@@ -727,6 +731,6 @@ static void Manage (vout_display_t *vd) ...@@ -727,6 +731,6 @@ static void Manage (vout_display_t *vd)
{ {
vout_display_sys_t *p_sys = vd->sys; vout_display_sys_t *p_sys = vd->sys;
ManageEvent (vd, p_sys->conn, p_sys->window); ManageEvent (vd, p_sys->conn, &p_sys->visible);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment