Client: Fix buffer damage

If the specified damage rectangle has fractional coordinates in the buffer
local coordinate space, the buffer damage needs to be expanded, i.e.

- bufferRect.left = floor(rect.left * scale)
- bufferRect.right = ceil(rect.right * scale) = ceil((rect.x + rect.width) * scale)

Flooring the coordinates and ceiling the size is not enough. It can
produce incorrect results.

For example, consider that a rectangle with logical coordinates of
QRect(0, 23, 179, 46) has been damaged in a window with scale 1.5. When
flooring the coordinates and ceiling the size, the following buffer
damage rect will be produced: QRect(0, 34, 269, 69). Its height is off by
1, the expected height is 70 (ceil((23 + 46) * 1.5) - floor(23 * 1.5) =
ceil(103.5) - floor(34.5) = 104 - 34 = 70).

Pick-to: 5.15 6.5 6.6
Change-Id: I927e75a2224bb58b4634125011d1305dbdfbb3aa
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Vlad Zahorodnii 2023-08-03 12:28:44 +03:00
parent 816f41c00d
commit f195fed91a

View File

@ -702,10 +702,15 @@ void QWaylandWindow::damage(const QRect &rect)
return;
const qreal s = scale();
if (mSurface->version() >= 4)
mSurface->damage_buffer(qFloor(s * rect.x()), qFloor(s * rect.y()), qCeil(s * rect.width()), qCeil(s * rect.height()));
else
if (mSurface->version() >= 4) {
const QRect bufferRect =
QRectF(s * rect.x(), s * rect.y(), s * rect.width(), s * rect.height())
.toAlignedRect();
mSurface->damage_buffer(bufferRect.x(), bufferRect.y(), bufferRect.width(),
bufferRect.height());
} else {
mSurface->damage(rect.x(), rect.y(), rect.width(), rect.height());
}
}
void QWaylandWindow::safeCommit(QWaylandBuffer *buffer, const QRegion &damage)
@ -747,8 +752,13 @@ void QWaylandWindow::commit(QWaylandBuffer *buffer, const QRegion &damage)
attachOffset(buffer);
if (mSurface->version() >= 4) {
const qreal s = scale();
for (const QRect &rect: damage)
mSurface->damage_buffer(qFloor(s * rect.x()), qFloor(s * rect.y()), qCeil(s * rect.width()), qCeil(s * rect.height()));
for (const QRect &rect : damage) {
const QRect bufferRect =
QRectF(s * rect.x(), s * rect.y(), s * rect.width(), s * rect.height())
.toAlignedRect();
mSurface->damage_buffer(bufferRect.x(), bufferRect.y(), bufferRect.width(),
bufferRect.height());
}
} else {
for (const QRect &rect: damage)
mSurface->damage(rect.x(), rect.y(), rect.width(), rect.height());