21 this, &SurfaceItemX11::handleBufferGeometryChanged);
23 this, &SurfaceItemX11::handleShapeChanged);
25 m_damageHandle = xcb_generate_id(kwinApp()->x11Connection());
26 xcb_damage_create(kwinApp()->x11Connection(), m_damageHandle,
window->
frameId(),
27 XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY);
57 syncManager->insertWait();
75 if (m_damageHandle == XCB_NONE) {
79 xcb_xfixes_region_t region = xcb_generate_id(kwinApp()->x11Connection());
80 xcb_xfixes_create_region(kwinApp()->x11Connection(), region, 0,
nullptr);
81 xcb_damage_subtract(kwinApp()->x11Connection(), m_damageHandle, 0, region);
83 m_damageCookie = xcb_xfixes_fetch_region_unchecked(kwinApp()->x11Connection(), region);
84 xcb_xfixes_destroy_region(kwinApp()->x11Connection(), region);
86 m_havePendingDamageRegion =
true;
93 if (!m_havePendingDamageRegion) {
96 m_havePendingDamageRegion =
false;
98 xcb_xfixes_fetch_region_reply_t *reply =
99 xcb_xfixes_fetch_region_reply(kwinApp()->x11Connection(), m_damageCookie,
nullptr);
101 qCDebug(KWIN_CORE) <<
"Failed to check damage region";
105 const int rectCount = xcb_xfixes_fetch_region_rectangles_length(reply);
108 if (rectCount > 1 && rectCount < 16) {
109 xcb_rectangle_t *rects = xcb_xfixes_fetch_region_rectangles(reply);
111 QList<QRect> qtRects;
112 qtRects.reserve(rectCount);
114 for (
int i = 0; i < rectCount; ++i) {
115 qtRects << QRect(rects[i].x, rects[i].y, rects[i].width, rects[i].height);
117 region.setRects(qtRects.constData(), rectCount);
119 region = QRect(reply->extents.x, reply->extents.y, reply->extents.width, reply->extents.height);
131 m_damageHandle = XCB_NONE;
136 if (m_damageHandle != XCB_NONE) {
138 xcb_damage_destroy(kwinApp()->x11Connection(), m_damageHandle);
139 m_damageHandle = XCB_NONE;
143void SurfaceItemX11::handleBufferGeometryChanged()
150void SurfaceItemX11::handleShapeChanged()
161 for (QRectF &shapePart :
shape) {
162 shapePart = shapePart.intersected(clipRect);
170 for (
const QRectF &shapePart :
shape()) {
171 shapeRegion += shapePart.toRect();
183 return std::make_unique<SurfacePixmapX11>(
this);
194 if (m_pixmap != XCB_PIXMAP_NONE) {
195 xcb_free_pixmap(kwinApp()->x11Connection(), m_pixmap);
201 return m_pixmap != XCB_PIXMAP_NONE;
222 xcb_connection_t *
connection = kwinApp()->x11Connection();
223 xcb_window_t frame = window->
frameId();
225 xcb_void_cookie_t namePixmapCookie = xcb_composite_name_window_pixmap_checked(
connection,
228 Xcb::WindowAttributes windowAttributes(frame);
230 if (xcb_generic_error_t *error = xcb_request_check(
connection, namePixmapCookie)) {
231 qCDebug(KWIN_CORE,
"Failed to create window pixmap for window 0x%x (error code %d)",
232 window->
window(), error->error_code);
238 if (!windowAttributes || windowAttributes->map_state != XCB_MAP_STATE_VIEWABLE) {
239 qCDebug(KWIN_CORE,
"Failed to create window pixmap for window 0x%x (not viewable)",
245 if (windowGeometry.
size() != bufferGeometry.size()) {
246 qCDebug(KWIN_CORE,
"Failed to create window pixmap for window 0x%x: window size (%fx%f) != buffer size (%fx%f)", window->
window(),
247 windowGeometry.
size().width(), windowGeometry.
size().height(), bufferGeometry.width(), bufferGeometry.height());
256 m_size = bufferGeometry.size().toSize();
261#include "moc_surfaceitem_x11.cpp"
QRectF boundingRect() const
void scheduleRepaint(const QRectF ®ion)
void setDestinationSize(const QSizeF &size)
void preprocess() override
void setBufferSize(const QSize &size)
void addDamage(const QRegion ®ion)
void setBufferSourceBox(const QRectF &box)
X11Window * window() const
QRegion opaque() const override
void preprocess() override
~SurfaceItemX11() override
std::unique_ptr< SurfacePixmap > createPixmap() override
QList< QRectF > shape() const override
SurfaceItemX11(X11Window *window, Scene *scene, Item *parent=nullptr)
~SurfacePixmapX11() override
xcb_pixmap_t pixmap() const
bool isValid() const override
xcb_visualid_t visual() const
SurfacePixmapX11(SurfaceItemX11 *item, QObject *parent=nullptr)
void bufferGeometryChanged(const QRectF &oldGeometry)
static X11Compositor * self()
xcb_visualid_t visual() const
xcb_window_t frameId() const
bool isUnmanaged() const override
xcb_window_t window() const
QList< QRectF > shapeRegion() const
QRegion opaqueRegion() const
KWIN_EXPORT xcb_connection_t * connection()