From 5b78fcd03b63241fa0382aa196afe789740fd5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 28 Mar 2017 12:23:44 +0200 Subject: QRasterBackingStore: Correct high-dpi image size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix QT_SCALE_FACTOR usage on macOS. Follow-up to 2d2d9078 QRasterBackingStore should account for native scaling only. Any Qt scaling will have already been factored into the size argument. Change-Id: I26a67addfcbec3d45f4ed87f03b8dd79fd99cb62 Reviewed-by: Tor Arne Vestbø --- src/platformsupport/graphics/qrasterbackingstore.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/platformsupport/graphics/qrasterbackingstore.cpp b/src/platformsupport/graphics/qrasterbackingstore.cpp index ef26edc494..2f7074403c 100644 --- a/src/platformsupport/graphics/qrasterbackingstore.cpp +++ b/src/platformsupport/graphics/qrasterbackingstore.cpp @@ -42,6 +42,9 @@ #include #include +#include +#include + QT_BEGIN_NAMESPACE QRasterBackingStore::QRasterBackingStore(QWindow *window) @@ -57,14 +60,14 @@ void QRasterBackingStore::resize(const QSize &size, const QRegion &staticContent { Q_UNUSED(staticContents); - int windowDevicePixelRatio = window()->devicePixelRatio(); - QSize effectiveBufferSize = size * windowDevicePixelRatio; + qreal nativeWindowDevicePixelRatio = window()->handle()->devicePixelRatio(); + QSize effectiveBufferSize = size * nativeWindowDevicePixelRatio; if (m_image.size() == effectiveBufferSize) return; m_image = QImage(effectiveBufferSize, format()); - m_image.setDevicePixelRatio(windowDevicePixelRatio); + m_image.setDevicePixelRatio(nativeWindowDevicePixelRatio); if (m_image.format() == QImage::Format_ARGB32_Premultiplied) m_image.fill(Qt::transparent); } @@ -106,8 +109,11 @@ bool QRasterBackingStore::scroll(const QRegion ®ion, int dx, int dy) void QRasterBackingStore::beginPaint(const QRegion ®ion) { // Keep backing store device pixel ratio in sync with window - if (m_image.devicePixelRatio() != window()->devicePixelRatio()) - resize(backingStore()->size(), backingStore()->staticContents()); + qreal nativeWindowDevicePixelRatio = window()->handle()->devicePixelRatio(); + if (m_image.devicePixelRatio() != nativeWindowDevicePixelRatio) { + const QSize nativeSize = QHighDpi::toNativePixels(backingStore()->size(), window()); + resize(nativeSize, backingStore()->staticContents()); + } if (!m_image.hasAlphaChannel()) return; -- cgit v1.2.3