From b4491667ccc2012b19e4cc4780fae8538cfeb874 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 13 Dec 2015 18:24:31 +0200 Subject: [PATCH] Defer window pixmap and mask updates until rendering time Interactive operations may result in a large number of changes within a single frame. Processing each one separately is a waste of time since only the last results will be visible. Additionally it's easier to make sure the GL context is available. --- source/main.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/source/main.c b/source/main.c index 6f35c98..30833db 100644 --- a/source/main.c +++ b/source/main.c @@ -25,9 +25,11 @@ typedef struct CompositedWindow Damage damage; Pixmap pixmap; GLXPixmap glx_pixmap; + int recreate_pixmap; unsigned texture; unsigned mask_texture; int use_mask; + int recreate_mask; } CompositedWindow; typedef struct CompositedMonitor @@ -377,6 +379,7 @@ void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, Comp window->pixmap = XCompositeNameWindowPixmap(compositor->display, window->window); window->glx_pixmap = glXCreatePixmap(compositor->display, screen->fbconfig, window->pixmap, attribs); + window->recreate_pixmap = 0; } void update_window_mask(Compositor *compositor, CompositedWindow *window) @@ -446,6 +449,8 @@ void update_window_mask(Compositor *compositor, CompositedWindow *window) glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data); free(data); + + window->recreate_mask = 0; } CompositedWindow *add_window(Compositor *compositor, CompositedScreen *screen, Window w) @@ -488,14 +493,11 @@ CompositedWindow *add_window(Compositor *compositor, CompositedScreen *screen, W window->glx_pixmap = None; XCompositeRedirectWindow(compositor->display, window->window, CompositeRedirectManual); - if(window->map_state==IsViewable) - create_window_pixmap(compositor, screen, window); + window->recreate_pixmap = (window->map_state==IsViewable); window->texture = create_2d_texture(); window->mask_texture = create_2d_texture(); - - if(window->map_state==IsViewable) - update_window_mask(compositor, window); + window->recreate_mask = (window->map_state==IsViewable); XShapeSelectInput(compositor->display, window->window, ShapeNotifyMask); @@ -1022,8 +1024,8 @@ void process_map_event(Compositor *compositor, XMapEvent *event) return; window->map_state = IsViewable; - create_window_pixmap(compositor, screen, window); - update_window_mask(compositor, window); + window->recreate_pixmap = 1; + window->recreate_mask = 1; mark_dirty(compositor, screen); } @@ -1088,7 +1090,7 @@ void process_configure_event(Compositor *compositor, XConfigureEvent *event) window->width = event->width; window->height = event->height; window->border = event->border_width; - create_window_pixmap(compositor, screen, window); + window->recreate_pixmap = 1; } reorder_window(screen, window, event->above); @@ -1131,7 +1133,7 @@ void process_shape_event(Compositor *compositor, XShapeEvent *event) window = find_window_global(compositor, event->window, &screen); if(window && window->map_state==IsViewable) { - update_window_mask(compositor, window); + window->recreate_mask = 1; mark_dirty(compositor, screen); } } @@ -1222,6 +1224,11 @@ void refresh_screen(Compositor *compositor, CompositedScreen *screen) XDamageSubtract(compositor->display, window->damage, None, None); + if(window->recreate_pixmap) + create_window_pixmap(compositor, screen, window); + if(window->recreate_mask) + update_window_mask(compositor, window); + glBindTexture(GL_TEXTURE_2D, window->texture); compositor->glXBindTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL); glUniform4f((use_mask ? screen->masked_geometry_loc : screen->geometry_loc), -- 2.45.2