From f4db3811694fe032b9fbf237b869fa842e094883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 14 Aug 2019 12:39:27 +0200 Subject: Get rid of QWidgetBackingStoreTracker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was added for Symbian almost 10 years ago (d7057e7c1f1a), for a somewhat dubious use-case. The Symbian code is since long gone (ae30d7141), so the remaining pieces are just adding complexity to the already intricate workings of the QtWidgets backingstore/painting logic. Task-number: QTBUG-8697 Change-Id: I82af610a8ac26719c588ac63f06b4501f59b400d Reviewed-by: Paul Olav Tvete (cherry picked from commit 2e0b0be2ce30394269559590b42c81de27301ee6) Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 105 ++-------------------- src/widgets/kernel/qwidget_p.h | 48 +--------- src/widgets/kernel/qwidgetbackingstore.cpp | 10 +-- src/widgets/kernel/qwidgetwindow.cpp | 2 +- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 9 +- 5 files changed, 18 insertions(+), 156 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index ba9b2a0487..066dfaa183 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -146,91 +146,6 @@ static inline bool qRectIntersects(const QRect &r1, const QRect &r2) extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp -/*! - \internal - \class QWidgetBackingStoreTracker - \brief Class which allows tracking of which widgets are using a given backing store - - QWidgetBackingStoreTracker is a thin wrapper around a QWidgetBackingStore pointer, - which maintains a list of the QWidgets which are currently using the backing - store. This list is modified via the registerWidget and unregisterWidget functions. - */ - -QWidgetBackingStoreTracker::QWidgetBackingStoreTracker() - : m_ptr(0) -{ - -} - -QWidgetBackingStoreTracker::~QWidgetBackingStoreTracker() -{ - delete m_ptr; -} - -/*! - \internal - Destroy the contained QWidgetBackingStore, if not null, and clear the list of - widgets using the backing store, then create a new QWidgetBackingStore, providing - the QWidget. - */ -void QWidgetBackingStoreTracker::create(QWidget *widget) -{ - destroy(); - m_ptr = new QWidgetBackingStore(widget); -} - -/*! - \internal - Destroy the contained QWidgetBackingStore, if not null, and clear the list of - widgets using the backing store. - */ -void QWidgetBackingStoreTracker::destroy() -{ - delete m_ptr; - m_ptr = 0; - m_widgets.clear(); -} - -/*! - \internal - Add the widget to the list of widgets currently using the backing store. - If the widget was already in the list, this function is a no-op. - */ -void QWidgetBackingStoreTracker::registerWidget(QWidget *w) -{ - Q_ASSERT(m_ptr); - Q_ASSERT(w->internalWinId()); - Q_ASSERT(qt_widget_private(w)->maybeBackingStore() == m_ptr); - m_widgets.insert(w); -} - -/*! - \internal - Remove the widget from the list of widgets currently using the backing store. - If the widget was in the list, and removing it causes the list to be empty, - the backing store is deleted. - If the widget was not in the list, this function is a no-op. - */ -void QWidgetBackingStoreTracker::unregisterWidget(QWidget *w) -{ - if (m_widgets.remove(w) && m_widgets.isEmpty()) { - delete m_ptr; - m_ptr = 0; - } -} - -/*! - \internal - Recursively remove widget and all of its descendents. - */ -void QWidgetBackingStoreTracker::unregisterWidgetSubtree(QWidget *widget) -{ - unregisterWidget(widget); - foreach (QObject *child, widget->children()) - if (QWidget *childWidget = qobject_cast(child)) - unregisterWidgetSubtree(childWidget); -} - QWidgetPrivate::QWidgetPrivate(int version) : QObjectPrivate(version) , extra(0) @@ -1364,10 +1279,8 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) d->create(); // a real toplevel window needs a backing store - if (isWindow() && windowType() != Qt::Desktop) { - d->topData()->backingStoreTracker.destroy(); - d->topData()->backingStoreTracker.create(this); - } + if (isWindow() && windowType() != Qt::Desktop) + d->topData()->widgetBackingStore.reset(new QWidgetBackingStore(this)); d->setModal_sys(); @@ -1891,7 +1804,7 @@ void QWidgetPrivate::deleteTLSysExtra() //the qplatformbackingstore may hold a reference to the window, so the backingstore //needs to be deleted first. - extra->topextra->backingStoreTracker.destroy(); + extra->topextra->widgetBackingStore.reset(nullptr); deleteBackingStore(this); #ifndef QT_NO_OPENGL extra->topextra->widgetTextures.clear(); @@ -10755,16 +10668,8 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) if (newParent && isAncestorOf(focusWidget())) focusWidget()->clearFocus(); - QTLWExtra *oldTopExtra = window()->d_func()->maybeTopData(); - QWidgetBackingStoreTracker *oldBsTracker = oldTopExtra ? &oldTopExtra->backingStoreTracker : 0; - d->setParent_sys(parent, f); - QTLWExtra *topExtra = window()->d_func()->maybeTopData(); - QWidgetBackingStoreTracker *bsTracker = topExtra ? &topExtra->backingStoreTracker : 0; - if (oldBsTracker && oldBsTracker != bsTracker) - oldBsTracker->unregisterWidgetSubtree(this); - if (desktopWidget) parent = 0; @@ -11134,7 +11039,7 @@ void QWidgetPrivate::repaint(T r) QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) - tlwExtra->backingStoreTracker->markDirty(r, q, QWidgetBackingStore::UpdateNow); + tlwExtra->widgetBackingStore->markDirty(r, q, QWidgetBackingStore::UpdateNow); } /*! @@ -11209,7 +11114,7 @@ void QWidgetPrivate::update(T r) QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) - tlwExtra->backingStoreTracker->markDirty(clipped, q); + tlwExtra->widgetBackingStore->markDirty(clipped, q); } /*! diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 970f5c0378..b4a9d283db 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -116,56 +116,12 @@ protected: QRegion m_region; }; - - -class Q_AUTOTEST_EXPORT QWidgetBackingStoreTracker -{ - -public: - QWidgetBackingStoreTracker(); - ~QWidgetBackingStoreTracker(); - - void create(QWidget *tlw); - void destroy(); - - void registerWidget(QWidget *w); - void unregisterWidget(QWidget *w); - void unregisterWidgetSubtree(QWidget *w); - - inline QWidgetBackingStore* data() - { - return m_ptr; - } - - inline QWidgetBackingStore* operator->() - { - return m_ptr; - } - - inline QWidgetBackingStore& operator*() - { - return *m_ptr; - } - - inline operator bool() const - { - return (nullptr != m_ptr); - } - -private: - Q_DISABLE_COPY_MOVE(QWidgetBackingStoreTracker) - -private: - QWidgetBackingStore* m_ptr; - QSet m_widgets; -}; - struct QTLWExtra { // *************************** Cross-platform variables ***************************** // Regular pointers (keep them together to avoid gaps on 64 bits architectures). std::unique_ptr icon; // widget icon - QWidgetBackingStoreTracker backingStoreTracker; + std::unique_ptr widgetBackingStore; QBackingStore *backingStore; QPainter *sharedPainter; QWidgetWindow *window; @@ -1028,7 +984,7 @@ inline QWidgetBackingStore *QWidgetPrivate::maybeBackingStore() const { Q_Q(const QWidget); QTLWExtra *x = q->window()->d_func()->maybeTopData(); - return x ? x->backingStoreTracker.data() : nullptr; + return x ? x->widgetBackingStore.get() : nullptr; } QT_END_NAMESPACE diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index 009ffb17a1..1b963010d1 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -300,7 +300,7 @@ void QWidgetBackingStore::unflushPaint(QWidget *widget, const QRegion &rgn) if (!tlwExtra) return; - qt_flush(widget, rgn, tlwExtra->backingStoreTracker->store, tlw, 0, tlw->d_func()->maybeBackingStore()); + qt_flush(widget, rgn, tlwExtra->widgetBackingStore->store, tlw, 0, tlw->d_func()->maybeBackingStore()); } #endif // QT_NO_PAINT_DEBUG @@ -800,7 +800,7 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) invalidateBackingStore((newRect & clipR).translated(-data.crect.topLeft())); } else { - QWidgetBackingStore *wbs = x->backingStoreTracker.data(); + QWidgetBackingStore *wbs = x->widgetBackingStore.get(); QRegion childExpose(newRect & clipR); QRegion overlappedExpose; @@ -864,7 +864,7 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy) if (x->inTopLevelResize) return; - QWidgetBackingStore *wbs = x->backingStoreTracker.data(); + QWidgetBackingStore *wbs = x->widgetBackingStore.get(); if (!wbs) return; @@ -1528,10 +1528,10 @@ void QWidgetPrivate::invalidateBackingStore(const T &r) if (masked.isEmpty()) return; - tlwExtra->backingStoreTracker->markDirty(masked, q, + tlwExtra->widgetBackingStore->markDirty(masked, q, QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid); } else { - tlwExtra->backingStoreTracker->markDirty(clipped, q, + tlwExtra->widgetBackingStore->markDirty(clipped, q, QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid); } } diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 5537ff497a..a01a377956 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -770,7 +770,7 @@ void QWidgetWindow::repaintWindow() QTLWExtra *tlwExtra = m_widget->window()->d_func()->maybeTopData(); if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) - tlwExtra->backingStoreTracker->markDirty(m_widget->rect(), m_widget, + tlwExtra->widgetBackingStore->markDirty(m_widget->rect(), m_widget, QWidgetBackingStore::UpdateNow, QWidgetBackingStore::BufferInvalid); } diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index bfc2631842..715bbbec0f 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -9564,7 +9565,7 @@ void tst_QWidget::destroyBackingStore() QTRY_VERIFY(w.numPaintEvents > 0); w.reset(); w.update(); - qt_widget_private(&w)->topData()->backingStoreTracker.create(&w); + qt_widget_private(&w)->topData()->widgetBackingStore.reset(new QWidgetBackingStore(&w)); w.update(); QApplication::processEvents(); @@ -9584,7 +9585,7 @@ QWidgetBackingStore* backingStore(QWidget &widget) QWidgetBackingStore *backingStore = nullptr; #ifdef QT_BUILD_INTERNAL if (QTLWExtra *topExtra = qt_widget_private(&widget)->maybeTopData()) - backingStore = topExtra->backingStoreTracker.data(); + backingStore = topExtra->widgetBackingStore.get(); #endif return backingStore; } @@ -9784,12 +9785,12 @@ class scrollWidgetWBS : public QWidget public: void deleteBackingStore() { - static_cast(d_ptr.data())->topData()->backingStoreTracker.destroy(); + static_cast(d_ptr.data())->topData()->widgetBackingStore.reset(nullptr); } void enableBackingStore() { if (!static_cast(d_ptr.data())->maybeBackingStore()) { - static_cast(d_ptr.data())->topData()->backingStoreTracker.create(this); + static_cast(d_ptr.data())->topData()->widgetBackingStore.reset(new QWidgetBackingStore(this)); static_cast(d_ptr.data())->invalidateBackingStore(this->rect()); repaint(); } -- cgit v1.2.3