15#include <QCoreApplication>
23static xcb_connection_t *s_connection =
nullptr;
24static xcb_window_t s_rootWindow = XCB_WINDOW_NONE;
34 s_connection =
nullptr;
35 s_rootWindow = XCB_WINDOW_NONE;
40static xcb_render_picture_t createPicture(xcb_pixmap_t pix,
int depth)
42 if (pix == XCB_PIXMAP_NONE) {
43 return XCB_RENDER_PICTURE_NONE;
45 xcb_connection_t *c = XRenderUtils::s_connection;
46 static QHash<int, xcb_render_pictformat_t> s_renderFormats;
47 if (!s_renderFormats.contains(depth)) {
48 xcb_render_query_pict_formats_reply_t *formats = xcb_render_query_pict_formats_reply(c, xcb_render_query_pict_formats_unchecked(c),
nullptr);
50 return XCB_RENDER_PICTURE_NONE;
52 for (xcb_render_pictforminfo_iterator_t it = xcb_render_query_pict_formats_formats_iterator(formats);
54 xcb_render_pictforminfo_next(&it)) {
55 if (it.data->depth == depth) {
56 s_renderFormats.insert(depth, it.data->id);
62 QHash<int, xcb_render_pictformat_t>::const_iterator it = s_renderFormats.constFind(depth);
63 if (it == s_renderFormats.constEnd()) {
64 qCWarning(LIBKWINXRENDERUTILS) <<
"Could not find XRender format for depth" << depth;
65 return XCB_RENDER_PICTURE_NONE;
67 xcb_render_picture_t pic = xcb_generate_id(c);
68 xcb_render_create_picture(c, pic, pix, it.value(), 0,
nullptr);
77void XRenderPicture::fromImage(
const QImage &img)
79 xcb_connection_t *c = XRenderUtils::s_connection;
80 const int depth = img.depth();
81 xcb_pixmap_t xpix = xcb_generate_id(c);
82 xcb_create_pixmap(c, depth, xpix, XRenderUtils::s_rootWindow, img.width(), img.height());
84 xcb_gcontext_t cid = xcb_generate_id(c);
85 xcb_create_gc(c, cid, xpix, 0,
nullptr);
86 xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, xpix, cid, img.width(), img.height(),
87 0, 0, 0, depth, img.sizeInBytes(), img.constBits());
90 d = std::make_unique<XRenderPictureData>(createPicture(xpix, depth));
91 xcb_free_pixmap(c, xpix);
101 if (picture != XCB_RENDER_PICTURE_NONE) {
103 xcb_render_free_picture(XRenderUtils::s_connection, picture);
107namespace XRenderUtils
115 reply = xcb_render_query_pict_formats_reply(s_connection,
116 xcb_render_query_pict_formats_unchecked(s_connection),
nullptr);
119 for (
auto screens = xcb_render_query_pict_formats_screens_iterator(
reply); screens.rem; xcb_render_pictscreen_next(&screens)) {
120 for (
auto depths = xcb_render_pictscreen_depths_iterator(screens.data); depths.rem; xcb_render_pictdepth_next(&depths)) {
121 const xcb_render_pictvisual_t *visuals = xcb_render_pictdepth_visuals(depths.data);
122 const int len = xcb_render_pictdepth_visuals_length(depths.data);
124 for (
int i = 0; i < len; i++) {
131 const xcb_render_pictforminfo_t *formats = xcb_render_query_pict_formats_formats(
reply);
132 const int len = xcb_render_query_pict_formats_formats_length(
reply);
134 for (
int i = 0; i < len; i++) {
135 if (formats[i].
type == XCB_RENDER_PICT_TYPE_DIRECT) {
146 xcb_render_query_pict_formats_reply_t *
reply;
148 QHash<xcb_render_pictformat_t, const xcb_render_directformat_t *>
formatInfoHash;
XRenderPicture(xcb_render_picture_t pic=XCB_RENDER_PICTURE_NONE)
void init(xcb_connection_t *connection, xcb_window_t rootWindow)
const xcb_render_directformat_t * findPictFormatInfo(xcb_render_pictformat_t format)
xcb_render_pictformat_t findPictFormat(xcb_visualid_t visual)
KWIN_EXPORT xcb_window_t rootWindow()
KWIN_EXPORT xcb_connection_t * connection()