Implement virtual void QPlatformWindow::setBackingStore()

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 <jan-arve.saether@qt.io>
(cherry picked from commit a4ca9e80658bca7dad1529f03c1b59173a6ecf62)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2023-07-13 16:50:03 +02:00 committed by Qt Cherry-pick Bot
parent b2004620bd
commit c5986c9e59
7 changed files with 29 additions and 5 deletions

View File

@ -32,6 +32,7 @@ class QScreen;
class QWindow; class QWindow;
class QIcon; class QIcon;
class QRegion; class QRegion;
class QPlatformBackingStore;
class Q_GUI_EXPORT QPlatformWindow : public QPlatformSurface class Q_GUI_EXPORT QPlatformWindow : public QPlatformSurface
{ {
@ -117,6 +118,7 @@ public:
virtual void requestUpdate(); virtual void requestUpdate();
bool hasPendingUpdateRequest() const; bool hasPendingUpdateRequest() const;
virtual void deliverUpdateRequest(); virtual void deliverUpdateRequest();
virtual void setBackingStore(QPlatformBackingStore *) {}
// Window property accessors. Platform plugins should use these // Window property accessors. Platform plugins should use these
// instead of accessing QWindow directly. // instead of accessing QWindow directly.

View File

@ -47,6 +47,7 @@ bool QFbScreen::event(QEvent *event)
void QFbScreen::addWindow(QFbWindow *window) void QFbScreen::addWindow(QFbWindow *window)
{ {
Q_ASSERT(window->backingStore());
mWindowStack.prepend(window); mWindowStack.prepend(window);
if (!mPendingBackingStores.isEmpty()) { if (!mPendingBackingStores.isEmpty()) {
//check if we have a backing store for this window //check if we have a backing store for this window

View File

@ -3,9 +3,11 @@
#include "qfbwindow_p.h" #include "qfbwindow_p.h"
#include "qfbscreen_p.h" #include "qfbscreen_p.h"
#include "qfbbackingstore_p.h"
#include <QtGui/QScreen> #include <QtGui/QScreen>
#include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformbackingstore.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -111,5 +113,11 @@ void QFbWindow::repaint(const QRegion &region)
for (auto rect : region) for (auto rect : region)
platformScreen()->setDirty(rect.translated(topLeft)); platformScreen()->setDirty(rect.translated(topLeft));
} }
void QFbWindow::setBackingStore(QPlatformBackingStore *store)
{
Q_ASSERT(store);
Q_ASSERT_X(dynamic_cast<QFbBackingStore *>(store), __FUNCTION__,
"Argument is not a QFbBackingStore.");
mBackingStore = static_cast<QFbBackingStore *>(store);
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -41,7 +41,7 @@ public:
WId winId() const override { return mWindowId; } WId winId() const override { return mWindowId; }
void setBackingStore(QFbBackingStore *store) { mBackingStore = store; } void setBackingStore(QPlatformBackingStore *store) override;
QFbBackingStore *backingStore() const { return mBackingStore; } QFbBackingStore *backingStore() const { return mBackingStore; }
QFbScreen *platformScreen() const; QFbScreen *platformScreen() const;

View File

@ -5,9 +5,9 @@
#include "qandroidplatformwindow.h" #include "qandroidplatformwindow.h"
#include "qandroidplatformopenglcontext.h" #include "qandroidplatformopenglcontext.h"
#include "qandroidplatformscreen.h" #include "qandroidplatformscreen.h"
#include "qandroidplatformbackingstore.h"
#include "androidjnimain.h" #include "androidjnimain.h"
#include "qpa/qplatformbackingstore.h"
#include <qguiapplication.h> #include <qguiapplication.h>
#include <qpa/qwindowsysteminterface.h> #include <qpa/qwindowsysteminterface.h>
#include <private/qhighdpiscaling_p.h> #include <private/qhighdpiscaling_p.h>
@ -169,4 +169,12 @@ void QAndroidPlatformWindow::applicationStateChanged(Qt::ApplicationState)
QWindowSystemInterface::flushWindowSystemEvents(); QWindowSystemInterface::flushWindowSystemEvents();
} }
void QAndroidPlatformWindow::setBackingStore(QPlatformBackingStore *store)
{
Q_ASSERT(store);
Q_ASSERT_X(dynamic_cast<QAndroidPlatformBackingStore *>(store), __FUNCTION__,
"Argument is not a QAndroidPlatformBackingStore.");
m_backingStore = static_cast<QAndroidPlatformBackingStore *>(store);
}
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -50,7 +50,7 @@ public:
virtual void applicationStateChanged(Qt::ApplicationState); virtual void applicationStateChanged(Qt::ApplicationState);
void setBackingStore(QAndroidPlatformBackingStore *store) { m_backingStore = store; } void setBackingStore(QPlatformBackingStore *store) override;
QAndroidPlatformBackingStore *backingStore() const { return m_backingStore; } QAndroidPlatformBackingStore *backingStore() const { return m_backingStore; }
virtual void repaint(const QRegion &) { } virtual void repaint(const QRegion &) { }

View File

@ -1332,6 +1332,11 @@ void QWidgetPrivate::create()
QBackingStore *store = q->backingStore(); QBackingStore *store = q->backingStore();
usesRhiFlush = false; 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 (!store) {
if (q->windowType() != Qt::Desktop) { if (q->windowType() != Qt::Desktop) {
if (q->isWindow()) { if (q->isWindow()) {