Improvement: GLX: Cache region contents & --glx-no-rebind-pixmap

- Cache region contents in is_region_empty(), mostly useful only for GLX
  backend to save one roundtrip to X.

- GLX backend: Add --glx-no-rebind-pixmap, which prevents rebinding of
  GLX texture to pixmap on content change. It doesn't work on some
  drivers, but it saves some CPU on those where it does.

- Wrap XFree() with a new function cxfree() since its man page claims
  NULL pointers are not acceptable (although in fact it does...).

- Use macro to save some code in get_cfg(). Code clean-up.
pull/2/head
Richard Grenville 11 years ago
parent ab53e73ce7
commit 53870fb7fe

@ -1183,7 +1183,7 @@ c2_match_once_leaf(session_t *ps, win *w, const c2_l_t *pleaf,
// Free the string after usage, if necessary // Free the string after usage, if necessary
if (tgt_free) { if (tgt_free) {
if (C2_L_TATOM == pleaf->type) if (C2_L_TATOM == pleaf->type)
XFree(tgt_free); cxfree(tgt_free);
else else
free(tgt_free); free(tgt_free);
} }

@ -357,12 +357,15 @@ typedef struct {
char *display; char *display;
/// The backend in use. /// The backend in use.
enum backend backend; enum backend backend;
/// Whether to avoid using stencil buffer under GLX backend. Might be unsafe. /// Whether to avoid using stencil buffer under GLX backend. Might be
/// unsafe.
bool glx_no_stencil; bool glx_no_stencil;
/// Whether to copy unmodified regions from front buffer. /// Whether to copy unmodified regions from front buffer.
bool glx_copy_from_front; bool glx_copy_from_front;
/// Whether to use glXCopySubBufferMESA() to update screen. /// Whether to use glXCopySubBufferMESA() to update screen.
bool glx_use_copysubbuffermesa; bool glx_use_copysubbuffermesa;
/// Whether to avoid rebinding pixmap on window damage.
bool glx_no_rebind_pixmap;
/// Whether to try to detect WM windows and mark them as focused. /// Whether to try to detect WM windows and mark them as focused.
bool mark_wmwin_focused; bool mark_wmwin_focused;
/// Whether to mark override-redirect windows as focused. /// Whether to mark override-redirect windows as focused.
@ -1424,6 +1427,17 @@ fds_poll(session_t *ps, struct timeval *ptv) {
} }
#undef CPY_FDS #undef CPY_FDS
/**
* Wrapper of XFree() for convenience.
*
* Because a NULL pointer cannot be passed to XFree(), its man page says.
*/
static inline void
cxfree(void *data) {
if (data)
XFree(data);
}
/** /**
* Wrapper of XInternAtom() for convenience. * Wrapper of XInternAtom() for convenience.
*/ */
@ -1544,7 +1558,7 @@ wid_has_prop(const session_t *ps, Window w, Atom atom) {
if (Success == XGetWindowProperty(ps->dpy, w, atom, 0, 0, False, if (Success == XGetWindowProperty(ps->dpy, w, atom, 0, 0, False,
AnyPropertyType, &type, &format, &nitems, &after, &data)) { AnyPropertyType, &type, &format, &nitems, &after, &data)) {
XFree(data); cxfree(data);
if (type) return true; if (type) return true;
} }
@ -1598,7 +1612,7 @@ static inline void
free_winprop(winprop_t *pprop) { free_winprop(winprop_t *pprop) {
// Empty the whole structure to avoid possible issues // Empty the whole structure to avoid possible issues
if (pprop->data.p8) { if (pprop->data.p8) {
XFree(pprop->data.p8); cxfree(pprop->data.p8);
pprop->data.p8 = NULL; pprop->data.p8 = NULL;
} }
pprop->nitems = 0; pprop->nitems = 0;
@ -1647,7 +1661,8 @@ glx_tex_binded(const glx_texture_t *ptex, Pixmap pixmap) {
} }
void void
glx_set_clip(session_t *ps, XserverRegion reg); glx_set_clip(session_t *ps, XserverRegion reg,
const XRectangle * const cache_rects, const int cache_nrects);
bool bool
glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z, glx_blur_dst(session_t *ps, int dx, int dy, int width, int height, float z,

@ -614,7 +614,7 @@ wid_get_prop_adv(const session_t *ps, Window w, Atom atom, long offset,
}; };
} }
XFree(data); cxfree(data);
return (winprop_t) { return (winprop_t) {
.data.p8 = NULL, .data.p8 = NULL,
@ -658,12 +658,12 @@ win_rounded_corners(session_t *ps, win *w) {
for (i = 0; i < nrects; ++i) for (i = 0; i < nrects; ++i)
if (rects[i].width >= minwidth && rects[i].height >= minheight) { if (rects[i].width >= minwidth && rects[i].height >= minheight) {
w->rounded_corners = true; w->rounded_corners = true;
XFree(rects); cxfree(rects);
return; return;
} }
w->rounded_corners = false; w->rounded_corners = false;
XFree(rects); cxfree(rects);
} }
/** /**
@ -762,7 +762,7 @@ find_toplevel2(session_t *ps, Window wid) {
break; break;
} }
if (tchildren) XFree(tchildren); cxfree(tchildren);
wid = parent; wid = parent;
} }
@ -1026,7 +1026,7 @@ find_client_win(session_t *ps, Window w) {
break; break;
} }
XFree(children); cxfree(children);
return ret; return ret;
} }
@ -1448,7 +1448,8 @@ win_paint_win(session_t *ps, win *w, XserverRegion reg_paint) {
// Let glx_bind_pixmap() determine pixmap size, because if the user // Let glx_bind_pixmap() determine pixmap size, because if the user
// is resizing windows, the width and height we get may not be up-to-date, // is resizing windows, the width and height we get may not be up-to-date,
// causing the jittering issue M4he reported in #7. // causing the jittering issue M4he reported in #7.
if (!paint_bind_tex(ps, &w->paint, 0, 0, 0, w->pixmap_damaged)) { if (!paint_bind_tex(ps, &w->paint, 0, 0, 0,
(!ps->o.glx_no_rebind_pixmap && w->pixmap_damaged))) {
printf_errf("(%#010lx): Failed to bind texture. Expect troubles.", w->id); printf_errf("(%#010lx): Failed to bind texture. Expect troubles.", w->id);
} }
w->pixmap_damaged = false; w->pixmap_damaged = false;
@ -1665,7 +1666,7 @@ paint_all(session_t *ps, XserverRegion region, win *t) {
reg_paint = region; reg_paint = region;
} }
set_tgt_clip(ps, reg_paint); set_tgt_clip(ps, reg_paint, NULL, 0);
paint_root(ps, reg_paint); paint_root(ps, reg_paint);
// Create temporary regions for use during painting // Create temporary regions for use during painting
@ -1716,10 +1717,16 @@ paint_all(session_t *ps, XserverRegion region, win *t) {
XFixesSubtractRegion(ps->dpy, reg_paint, reg_paint, w->border_size); XFixesSubtractRegion(ps->dpy, reg_paint, reg_paint, w->border_size);
// Detect if the region is empty before painting // Detect if the region is empty before painting
if (region == reg_paint || !is_region_empty(ps, reg_paint)) { {
set_tgt_clip(ps, reg_paint); int nrects = 0;
XRectangle *rects = NULL;
if (region == reg_paint
|| !is_region_empty(ps, reg_paint, &rects, &nrects)) {
set_tgt_clip(ps, reg_paint, rects, nrects);
win_paint_shadow(ps, w, reg_paint); win_paint_shadow(ps, w, reg_paint);
}
cxfree(rects);
} }
} }
@ -1743,16 +1750,21 @@ paint_all(session_t *ps, XserverRegion region, win *t) {
reg_paint = region; reg_paint = region;
} }
if (!is_region_empty(ps, reg_paint)) { {
set_tgt_clip(ps, reg_paint); int nrects = 0;
// Blur window background XRectangle *rects = NULL;
if (w->blur_background && (WMODE_SOLID != w->mode if (!is_region_empty(ps, reg_paint, &rects, &nrects)) {
|| (ps->o.blur_background_frame && w->frame_opacity))) { set_tgt_clip(ps, reg_paint, rects, nrects);
win_blur_background(ps, w, ps->tgt_buffer, reg_paint); // Blur window background
} if (w->blur_background && (WMODE_SOLID != w->mode
|| (ps->o.blur_background_frame && w->frame_opacity))) {
win_blur_background(ps, w, ps->tgt_buffer, reg_paint);
}
// Painting the window // Painting the window
win_paint_win(ps, w, reg_paint); win_paint_win(ps, w, reg_paint);
}
cxfree(rects);
} }
} }
@ -1762,7 +1774,7 @@ paint_all(session_t *ps, XserverRegion region, win *t) {
// Do this as early as possible // Do this as early as possible
if (!ps->o.dbe) if (!ps->o.dbe)
set_tgt_clip(ps, None); set_tgt_clip(ps, None, NULL, 0);
if (ps->o.vsync) { if (ps->o.vsync) {
// Make sure all previous requests are processed to achieve best // Make sure all previous requests are processed to achieve best
@ -2751,7 +2763,7 @@ restack_win(session_t *ps, win *w, Window new_above) {
printf("-> "); printf("-> ");
if (to_free) { if (to_free) {
XFree(window_name); cxfree(window_name);
window_name = NULL; window_name = NULL;
} }
} }
@ -3251,11 +3263,11 @@ wid_get_text_prop(session_t *ps, Window wid, Atom prop,
*pnstr = 0; *pnstr = 0;
if (*pstrlst) if (*pstrlst)
XFreeStringList(*pstrlst); XFreeStringList(*pstrlst);
XFree(text_prop.value); cxfree(text_prop.value);
return false; return false;
} }
XFree(text_prop.value); cxfree(text_prop.value);
return true; return true;
} }
@ -3281,10 +3293,10 @@ wid_get_name(session_t *ps, Window wid, char **name) {
|| !nstr || !strlst) { || !nstr || !strlst) {
if (strlst) if (strlst)
XFreeStringList(strlst); XFreeStringList(strlst);
XFree(text_prop.value); cxfree(text_prop.value);
return false; return false;
} }
XFree(text_prop.value); cxfree(text_prop.value);
} }
*name = mstrcpy(strlst[0]); *name = mstrcpy(strlst[0]);
@ -3766,8 +3778,7 @@ ev_property_notify(session_t *ps, XPropertyEvent *ev) {
// Print out changed atom // Print out changed atom
char *name = XGetAtomName(ps->dpy, ev->atom); char *name = XGetAtomName(ps->dpy, ev->atom);
printf_dbg(" { atom = %s }\n", name); printf_dbg(" { atom = %s }\n", name);
if (name) cxfree(name);
XFree(name);
} }
#endif #endif
@ -3987,7 +3998,7 @@ ev_handle(session_t *ps, XEvent *ev) {
ev_name(ps, ev), ev_serial(ev), wid, window_name); ev_name(ps, ev), ev_serial(ev), wid, window_name);
if (to_free) { if (to_free) {
XFree(window_name); cxfree(window_name);
window_name = NULL; window_name = NULL;
} }
} }
@ -4228,6 +4239,10 @@ usage(void) {
" My tests on nouveau shows a 200% performance boost when only 1/4 of\n" " My tests on nouveau shows a 200% performance boost when only 1/4 of\n"
" the screen is updated. May break VSync and is not available on some\n" " the screen is updated. May break VSync and is not available on some\n"
" drivers. Overrides --glx-copy-from-front.\n" " drivers. Overrides --glx-copy-from-front.\n"
"--glx-no-rebind-pixmap\n"
" GLX backend: Avoid rebinding pixmap on window damage. Probably\n"
" could improve performance on rapid window content changes, but is\n"
" known to break things on some drivers.\n"
#undef WARNING #undef WARNING
#ifndef CONFIG_DBUS #ifndef CONFIG_DBUS
#define WARNING WARNING_DISABLED #define WARNING WARNING_DISABLED
@ -4702,6 +4717,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
{ "glx-use-copysubbuffermesa", no_argument, NULL, 295 }, { "glx-use-copysubbuffermesa", no_argument, NULL, 295 },
{ "blur-background-exclude", required_argument, NULL, 296 }, { "blur-background-exclude", required_argument, NULL, 296 },
{ "active-opacity", required_argument, NULL, 297 }, { "active-opacity", required_argument, NULL, 297 },
{ "glx-no-rebind-pixmap", no_argument, NULL, 298 },
// Must terminate with a NULL entry // Must terminate with a NULL entry
{ NULL, 0, NULL, 0 }, { NULL, 0, NULL, 0 },
}; };
@ -4759,6 +4775,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
while (-1 != while (-1 !=
(o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) { (o = getopt_long(argc, argv, shortopts, longopts, &longopt_idx))) {
switch (o) { switch (o) {
#define P_CASEBOOL(idx, option) case idx: ps->o.option = true; break
// Short options // Short options
case 'h': case 'h':
usage(); usage();
@ -4790,9 +4807,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
case 'F': case 'F':
fading_enable = true; fading_enable = true;
break; break;
case 'S': P_CASEBOOL('S', synchronize);
ps->o.synchronize = true;
break;
case 'r': case 'r':
ps->o.shadow_radius = atoi(optarg); ps->o.shadow_radius = atoi(optarg);
break; break;
@ -4811,17 +4826,13 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
case 'e': case 'e':
ps->o.frame_opacity = atof(optarg); ps->o.frame_opacity = atof(optarg);
break; break;
case 'z': P_CASEBOOL('z', clear_shadow);
ps->o.clear_shadow = true;
break;
case 'n': case 'n':
case 'a': case 'a':
case 's': case 's':
printf_errfq(1, "(): -n, -a, and -s have been removed."); printf_errfq(1, "(): -n, -a, and -s have been removed.");
break; break;
case 'b': P_CASEBOOL('b', fork_after_register);
ps->o.fork_after_register = true;
break;
// Long options // Long options
case 256: case 256:
// --config // --config
@ -4838,42 +4849,21 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
// --shadow-blue // --shadow-blue
ps->o.shadow_blue = atof(optarg); ps->o.shadow_blue = atof(optarg);
break; break;
case 260: P_CASEBOOL(260, inactive_opacity_override);
// --inactive-opacity-override
ps->o.inactive_opacity_override = true;
break;
case 261: case 261:
// --inactive-dim // --inactive-dim
ps->o.inactive_dim = atof(optarg); ps->o.inactive_dim = atof(optarg);
break; break;
case 262: P_CASEBOOL(262, mark_wmwin_focused);
// --mark-wmwin-focused
ps->o.mark_wmwin_focused = true;
break;
case 263: case 263:
// --shadow-exclude // --shadow-exclude
condlst_add(ps, &ps->o.shadow_blacklist, optarg); condlst_add(ps, &ps->o.shadow_blacklist, optarg);
break; break;
case 264: P_CASEBOOL(264, mark_ovredir_focused);
// --mark-ovredir-focused P_CASEBOOL(265, no_fading_openclose);
ps->o.mark_ovredir_focused = true; P_CASEBOOL(266, shadow_ignore_shaped);
break; P_CASEBOOL(267, detect_rounded_corners);
case 265: P_CASEBOOL(268, detect_client_opacity);
// --no-fading-openclose
ps->o.no_fading_openclose = true;
break;
case 266:
// --shadow-ignore-shaped
ps->o.shadow_ignore_shaped = true;
break;
case 267:
// --detect-rounded-corners
ps->o.detect_rounded_corners = true;
break;
case 268:
// --detect-client-opacity
ps->o.detect_client_opacity = true;
break;
case 269: case 269:
// --refresh-rate // --refresh-rate
ps->o.refresh_rate = atoi(optarg); ps->o.refresh_rate = atoi(optarg);
@ -4887,66 +4877,24 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
// --alpha-step // --alpha-step
ps->o.alpha_step = atof(optarg); ps->o.alpha_step = atof(optarg);
break; break;
case 272: P_CASEBOOL(272, dbe);
// --dbe P_CASEBOOL(273, paint_on_overlay);
ps->o.dbe = true; P_CASEBOOL(274, sw_opti);
break; P_CASEBOOL(275, vsync_aggressive);
case 273: P_CASEBOOL(276, use_ewmh_active_win);
// --paint-on-overlay P_CASEBOOL(277, respect_prop_shadow);
ps->o.paint_on_overlay = true; P_CASEBOOL(278, unredir_if_possible);
break;
case 274:
// --sw-opti
ps->o.sw_opti = true;
break;
case 275:
// --vsync-aggressive
ps->o.vsync_aggressive = true;
break;
case 276:
// --use-ewmh-active-win
ps->o.use_ewmh_active_win = true;
break;
case 277:
// --respect-prop-shadow
ps->o.respect_prop_shadow = true;
break;
case 278:
// --unredir-if-possible
ps->o.unredir_if_possible = true;
break;
case 279: case 279:
// --focus-exclude // --focus-exclude
condlst_add(ps, &ps->o.focus_blacklist, optarg); condlst_add(ps, &ps->o.focus_blacklist, optarg);
break; break;
case 280: P_CASEBOOL(280, inactive_dim_fixed);
// --inactive-dim-fixed P_CASEBOOL(281, detect_transient);
ps->o.inactive_dim_fixed = true; P_CASEBOOL(282, detect_client_leader);
break; P_CASEBOOL(283, blur_background);
case 281: P_CASEBOOL(284, blur_background_frame);
// --detect-transient P_CASEBOOL(285, blur_background_fixed);
ps->o.detect_transient = true; P_CASEBOOL(286, dbus);
break;
case 282:
// --detect-client-leader
ps->o.detect_client_leader = true;
break;
case 283:
// --blur-background
ps->o.blur_background = true;
break;
case 284:
// --blur-background-frame
ps->o.blur_background_frame = true;
break;
case 285:
// --blur-background-fixed
ps->o.blur_background_fixed = true;
break;
case 286:
// --dbus
ps->o.dbus = true;
break;
case 287: case 287:
// --logpath // --logpath
ps->o.logpath = mstrcpy(optarg); ps->o.logpath = mstrcpy(optarg);
@ -4964,14 +4912,8 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
if (!parse_backend(ps, optarg)) if (!parse_backend(ps, optarg))
exit(1); exit(1);
break; break;
case 291: P_CASEBOOL(291, glx_no_stencil);
// --glx-no-stencil P_CASEBOOL(292, glx_copy_from_front);
ps->o.glx_no_stencil = true;
break;
case 292:
// --glx-copy-from-front
ps->o.glx_copy_from_front = true;
break;
case 293: case 293:
// --benchmark // --benchmark
ps->o.benchmark = atoi(optarg); ps->o.benchmark = atoi(optarg);
@ -4980,10 +4922,7 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
// --benchmark-wid // --benchmark-wid
ps->o.benchmark_wid = strtol(optarg, NULL, 0); ps->o.benchmark_wid = strtol(optarg, NULL, 0);
break; break;
case 295: P_CASEBOOL(295, glx_use_copysubbuffermesa);
// --glx-use-copysubbuffermesa
ps->o.glx_use_copysubbuffermesa = true;
break;
case 296: case 296:
// --blur-background-exclude // --blur-background-exclude
condlst_add(ps, &ps->o.blur_background_blacklist, optarg); condlst_add(ps, &ps->o.blur_background_blacklist, optarg);
@ -4992,9 +4931,11 @@ get_cfg(session_t *ps, int argc, char *const *argv, bool first_pass) {
// --active-opacity // --active-opacity
ps->o.active_opacity = (normalize_d(atof(optarg)) * OPAQUE); ps->o.active_opacity = (normalize_d(atof(optarg)) * OPAQUE);
break; break;
P_CASEBOOL(298, glx_no_rebind_pixmap);
default: default:
usage(); usage();
break; break;
#undef P_CASEBOOL
} }
} }
@ -5492,7 +5433,7 @@ init_filters(session_t *ps) {
ps->xrfilter_convolution_exists = true; ps->xrfilter_convolution_exists = true;
} }
} }
XFree(pf); cxfree(pf);
// Turn features off if any required filter is not present // Turn features off if any required filter is not present
if (!ps->xrfilter_convolution_exists) { if (!ps->xrfilter_convolution_exists) {
@ -6195,7 +6136,7 @@ session_init(session_t *ps_old, int argc, char **argv) {
add_win(ps, children[i], i ? children[i-1] : None); add_win(ps, children[i], i ? children[i-1] : None);
} }
XFree(children); cxfree(children);
} }
@ -6445,7 +6386,7 @@ session_run(session_t *ps) {
if (!ps->redirected) if (!ps->redirected)
free_region(ps, &ps->all_damage); free_region(ps, &ps->all_damage);
if (ps->all_damage && !is_region_empty(ps, ps->all_damage)) { if (ps->all_damage && !is_region_empty(ps, ps->all_damage, NULL, NULL)) {
static int paint = 0; static int paint = 0;
paint_all(ps, ps->all_damage, t); paint_all(ps, ps->all_damage, t);
ps->reg_ignore_expire = false; ps->reg_ignore_expire = false;

@ -269,8 +269,7 @@ make_text_prop(session_t *ps, char *str) {
printf_errfq(1, "(): Failed to allocate memory."); printf_errfq(1, "(): Failed to allocate memory.");
if (XmbTextListToTextProperty(ps->dpy, &str, 1, XStringStyle, pprop)) { if (XmbTextListToTextProperty(ps->dpy, &str, 1, XStringStyle, pprop)) {
if (pprop->value) cxfree(pprop->value);
XFree(pprop->value);
free(pprop); free(pprop);
pprop = NULL; pprop = NULL;
} }
@ -547,14 +546,15 @@ win_render(session_t *ps, win *w, int x, int y, int wid, int hei, double opacity
} }
static inline void static inline void
set_tgt_clip(session_t *ps, XserverRegion reg) { set_tgt_clip(session_t *ps, XserverRegion reg,
const XRectangle * const cache_rects, const int cache_nrects) {
switch (ps->o.backend) { switch (ps->o.backend) {
case BKEND_XRENDER: case BKEND_XRENDER:
XFixesSetPictureClipRegion(ps->dpy, ps->tgt_buffer, 0, 0, reg); XFixesSetPictureClipRegion(ps->dpy, ps->tgt_buffer, 0, 0, reg);
break; break;
#ifdef CONFIG_VSYNC_OPENGL #ifdef CONFIG_VSYNC_OPENGL
case BKEND_GLX: case BKEND_GLX:
glx_set_clip(ps, reg); glx_set_clip(ps, reg, cache_rects, cache_nrects);
break; break;
#endif #endif
} }
@ -854,7 +854,7 @@ dump_region(const session_t *ps, XserverRegion region) {
printf("Rect #%d: %8d, %8d, %8d, %8d\n", i, rects[i].x, rects[i].y, printf("Rect #%d: %8d, %8d, %8d, %8d\n", i, rects[i].x, rects[i].y,
rects[i].width, rects[i].height); rects[i].width, rects[i].height);
XFree(rects); cxfree(rects);
} }
/** /**
@ -865,13 +865,22 @@ dump_region(const session_t *ps, XserverRegion region) {
* *
* @param ps current session * @param ps current session
* @param region region to check for * @param region region to check for
* @param pcache_rects a place to cache the dumped rectangles
* @param ncache_nrects a place to cache the number of dumped rectangles
*/ */
static inline bool static inline bool
is_region_empty(const session_t *ps, XserverRegion region) { is_region_empty(const session_t *ps, XserverRegion region,
XRectangle **pcache_rects, int *pcache_nrects) {
int nrects = 0; int nrects = 0;
XRectangle *rects = XFixesFetchRegion(ps->dpy, region, &nrects); XRectangle *rects = XFixesFetchRegion(ps->dpy, region, &nrects);
XFree(rects); if (pcache_rects)
*pcache_rects = rects;
else
cxfree(rects);
if (pcache_nrects)
*pcache_nrects = nrects;
return !nrects; return !nrects;
} }

@ -135,8 +135,7 @@ glx_init(session_t *ps, bool need_render) {
success = true; success = true;
glx_init_end: glx_init_end:
if (pvis) cxfree(pvis);
XFree(pvis);
if (!success) if (!success)
glx_destroy(ps); glx_destroy(ps);
@ -324,8 +323,7 @@ glx_update_fbconfig(session_t *ps) {
} }
} }
if (pfbcfgs) cxfree(pfbcfgs);
XFree(pfbcfgs);
// Sanity checks // Sanity checks
if (!ps->glx_fbconfigs[ps->depth]) { if (!ps->glx_fbconfigs[ps->depth]) {
@ -564,7 +562,7 @@ glx_paint_pre(session_t *ps, XserverRegion *preg) {
{ {
XserverRegion reg_copy = XFixesCreateRegion(ps->dpy, NULL, 0); XserverRegion reg_copy = XFixesCreateRegion(ps->dpy, NULL, 0);
XFixesSubtractRegion(ps->dpy, reg_copy, ps->screen_reg, *preg); XFixesSubtractRegion(ps->dpy, reg_copy, ps->screen_reg, *preg);
glx_set_clip(ps, reg_copy); glx_set_clip(ps, reg_copy, NULL, 0);
free_region(ps, &reg_copy); free_region(ps, &reg_copy);
} }
@ -579,14 +577,15 @@ glx_paint_pre(session_t *ps, XserverRegion *preg) {
} }
} }
glx_set_clip(ps, *preg); glx_set_clip(ps, *preg, NULL, 0);
} }
/** /**
* Set clipping region on the target window. * Set clipping region on the target window.
*/ */
void void
glx_set_clip(session_t *ps, XserverRegion reg) { glx_set_clip(session_t *ps, XserverRegion reg,
const XRectangle * const cache_rects, const int cache_nrects) {
// Quit if we aren't using stencils // Quit if we aren't using stencils
if (ps->o.glx_no_stencil) if (ps->o.glx_no_stencil)
return; return;
@ -601,10 +600,16 @@ glx_set_clip(session_t *ps, XserverRegion reg) {
if (!reg) if (!reg)
return; return;
int nrects = 0; int nrects = cache_nrects;
XRectangle *rects = XFixesFetchRegion(ps->dpy, reg, &nrects); XRectangle *rects_free = NULL;
const XRectangle *rects = cache_rects;
if (!rects) {
nrects = 0;
rects = rects_free = XFixesFetchRegion(ps->dpy, reg, &nrects);
}
if (!nrects) { if (!nrects) {
if (rects) XFree(rects); cxfree(rects_free);
rects_free = NULL;
nrects = 1; nrects = 1;
rects = &rect_blank; rects = &rect_blank;
} }
@ -649,8 +654,7 @@ glx_set_clip(session_t *ps, XserverRegion reg) {
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
} }
if (rects && &rect_blank != rects) cxfree(rects_free);
XFree(rects);
} }
bool bool
@ -954,7 +958,7 @@ glx_render(session_t *ps, const glx_texture_t *ptex,
glEnd(); glEnd();
if (rects && rects != &rec_all) if (rects && rects != &rec_all)
XFree(rects); cxfree(rects);
free_region(ps, &reg_new); free_region(ps, &reg_new);
} }
@ -989,7 +993,7 @@ glx_swap_copysubbuffermesa(session_t *ps, XserverRegion reg) {
glXSwapBuffers(ps->dpy, get_tgt_window(ps)); glXSwapBuffers(ps->dpy, get_tgt_window(ps));
} }
else { else {
glx_set_clip(ps, None); glx_set_clip(ps, None, NULL, 0);
for (int i = 0; i < nrects; ++i) { for (int i = 0; i < nrects; ++i) {
const int x = rects[i].x; const int x = rects[i].x;
const int y = ps->root_height - rects[i].y - rects[i].height; const int y = ps->root_height - rects[i].y - rects[i].height;
@ -1003,8 +1007,7 @@ glx_swap_copysubbuffermesa(session_t *ps, XserverRegion reg) {
} }
} }
if (rects) cxfree(rects);
XFree(rects);
} }
#ifdef CONFIG_VSYNC_OPENGL_GLSL #ifdef CONFIG_VSYNC_OPENGL_GLSL

Loading…
Cancel
Save