From 881664b42ee7555d7853aa732a383981c11386a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 12 Feb 2013 09:54:25 +0100 Subject: [PATCH] Port helper function createPicture to XCB Uses query_pict_formats to retrieve all formats and iterates over them to find the one matching the requested depth. Results are now cached in an QHash with the depth as key instead of an array using the depth as index. --- libkwineffects/kwinxrenderutils.cpp | 50 ++++++++++++----------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/libkwineffects/kwinxrenderutils.cpp b/libkwineffects/kwinxrenderutils.cpp index aa03cb6990..9ac5094f25 100644 --- a/libkwineffects/kwinxrenderutils.cpp +++ b/libkwineffects/kwinxrenderutils.cpp @@ -72,42 +72,34 @@ XRenderPicture xRenderBlendPicture(double opacity) return _blendPicture; } -// XRenderFind(Standard)Format() is a roundtrip, so cache the results -static XRenderPictFormat* renderformats[ 33 ]; - static xcb_render_picture_t createPicture(xcb_pixmap_t pix, int depth) { if (pix == XCB_PIXMAP_NONE) return XCB_RENDER_PICTURE_NONE; - if (renderformats[ depth ] == NULL) { - switch(depth) { - case 1: - renderformats[ 1 ] = XRenderFindStandardFormat(display(), PictStandardA1); - break; - case 8: - renderformats[ 8 ] = XRenderFindStandardFormat(display(), PictStandardA8); - break; - case 24: - renderformats[ 24 ] = XRenderFindStandardFormat(display(), PictStandardRGB24); - break; - case 32: - renderformats[ 32 ] = XRenderFindStandardFormat(display(), PictStandardARGB32); - break; - default: { - XRenderPictFormat req; - long mask = PictFormatType | PictFormatDepth; - req.type = PictTypeDirect; - req.depth = depth; - renderformats[ depth ] = XRenderFindFormat(display(), mask, &req, 0); - break; + static QHash s_renderFormats; + if (!s_renderFormats.contains(depth)) { + xcb_render_query_pict_formats_reply_t *formats = xcb_render_query_pict_formats_reply(connection(), xcb_render_query_pict_formats_unchecked(connection()), NULL); + if (!formats) { + return XCB_RENDER_PICTURE_NONE; } + for (xcb_render_pictforminfo_iterator_t it = xcb_render_query_pict_formats_formats_iterator(formats); + it.rem; + xcb_render_pictforminfo_next(&it)) { + if (it.data->depth == depth) { + s_renderFormats.insert(depth, it.data->id); + break; + } } - if (renderformats[ depth ] == NULL) { - kWarning(1212) << "Could not find XRender format for depth" << depth; - return None; - } + free(formats); } - return XRenderCreatePicture(display(), pix, renderformats[ depth ], 0, NULL); + QHash::const_iterator it = s_renderFormats.constFind(depth); + if (it == s_renderFormats.constEnd()) { + kWarning(1212) << "Could not find XRender format for depth" << depth; + return XCB_RENDER_PICTURE_NONE; + } + xcb_render_picture_t pic = xcb_generate_id(connection()); + xcb_render_create_picture(connection(), pic, pix, it.value(), 0, NULL); + return pic; } XRenderPicture::XRenderPicture(QPixmap pix)