From c5986c9e595c5804331b50cc6c469f853f99593f Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 13 Jul 2023 16:50:03 +0200 Subject: [PATCH] Implement virtual void QPlatformWindow::setBackingStore() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWidget re-uses an existing backing store. Platform windows depend on being associated to a backing store, in case they become toplevel windows. If a platform window gets deleted and re-created each time it is shown or hidden, it has to be manually associated to the re-used backing store. This patch partly reverts fbf0aeea7d3b38ced7a16fcd5c3e2e9b45536292. It removes Android specific code from QWidgetPrivate::create(), which has been added to suppress re-using backing stores in the absence of the new API. Fixes: QTBUG-97482 Change-Id: Iaa1b7652efa120ec1955914c0383e8ccd8a41429 Reviewed-by: Jan Arve Sæther (cherry picked from commit a4ca9e80658bca7dad1529f03c1b59173a6ecf62) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qplatformwindow.h | 2 ++ src/platformsupport/fbconvenience/qfbscreen.cpp | 1 + src/platformsupport/fbconvenience/qfbwindow.cpp | 10 +++++++++- src/platformsupport/fbconvenience/qfbwindow_p.h | 2 +- .../platforms/android/qandroidplatformwindow.cpp | 12 ++++++++++-- .../platforms/android/qandroidplatformwindow.h | 2 +- src/widgets/kernel/qwidget.cpp | 5 +++++ 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index b6e96a457ef..6e2d823c4ad 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -32,6 +32,7 @@ class QScreen; class QWindow; class QIcon; class QRegion; +class QPlatformBackingStore; class Q_GUI_EXPORT QPlatformWindow : public QPlatformSurface { @@ -117,6 +118,7 @@ public: virtual void requestUpdate(); bool hasPendingUpdateRequest() const; virtual void deliverUpdateRequest(); + virtual void setBackingStore(QPlatformBackingStore *) {} // Window property accessors. Platform plugins should use these // instead of accessing QWindow directly. diff --git a/src/platformsupport/fbconvenience/qfbscreen.cpp b/src/platformsupport/fbconvenience/qfbscreen.cpp index e804488005f..a5d87fec041 100644 --- a/src/platformsupport/fbconvenience/qfbscreen.cpp +++ b/src/platformsupport/fbconvenience/qfbscreen.cpp @@ -47,6 +47,7 @@ bool QFbScreen::event(QEvent *event) void QFbScreen::addWindow(QFbWindow *window) { + Q_ASSERT(window->backingStore()); mWindowStack.prepend(window); if (!mPendingBackingStores.isEmpty()) { //check if we have a backing store for this window diff --git a/src/platformsupport/fbconvenience/qfbwindow.cpp b/src/platformsupport/fbconvenience/qfbwindow.cpp index 54716cc4976..8df50a14dac 100644 --- a/src/platformsupport/fbconvenience/qfbwindow.cpp +++ b/src/platformsupport/fbconvenience/qfbwindow.cpp @@ -3,9 +3,11 @@ #include "qfbwindow_p.h" #include "qfbscreen_p.h" +#include "qfbbackingstore_p.h" #include #include +#include QT_BEGIN_NAMESPACE @@ -111,5 +113,11 @@ void QFbWindow::repaint(const QRegion ®ion) for (auto rect : region) platformScreen()->setDirty(rect.translated(topLeft)); } - +void QFbWindow::setBackingStore(QPlatformBackingStore *store) +{ + Q_ASSERT(store); + Q_ASSERT_X(dynamic_cast(store), __FUNCTION__, + "Argument is not a QFbBackingStore."); + mBackingStore = static_cast(store); +} QT_END_NAMESPACE diff --git a/src/platformsupport/fbconvenience/qfbwindow_p.h b/src/platformsupport/fbconvenience/qfbwindow_p.h index 8367a10bcef..8848e9dcf85 100644 --- a/src/platformsupport/fbconvenience/qfbwindow_p.h +++ b/src/platformsupport/fbconvenience/qfbwindow_p.h @@ -41,7 +41,7 @@ public: WId winId() const override { return mWindowId; } - void setBackingStore(QFbBackingStore *store) { mBackingStore = store; } + void setBackingStore(QPlatformBackingStore *store) override; QFbBackingStore *backingStore() const { return mBackingStore; } QFbScreen *platformScreen() const; diff --git a/src/plugins/platforms/android/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp index b1eba17d040..1bc4a04b989 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp @@ -5,9 +5,9 @@ #include "qandroidplatformwindow.h" #include "qandroidplatformopenglcontext.h" #include "qandroidplatformscreen.h" - +#include "qandroidplatformbackingstore.h" #include "androidjnimain.h" - +#include "qpa/qplatformbackingstore.h" #include #include #include @@ -169,4 +169,12 @@ void QAndroidPlatformWindow::applicationStateChanged(Qt::ApplicationState) QWindowSystemInterface::flushWindowSystemEvents(); } +void QAndroidPlatformWindow::setBackingStore(QPlatformBackingStore *store) +{ + Q_ASSERT(store); + Q_ASSERT_X(dynamic_cast(store), __FUNCTION__, + "Argument is not a QAndroidPlatformBackingStore."); + m_backingStore = static_cast(store); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/android/qandroidplatformwindow.h b/src/plugins/platforms/android/qandroidplatformwindow.h index 6fccc2e7fea..ee2771ee110 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.h +++ b/src/plugins/platforms/android/qandroidplatformwindow.h @@ -50,7 +50,7 @@ public: virtual void applicationStateChanged(Qt::ApplicationState); - void setBackingStore(QAndroidPlatformBackingStore *store) { m_backingStore = store; } + void setBackingStore(QPlatformBackingStore *store) override; QAndroidPlatformBackingStore *backingStore() const { return m_backingStore; } virtual void repaint(const QRegion &) { } diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index dda15779afe..9fc7184c58d 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1332,6 +1332,11 @@ void QWidgetPrivate::create() QBackingStore *store = q->backingStore(); usesRhiFlush = false; + // Re-use backing store, in case a new platform window was created and doesn't know about it. + // (e.g. QAndroidPlatformWindow) + if (store && q->windowHandle()) + q->windowHandle()->handle()->setBackingStore(store->handle()); + if (!store) { if (q->windowType() != Qt::Desktop) { if (q->isWindow()) {