From f72c2196c7b735d863a8f0f23bf1cf87c768afb2 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 12 Nov 2021 17:11:07 +0200 Subject: [PATCH] Calculate correct surface-to-buffer matrix with only upscaled viewport Currently, if a wp_viewport upscales the surface but doesn't set the source rectangle, the surface-to-buffer matrix will be calculated incorrectly. If the source rect is not set, we need to calculate the source size based on the buffer size and compare it with the destination size. If the two are not the same, add a scale transform. BUG: 445346 --- src/wayland/surface_interface.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wayland/surface_interface.cpp b/src/wayland/surface_interface.cpp index 74a6929a68..c8fdfb8601 100644 --- a/src/wayland/surface_interface.cpp +++ b/src/wayland/surface_interface.cpp @@ -434,8 +434,17 @@ QMatrix4x4 SurfaceInterfacePrivate::buildSurfaceToBufferMatrix() if (current.viewport.sourceGeometry.isValid()) { surfaceToBufferMatrix.translate(current.viewport.sourceGeometry.x(), current.viewport.sourceGeometry.y()); - surfaceToBufferMatrix.scale(current.viewport.sourceGeometry.width() / surfaceSize.width(), - current.viewport.sourceGeometry.height() / surfaceSize.height()); + } + + QSizeF sourceSize; + if (current.viewport.sourceGeometry.isValid()) { + sourceSize = current.viewport.sourceGeometry.size(); + } else { + sourceSize = bufferSize / current.bufferScale; + } + + if (sourceSize != surfaceSize) { + surfaceToBufferMatrix.scale(sourceSize.width() / surfaceSize.width(), sourceSize.height() / surfaceSize.height()); } return surfaceToBufferMatrix;