summaryrefslogtreecommitdiff
path: root/xcb.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2011-04-02 19:49:38 +0200
committerMichael Stapelberg <michael@stapelberg.de>2011-04-02 19:49:38 +0200
commite03e93fd1bb6f347b13d42796c1f0dada4ca8bb5 (patch)
treeea4fe16a784b838f2ae3c9486411a1b9af0430bd /xcb.c
parente7201e2df53e740e364d6d0992a1c6e329909e06 (diff)
optimization: render to pixmap which is used as background for the window
Before this commit, the background color (white by default) was visible for about 100ms until the image was drawn. This flickering is now eliminated. Also, we don’t need to handle Expose-events anymore, as X11 will use the window’s background pixmap automatically.
Diffstat (limited to 'xcb.c')
-rw-r--r--xcb.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/xcb.c b/xcb.c
index 32077e1..818bf75 100644
--- a/xcb.c
+++ b/xcb.c
@@ -78,13 +78,34 @@ xcb_visualtype_t *get_root_visual_type(xcb_screen_t *screen) {
return NULL;
}
-xcb_window_t open_fullscreen_window(xcb_connection_t *conn, xcb_screen_t *scr, char *color) {
+xcb_pixmap_t create_bg_pixmap(xcb_connection_t *conn, xcb_screen_t *scr, char *color) {
+ xcb_pixmap_t bg_pixmap = xcb_generate_id(conn);
+ xcb_create_pixmap(conn, scr->root_depth, bg_pixmap, scr->root,
+ scr->width_in_pixels, scr->height_in_pixels);
+
+ /* Generate a Graphics Context and fill the pixmap with background color
+ * (for images that are smaller than your screen) */
+ xcb_gcontext_t gc = xcb_generate_id(conn);
+ uint32_t values[] = { get_colorpixel(color) };
+ xcb_create_gc(conn, gc, bg_pixmap, XCB_GC_FOREGROUND, values);
+ xcb_rectangle_t rect = { 0, 0, scr->width_in_pixels, scr->height_in_pixels };
+ xcb_poly_fill_rectangle(conn, bg_pixmap, gc, 1, &rect);
+
+ return bg_pixmap;
+}
+
+xcb_window_t open_fullscreen_window(xcb_connection_t *conn, xcb_screen_t *scr, char *color, xcb_pixmap_t pixmap) {
uint32_t mask = 0;
uint32_t values[3];
xcb_window_t win = xcb_generate_id(conn);
- mask |= XCB_CW_BACK_PIXEL;
- values[0] = get_colorpixel(color);
+ if (pixmap == XCB_NONE) {
+ mask |= XCB_CW_BACK_PIXEL;
+ values[0] = get_colorpixel(color);
+ } else {
+ mask |= XCB_CW_BACK_PIXMAP;
+ values[0] = pixmap;
+ }
mask |= XCB_CW_OVERRIDE_REDIRECT;
values[1] = 1;