diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-07-11 17:27:36 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-07-14 16:14:21 +0000 |
commit | 97d471c99ff43443af17c82638e7b350fb198f52 (patch) | |
tree | 3be3ddcc2a697722182e6ff2db23f165cce85f59 /src/platformsupport | |
parent | f8c42ea8913da919f221b92dc2de67058a982e1a (diff) |
Make QRasterBackingStore::resize() lazy
By deferring the image resizing until the first beginPaint after the
resize we can be sure to have a platform window, simplifying the logic.
Change-Id: I5409522563a62794b111dac7f817bc3cae6bf4e8
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/platformsupport')
-rw-r--r-- | src/platformsupport/graphics/qrasterbackingstore.cpp | 28 | ||||
-rw-r--r-- | src/platformsupport/graphics/qrasterbackingstore_p.h | 1 |
2 files changed, 9 insertions, 20 deletions
diff --git a/src/platformsupport/graphics/qrasterbackingstore.cpp b/src/platformsupport/graphics/qrasterbackingstore.cpp index b8d393844c..a3ffe11d19 100644 --- a/src/platformsupport/graphics/qrasterbackingstore.cpp +++ b/src/platformsupport/graphics/qrasterbackingstore.cpp @@ -59,20 +59,7 @@ QRasterBackingStore::~QRasterBackingStore() void QRasterBackingStore::resize(const QSize &size, const QRegion &staticContents) { Q_UNUSED(staticContents); - - // We can't guarantee that we have a platform-window at this point, so we have - // to pull out the DPR using QWindow and its QScreen fallback, and then remove - // the Qt scaling factor. - qreal nativeWindowDevicePixelRatio = window()->devicePixelRatio() / QHighDpiScaling::factor(window()); - QSize effectiveBufferSize = size * nativeWindowDevicePixelRatio; - - if (m_image.size() == effectiveBufferSize) - return; - - m_image = QImage(effectiveBufferSize, format()); - m_image.setDevicePixelRatio(nativeWindowDevicePixelRatio); - if (m_image.format() == QImage::Format_ARGB32_Premultiplied) - m_image.fill(Qt::transparent); + m_requestedSize = size; } QImage::Format QRasterBackingStore::format() const @@ -111,11 +98,13 @@ 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 qreal nativeWindowDevicePixelRatio = window()->handle()->devicePixelRatio(); - if (m_image.devicePixelRatio() != nativeWindowDevicePixelRatio) { - const QSize nativeSize = QHighDpi::toNativePixels(backingStore()->size(), window()); - resize(nativeSize, backingStore()->staticContents()); + QSize effectiveBufferSize = m_requestedSize * nativeWindowDevicePixelRatio; + if (m_image.devicePixelRatio() != nativeWindowDevicePixelRatio || m_image.size() != effectiveBufferSize) { + m_image = QImage(effectiveBufferSize, format()); + m_image.setDevicePixelRatio(nativeWindowDevicePixelRatio); + if (m_image.format() == QImage::Format_ARGB32_Premultiplied) + m_image.fill(Qt::transparent); } if (!m_image.hasAlphaChannel()) @@ -123,9 +112,8 @@ void QRasterBackingStore::beginPaint(const QRegion ®ion) QPainter painter(&m_image); painter.setCompositionMode(QPainter::CompositionMode_Source); - const QColor blank = Qt::transparent; for (const QRect &rect : region) - painter.fillRect(rect, blank); + painter.fillRect(rect, Qt::transparent); } QT_END_NAMESPACE diff --git a/src/platformsupport/graphics/qrasterbackingstore_p.h b/src/platformsupport/graphics/qrasterbackingstore_p.h index 55976d2ceb..2764fd6432 100644 --- a/src/platformsupport/graphics/qrasterbackingstore_p.h +++ b/src/platformsupport/graphics/qrasterbackingstore_p.h @@ -73,6 +73,7 @@ protected: virtual QImage::Format format() const; QImage m_image; + QSize m_requestedSize; }; QT_END_NAMESPACE |