From d8b4bef3ddff327598027c8f94a61e3d0b61a2dd Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 8 Jul 2016 14:46:34 +0200 Subject: Fix high-DPI scaling of window decorations for shared memory buffers Change-Id: I6833ab86ffdb4e37dad5108baddb7a54cfb5e9fa Reviewed-by: Giulio Camuffo --- src/client/qwaylandshmbackingstore.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/client/qwaylandshmbackingstore.cpp') diff --git a/src/client/qwaylandshmbackingstore.cpp b/src/client/qwaylandshmbackingstore.cpp index 3bbe24c3..5c93d2ba 100644 --- a/src/client/qwaylandshmbackingstore.cpp +++ b/src/client/qwaylandshmbackingstore.cpp @@ -301,29 +301,37 @@ void QWaylandShmBackingStore::updateDecorations() QPainter decorationPainter(entireSurface()); decorationPainter.setCompositionMode(QPainter::CompositionMode_Source); QImage sourceImage = windowDecoration()->contentImage(); - QRect target; + + qreal dp = sourceImage.devicePixelRatio(); + int dpWidth = int(sourceImage.width() / dp); + int dpHeight = int(sourceImage.height() / dp); + QMatrix sourceMatrix; + sourceMatrix.scale(dp, dp); + QRect target; // needs to be in device independent pixels + //Top target.setX(0); target.setY(0); - target.setWidth(sourceImage.width()); + target.setWidth(dpWidth); target.setHeight(windowDecorationMargins().top()); - decorationPainter.drawImage(target, sourceImage, target); + decorationPainter.drawImage(target, sourceImage, sourceMatrix.mapRect(target)); //Left target.setWidth(windowDecorationMargins().left()); - target.setHeight(sourceImage.height()); - decorationPainter.drawImage(target, sourceImage, target); + target.setHeight(dpHeight); + decorationPainter.drawImage(target, sourceImage, sourceMatrix.mapRect(target)); //Right - target.setX(sourceImage.width() - windowDecorationMargins().right()); - decorationPainter.drawImage(target, sourceImage, target); + target.setX(dpWidth - windowDecorationMargins().right()); + target.setWidth(windowDecorationMargins().right()); + decorationPainter.drawImage(target, sourceImage, sourceMatrix.mapRect(target)); //Bottom target.setX(0); - target.setY(sourceImage.height() - windowDecorationMargins().bottom()); - target.setWidth(sourceImage.width()); + target.setY(dpHeight - windowDecorationMargins().bottom()); + target.setWidth(dpWidth); target.setHeight(windowDecorationMargins().bottom()); - decorationPainter.drawImage(target, sourceImage, target); + decorationPainter.drawImage(target, sourceImage, sourceMatrix.mapRect(target)); } QWaylandAbstractDecoration *QWaylandShmBackingStore::windowDecoration() const -- cgit v1.2.1