QBackingStore: Make QPlatformBackingStore creation lazy

Some platform backing stores may require that the window has been
created, so let's defer the platform backingstore creation until
absolutely necessary.

Change-Id: Ib93151c6473e3bbe77d994782d84289c2f63bcf2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2019-01-22 12:34:02 +01:00
parent 6c18f86af7
commit 18f415e46d

View File

@ -62,7 +62,7 @@ public:
}
QWindow *window;
QPlatformBackingStore *platformBackingStore;
QPlatformBackingStore *platformBackingStore = nullptr;
QScopedPointer<QImage> highDpiBackingstore;
QRegion staticContents;
QSize size;
@ -95,8 +95,6 @@ public:
QBackingStore::QBackingStore(QWindow *window)
: d_ptr(new QBackingStorePrivate(window))
{
d_ptr->platformBackingStore = QGuiApplicationPrivate::platformIntegration()->createPlatformBackingStore(window);
d_ptr->platformBackingStore->setBackingStore(this);
}
/*!
@ -131,7 +129,8 @@ void QBackingStore::beginPaint(const QRegion &region)
d_ptr->highDpiBackingstore->devicePixelRatio() != d_ptr->window->devicePixelRatio())
resize(size());
d_ptr->platformBackingStore->beginPaint(QHighDpi::toNativeLocalRegion(region, d_ptr->window));
QPlatformBackingStore *platformBackingStore = handle();
platformBackingStore->beginPaint(QHighDpi::toNativeLocalRegion(region, d_ptr->window));
// When QtGui is applying a high-dpi scale factor the backing store
// creates a "large" backing store image. This image needs to be
@ -139,7 +138,7 @@ void QBackingStore::beginPaint(const QRegion &region)
// devicePixelRatio. Do this on a separate image instance that shares
// the image data to avoid having the new devicePixelRatio be propagated
// back to the platform plugin.
QPaintDevice *device = d_ptr->platformBackingStore->paintDevice();
QPaintDevice *device = platformBackingStore->paintDevice();
if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image) {
QImage *source = static_cast<QImage *>(device);
const bool needsNewImage = d_ptr->highDpiBackingstore.isNull()
@ -168,7 +167,7 @@ void QBackingStore::beginPaint(const QRegion &region)
*/
QPaintDevice *QBackingStore::paintDevice()
{
QPaintDevice *device = d_ptr->platformBackingStore->paintDevice();
QPaintDevice *device = handle()->paintDevice();
if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image)
return d_ptr->highDpiBackingstore.data();
@ -189,7 +188,7 @@ void QBackingStore::endPaint()
if (paintDevice()->paintingActive())
qWarning() << "QBackingStore::endPaint() called with active painter on backingstore paint device";
d_ptr->platformBackingStore->endPaint();
handle()->endPaint();
}
static bool isRasterSurface(QWindow *window)
@ -247,7 +246,7 @@ void QBackingStore::flush(const QRegion &region, QWindow *window, const QPoint &
Q_ASSERT(window == topLevelWindow || topLevelWindow->isAncestorOf(window, QWindow::ExcludeTransients));
d_ptr->platformBackingStore->flush(window, QHighDpi::toNativeLocalRegion(region, window),
handle()->flush(window, QHighDpi::toNativeLocalRegion(region, window),
QHighDpi::toNativeLocalPosition(offset, window));
}
@ -259,7 +258,7 @@ void QBackingStore::flush(const QRegion &region, QWindow *window, const QPoint &
void QBackingStore::resize(const QSize &size)
{
d_ptr->size = size;
d_ptr->platformBackingStore->resize(QHighDpi::toNativePixels(size, d_ptr->window), d_ptr->staticContents);
handle()->resize(QHighDpi::toNativePixels(size, d_ptr->window), d_ptr->staticContents);
}
/*!
@ -286,7 +285,7 @@ bool QBackingStore::scroll(const QRegion &area, int dx, int dy)
if (qFloor(nativeDx) != nativeDx || qFloor(nativeDy) != nativeDy)
return false;
return d_ptr->platformBackingStore->scroll(QHighDpi::toNativeLocalRegion(area, d_ptr->window),
return handle()->scroll(QHighDpi::toNativeLocalRegion(area, d_ptr->window),
nativeDx, nativeDy);
}
@ -367,6 +366,10 @@ void Q_GUI_EXPORT qt_scrollRectInImage(QImage &img, const QRect &rect, const QPo
*/
QPlatformBackingStore *QBackingStore::handle() const
{
if (!d_ptr->platformBackingStore) {
d_ptr->platformBackingStore = QGuiApplicationPrivate::platformIntegration()->createPlatformBackingStore(d_ptr->window);
d_ptr->platformBackingStore->setBackingStore(const_cast<QBackingStore*>(this));
}
return d_ptr->platformBackingStore;
}