From ad3dc5d2333860272618274e65700e39fc6beaf6 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 3 Feb 2019 15:14:14 +0000 Subject: [PATCH] Move session_t::pictfmts into x.c As a global variable, since they shouldn't change during the period compton is running. Also limit the scope of the variable to x.c. Signed-off-by: Yuxuan Shui --- src/common.h | 2 -- src/compton.c | 1 - src/x.c | 28 +++++++++++++++------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/common.h b/src/common.h index 56ee25bb..1c98de5e 100644 --- a/src/common.h +++ b/src/common.h @@ -356,8 +356,6 @@ typedef struct session { xcb_connection_t *c; /// Default visual. xcb_visualid_t vis; - /// Pict formats info - xcb_render_query_pict_formats_reply_t *pictfmts; /// Default depth. int depth; /// Root window. diff --git a/src/compton.c b/src/compton.c index 42c957fe..2dcb6444 100644 --- a/src/compton.c +++ b/src/compton.c @@ -3161,7 +3161,6 @@ session_destroy(session_t *ps) { } free(ps->o.glx_fshader_win_str); free_xinerama_info(ps); - free(ps->pictfmts); deinit_render(ps); diff --git a/src/x.c b/src/x.c index 1d9a7e98..d089b26a 100644 --- a/src/x.c +++ b/src/x.c @@ -111,27 +111,30 @@ bool wid_get_text_prop(session_t *ps, xcb_window_t wid, xcb_atom_t prop, return true; } -static inline void x_get_server_pictfmts(session_t *ps) { - if (ps->pictfmts) +// A cache of pict formats. We assume they don't change during the lifetime +// of compton +static thread_local xcb_render_query_pict_formats_reply_t *g_pictfmts = NULL; + +static inline void x_get_server_pictfmts(xcb_connection_t *c) { + if (g_pictfmts) return; xcb_generic_error_t *e = NULL; // Get window picture format - ps->pictfmts = - xcb_render_query_pict_formats_reply(ps->c, - xcb_render_query_pict_formats(ps->c), &e); - if (e || !ps->pictfmts) { + g_pictfmts = + xcb_render_query_pict_formats_reply(c, + xcb_render_query_pict_formats(c), &e); + if (e || !g_pictfmts) { log_fatal("failed to get pict formats\n"); abort(); } } xcb_render_pictforminfo_t *x_get_pictform_for_visual(session_t *ps, xcb_visualid_t visual) { - if (!ps->pictfmts) - x_get_server_pictfmts(ps); + x_get_server_pictfmts(ps->c); - xcb_render_pictvisual_t *pv = xcb_render_util_find_visual_format(ps->pictfmts, visual); + xcb_render_pictvisual_t *pv = xcb_render_util_find_visual_format(g_pictfmts, visual); for(xcb_render_pictforminfo_iterator_t i = - xcb_render_query_pict_formats_formats_iterator(ps->pictfmts); i.rem; + xcb_render_query_pict_formats_formats_iterator(g_pictfmts); i.rem; xcb_render_pictforminfo_next(&i)) { if (i.data->id == pv->format) { return i.data; @@ -183,11 +186,10 @@ x_create_picture_with_standard_and_pixmap( xcb_pixmap_t pixmap, unsigned long valuemask, const xcb_render_create_picture_value_list_t *attr) { - if (!ps->pictfmts) - x_get_server_pictfmts(ps); + x_get_server_pictfmts(ps->c); xcb_render_pictforminfo_t *pictfmt = - xcb_render_util_find_standard_format(ps->pictfmts, standard); + xcb_render_util_find_standard_format(g_pictfmts, standard); assert(pictfmt); return x_create_picture_with_pictfmt_and_pixmap(ps, pictfmt, pixmap, valuemask, attr); }