From 26968c3802fdcd4d153b0ce7507387f45f9ac140 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 3 Apr 2025 12:33:34 +0300 Subject: [PATCH] Client: Fix copying shm buffer data with fractional scaling The QWaylandShmBackingStore computes the device pixels in the source image manually. But it does not match what the QPainter does one to one. Visually, it produces artifacts where the contents of an app is jiggling or moves back and forth by one pixel. In order to address the issue, the QWaylandShmBackingStore can copy whole buffers but with a clip region set. That way, the QPainter can consistently compute the coordinates in the device pixels. Pick-to: 6.9 Change-Id: Ib4832c4d687f43f6cc1de4a1760c32f1abd2ab03 Reviewed-by: David Edmundson --- .../platforms/wayland/qwaylandshmbackingstore.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp index 9ca2415a320..5e6a00cf600 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -364,13 +364,8 @@ bool QWaylandShmBackingStore::recreateBackBufferIfNeeded() QPainter painter(targetImage); painter.setCompositionMode(QPainter::CompositionMode_Source); - - const qreal sourceDevicePixelRatio = sourceImage->devicePixelRatio(); - for (const QRect &rect : buffer->dirtyRegion()) { - QRectF sourceRect(QPointF(rect.topLeft()) * sourceDevicePixelRatio, - QSizeF(rect.size()) * sourceDevicePixelRatio); - painter.drawImage(rect, *sourceImage, sourceRect); - } + painter.setClipRegion(buffer->dirtyRegion()); + painter.drawImage(QRectF(QPointF(), targetImage->deviceIndependentSize()), *sourceImage, sourceImage->rect()); } mBackBuffer = buffer;