backends/x11: Port away from XRenderPicture

This commit is contained in:
Vlad Zahorodnii 2024-06-18 23:33:05 +03:00
parent ad31fd6b18
commit 8a5bae0f86
3 changed files with 30 additions and 4 deletions

View file

@ -8,7 +8,6 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "x11_windowed_backend.h"
#include "../common/kwinxrenderutils.h"
#include "config-kwin.h"
@ -243,8 +242,8 @@ bool X11WindowedBackend::initialize()
initXInput();
initDri3();
initRender();
XRenderUtils::init(m_connection, m_screen->root);
createOutputs();
m_pointerDevice = std::make_unique<X11WindowedInputDevice>();
@ -339,6 +338,22 @@ void X11WindowedBackend::initDri3()
}
}
void X11WindowedBackend::initRender()
{
xcb_render_query_pict_formats_cookie_t cookie = xcb_render_query_pict_formats(m_connection);
xcb_render_query_pict_formats_reply_t *reply = xcb_render_query_pict_formats_reply(m_connection, cookie, nullptr);
if (reply) {
for (xcb_render_pictforminfo_iterator_t it = xcb_render_query_pict_formats_formats_iterator(reply); it.rem; xcb_render_pictforminfo_next(&it)) {
xcb_render_pictforminfo_t *info = it.data;
if (info->depth == 32) {
m_pictureFormats.insert(info->depth, info->id);
break;
}
}
free(reply);
}
}
X11WindowedOutput *X11WindowedBackend::findOutput(xcb_window_t window) const
{
const auto it = std::ranges::find_if(m_outputs, [window](X11WindowedOutput *output) {
@ -744,6 +759,11 @@ bool X11WindowedBackend::hasXInput() const
return m_hasXInput;
}
xcb_render_pictformat_t X11WindowedBackend::pictureFormatForDepth(int depth) const
{
return m_pictureFormats.value(depth);
}
QHash<uint32_t, QList<uint64_t>> X11WindowedBackend::driFormats() const
{
return m_driFormats;

View file

@ -19,6 +19,7 @@
#include <QObject>
#include <QSize>
#include <xcb/render.h>
#include <xcb/xcb.h>
struct _XDisplay;
@ -107,6 +108,8 @@ public:
bool hasXInput() const;
xcb_render_pictformat_t pictureFormatForDepth(int depth) const;
QHash<uint32_t, QList<uint64_t>> driFormats() const;
uint32_t driFormatForDepth(int depth) const;
int driMajorVersion() const;
@ -139,6 +142,7 @@ private:
void updateSize(xcb_configure_notify_event_t *event);
void initXInput();
void initDri3();
void initRender();
X11WindowedOutput *findOutput(xcb_window_t window) const;
void destroyOutputs();
@ -178,6 +182,7 @@ private:
std::unique_ptr<EglDisplay> m_eglDisplay;
QList<X11WindowedOutput *> m_outputs;
QHash<int, xcb_render_pictformat_t> m_pictureFormats;
};
} // namespace KWin

View file

@ -9,7 +9,6 @@
#include "x11_windowed_output.h"
#include "config-kwin.h"
#include "../common/kwinxrenderutils.h"
#include "x11_windowed_backend.h"
#include "x11_windowed_logging.h"
@ -113,8 +112,10 @@ void X11WindowedCursor::update(const QImage &image, const QPointF &hotspot)
xcb_put_image(connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, img.width(), img.height(), 0, 0, 0, 32, img.sizeInBytes(), img.constBits());
XRenderPicture pic(pix, 32);
xcb_render_picture_t pic = xcb_generate_id(connection);
xcb_render_create_picture(connection, pic, pix, backend->pictureFormatForDepth(32), 0, nullptr);
xcb_render_create_cursor(connection, cid, pic, qRound(hotspot.x() * outputScale), qRound(hotspot.y() * outputScale));
xcb_render_free_picture(connection, pic);
}
xcb_change_window_attributes(connection, m_output->window(), XCB_CW_CURSOR, &cid);