From 1781eb50ac482d116782d0bd5332a3ad731053ac Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 13 Jul 2023 15:48:46 +0200 Subject: [PATCH] QWidget: Don't re-use backing store on Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWidget re-uses backing stores created in QWidgetPrivate::create(). The Android platform plugin creates a new platform window, when a widget becomes a toplevel window. When it is hidden, the platform window is deleted. The link between QAndroidPlatformWindow and its backing store is made in the constructor of QAndroidPlatformBackingstore. When a new QAndroidPlatformWindow is constructed and the backing store is re-used, there is no more link between platform window and platform backing store. This has lead to screen assets not being painted, when shown more than once. This patch forces QWidgetPrivate::create() to construct a new backing store on Android. This way, toplevel windows always have a backing store associated with it. It adds an assertion to QAndroidPlatformScreen::addWindow(). That will make e.g. tst_QWidget::visible() crash without the fix. Fixes: QTBUG-97482 Change-Id: Ib1b172068b03549df161ab93ac24a273221d5423 Reviewed-by: Jan Arve Sæther (cherry picked from commit dbb072eb2838a04e89e34dad686394a496d5de87) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/android/qandroidplatformscreen.cpp | 3 ++- src/widgets/kernel/qwidget.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp index 54c7a34efec..6c61306d021 100644 --- a/src/plugins/platforms/android/qandroidplatformscreen.cpp +++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp @@ -43,7 +43,7 @@ public: } private: - QTime m_timer; + QElapsedTimer m_timer; QString m_msg; }; @@ -172,6 +172,7 @@ bool QAndroidPlatformScreen::event(QEvent *event) void QAndroidPlatformScreen::addWindow(QAndroidPlatformWindow *window) { + Q_ASSERT(window->backingStore()); if (window->parent() && window->isRaster()) return; diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 9fc7184c58d..38dfe2509ec 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1329,7 +1329,13 @@ void QWidgetPrivate::create() } #endif + // Android doesn't allow to re-use the backing store. + // => force creation of a new one. +#ifdef Q_OS_ANDROID + QBackingStore *store = nullptr; +#else QBackingStore *store = q->backingStore(); +#endif usesRhiFlush = false; // Re-use backing store, in case a new platform window was created and doesn't know about it.