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>
bb10
Tor Arne Vestbø 2017-07-11 17:27:36 +02:00
parent f8c42ea891
commit 97d471c99f
2 changed files with 9 additions and 20 deletions

View File

@ -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 &region, int dx, int dy)
void QRasterBackingStore::beginPaint(const QRegion &region)
{
// 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 &region)
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

View File

@ -73,6 +73,7 @@ protected:
virtual QImage::Format format() const;
QImage m_image;
QSize m_requestedSize;
};
QT_END_NAMESPACE