From 94d7603d5114eacaf648e0b0d2dcae5e161e0217 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 22:06:09 +0200 Subject: QWidget: replace manual memory management with unique_ptr [1/N]: widgetTextures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a vector (QVector cannot hold move-only classes), adapt to different API. Change-Id: Iece4b1bfcb35a02aac05935963e1e7f8c986b18d Reviewed-by: Mårten Nordheim --- src/widgets/kernel/qwidget.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index cdea0a570c..c63bf26b26 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1902,7 +1902,6 @@ void QWidgetPrivate::deleteTLSysExtra() extra->topextra->backingStoreTracker.destroy(); deleteBackingStore(this); #ifndef QT_NO_OPENGL - qDeleteAll(extra->topextra->widgetTextures); extra->topextra->widgetTextures.clear(); delete extra->topextra->shareContext; extra->topextra->shareContext = 0; -- cgit v1.2.3 From d473f216b9a34a0e6272533dc11e885eebfe4191 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 22:06:09 +0200 Subject: QWidget: replace manual memory management with unique_ptr [2/N]: topextra->icon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I wonder whether a QIcon could be aggregated here by value, as it has a null state and its default ctor sets d = nullptr. Change-Id: I7a0f46e9fdd51a93afb5db768d46d93b08f307ec Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- src/widgets/kernel/qwidget.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index c63bf26b26..68ce8d5d15 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -121,6 +121,8 @@ #include +#include + // widget/widget data creation count //#define QWIDGET_EXTRA_DEBUG //#define ALIEN_DEBUG @@ -1784,7 +1786,6 @@ void QWidgetPrivate::createTLExtra() createExtra(); if (!extra->topextra) { QTLWExtra* x = extra->topextra = new QTLWExtra; - x->icon = 0; x->backingStore = 0; x->sharedPainter = 0; x->incw = x->inch = 0; @@ -1872,7 +1873,6 @@ void QWidgetPrivate::deleteExtra() if (extra->topextra) { deleteTLSysExtra(); // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra() - delete extra->topextra->icon; delete extra->topextra; } delete extra; @@ -6265,8 +6265,9 @@ void QWidget::setWindowIcon(const QIcon &icon) d->createTLExtra(); if (!d->extra->topextra->icon) - d->extra->topextra->icon = new QIcon(); - *d->extra->topextra->icon = icon; + d->extra->topextra->icon = qt_make_unique(icon); + else + *d->extra->topextra->icon = icon; d->setWindowIcon_sys(); d->setWindowIcon_helper(); -- cgit v1.2.3 From 19ccbdabfe889fccd67ab162bbb144846ab098fb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 22:06:09 +0200 Subject: QWidget: replace manual memory management with unique_ptr [3/N]: topextra->shareContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Despite the name, it's fully owned by an individual QWidget object. Also make the member mutable, so we can remove the const_cast hack in QWidgetPrivate::shareContext(), and protect QT_NO_OPENGL builds, since the naked pointer compiled by chance due to some unguarded forward declarations while a unique_ptr will somewhere want to call the dtor, which doesn't compile on an object of merely forward-declared type. Change-Id: If8027b55d303822236fcdc1a79e4f3010967b4d2 Reviewed-by: Mårten Nordheim --- src/widgets/kernel/qwidget.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 68ce8d5d15..78a8af62df 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1799,7 +1799,6 @@ void QWidgetPrivate::createTLExtra() x->inTopLevelResize = false; x->embedded = 0; x->window = 0; - x->shareContext = 0; x->initialScreenIndex = -1; #if 0 // Used to be included in Qt4 for Q_WS_MAC x->wasMaximized = false; @@ -1903,8 +1902,7 @@ void QWidgetPrivate::deleteTLSysExtra() deleteBackingStore(this); #ifndef QT_NO_OPENGL extra->topextra->widgetTextures.clear(); - delete extra->topextra->shareContext; - extra->topextra->shareContext = 0; + extra->topextra->shareContext.reset(); #endif //the toplevel might have a context with a "qglcontext associated with it. We need to @@ -12413,16 +12411,15 @@ QOpenGLContext *QWidgetPrivate::shareContext() const if (Q_UNLIKELY(!extra || !extra->topextra || !extra->topextra->window)) return 0; - QWidgetPrivate *that = const_cast(this); if (!extra->topextra->shareContext) { - QOpenGLContext *ctx = new QOpenGLContext; + auto ctx = qt_make_unique(); ctx->setShareContext(qt_gl_global_share_context()); ctx->setFormat(extra->topextra->window->format()); ctx->setScreen(extra->topextra->window->screen()); ctx->create(); - that->extra->topextra->shareContext = ctx; + extra->topextra->shareContext = std::move(ctx); } - return that->extra->topextra->shareContext; + return extra->topextra->shareContext.get(); #endif // QT_NO_OPENGL } -- cgit v1.2.3 From 45c5cc619933d1283da27a15d5d7ab3d2e8e5329 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 22:06:09 +0200 Subject: QWidget: replace manual memory management with unique_ptr [4/N]: extra->curs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id65ead5563321b8edbe0055ad1531c2442d4d597 Reviewed-by: Friedemann Kleint Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- src/widgets/kernel/qwidget.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 78a8af62df..aa93ee6be2 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1823,9 +1823,6 @@ void QWidgetPrivate::createExtra() extra->topextra = 0; #if QT_CONFIG(graphicsview) extra->proxyWidget = 0; -#endif -#ifndef QT_NO_CURSOR - extra->curs = 0; #endif extra->minw = 0; extra->minh = 0; @@ -1860,9 +1857,6 @@ void QWidgetPrivate::createSysExtra() void QWidgetPrivate::deleteExtra() { if (extra) { // if exists -#ifndef QT_NO_CURSOR - delete extra->curs; -#endif deleteSysExtra(); #ifndef QT_NO_STYLE_STYLESHEET // dereference the stylesheet style @@ -5019,9 +5013,7 @@ void QWidget::setCursor(const QCursor &cursor) #endif { d->createExtra(); - QCursor *newCursor = new QCursor(cursor); - delete d->extra->curs; - d->extra->curs = newCursor; + d->extra->curs = qt_make_unique(cursor); } setAttribute(Qt::WA_SetCursor); d->setCursor_sys(cursor); @@ -5040,10 +5032,8 @@ void QWidgetPrivate::setCursor_sys(const QCursor &cursor) void QWidget::unsetCursor() { Q_D(QWidget); - if (d->extra) { - delete d->extra->curs; - d->extra->curs = 0; - } + if (d->extra) + d->extra->curs.reset(); if (!isWindow()) setAttribute(Qt::WA_SetCursor, false); d->unsetCursor_sys(); -- cgit v1.2.3 From 70c624d93ee040e8aa4ab576be008f07bbfb8a2e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 22:06:09 +0200 Subject: QWidget: replace manual memory management with unique_ptr [5/N]: extra->topextra MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is a bit frustrating that all the initialization and cleanup code are not in the QTLWExtra ctor and dtor. But that is for another patch. Change-Id: I0e45f89c1a53eb2f9a5699d3fbbef1a628b55432 Reviewed-by: Friedemann Kleint Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- src/widgets/kernel/qwidget.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index aa93ee6be2..ba9b2a0487 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1785,7 +1785,8 @@ void QWidgetPrivate::createTLExtra() if (!extra) createExtra(); if (!extra->topextra) { - QTLWExtra* x = extra->topextra = new QTLWExtra; + extra->topextra = qt_make_unique(); + QTLWExtra* x = extra->topextra.get(); x->backingStore = 0; x->sharedPainter = 0; x->incw = x->inch = 0; @@ -1820,7 +1821,6 @@ void QWidgetPrivate::createExtra() if (!extra) { // if not exists extra = new QWExtra; extra->glContext = 0; - extra->topextra = 0; #if QT_CONFIG(graphicsview) extra->proxyWidget = 0; #endif @@ -1866,7 +1866,6 @@ void QWidgetPrivate::deleteExtra() if (extra->topextra) { deleteTLSysExtra(); // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra() - delete extra->topextra; } delete extra; // extra->xic destroyed in QWidget::destroy() -- cgit v1.2.3 From 2e0b0be2ce30394269559590b42c81de27301ee6 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 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 --- src/widgets/kernel/qwidget.cpp | 105 ++--------------------------------------- 1 file changed, 5 insertions(+), 100 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') 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); } /*! -- cgit v1.2.3 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 ++--------------------------------------- 1 file changed, 5 insertions(+), 100 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') 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); } /*! -- cgit v1.2.3 From 6d9d4e6817b116676320a1aba0ea0af1633205bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 14 Aug 2019 14:07:55 +0200 Subject: Rename QWidgetBackingStore to QWidgetRepaintManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quoting a blog from 2009, "this class is responsible for figuring out which parts of the window surface needs to be updated prior to showing it to screen, so it's really a repaint manager." https://blog.qt.io/blog/2009/12/16/qt-graphics-and-performance-an-overview/ What better time to do the rename than 10 years later! Change-Id: Ibf3c3bc8c7df64ac03d72e1f71d296b62d832fee Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 97 +++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 49 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 066dfaa183..d1ad0c0a01 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -90,7 +90,7 @@ #include #endif #include -#include +#include #if 0 // Used to be included in Qt4 for Q_WS_MAC # include #endif @@ -869,11 +869,11 @@ QRegion qt_dirtyRegion(QWidget *widget) if (!widget) return QRegion(); - QWidgetBackingStore *bs = qt_widget_private(widget)->maybeBackingStore(); - if (!bs) + QWidgetRepaintManager *repaintManager = qt_widget_private(widget)->maybeRepaintManager(); + if (!repaintManager) return QRegion(); - return bs->dirtyRegion(widget); + return repaintManager->dirtyRegion(widget); } /***************************************************************************** @@ -1278,9 +1278,9 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) setAttribute(Qt::WA_WState_Created); // set created flag d->create(); - // a real toplevel window needs a backing store + // A real toplevel window needs a paint manager if (isWindow() && windowType() != Qt::Desktop) - d->topData()->widgetBackingStore.reset(new QWidgetBackingStore(this)); + d->topData()->repaintManager.reset(new QWidgetRepaintManager(this)); d->setModal_sys(); @@ -1585,10 +1585,10 @@ QWidget::~QWidget() qApp->d_func()->sendSyntheticEnterLeave(this); } - if (QWidgetBackingStore *bs = d->maybeBackingStore()) { - bs->removeDirtyWidget(this); + if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) { + repaintManager->removeDirtyWidget(this); if (testAttribute(Qt::WA_StaticContents)) - bs->removeStaticWidget(this); + repaintManager->removeStaticWidget(this); } delete d->needsFlush; @@ -1804,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->widgetBackingStore.reset(nullptr); + extra->topextra->repaintManager.reset(nullptr); deleteBackingStore(this); #ifndef QT_NO_OPENGL extra->topextra->widgetTextures.clear(); @@ -1875,8 +1875,8 @@ void QWidgetPrivate::syncBackingStore() if (paintOnScreen()) { repaint_sys(dirty); dirty = QRegion(); - } else if (QWidgetBackingStore *bs = maybeBackingStore()) { - bs->sync(); + } else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) { + repaintManager->sync(); } } @@ -1884,8 +1884,8 @@ void QWidgetPrivate::syncBackingStore(const QRegion ®ion) { if (paintOnScreen()) repaint_sys(region); - else if (QWidgetBackingStore *bs = maybeBackingStore()) { - bs->sync(q_func(), region); + else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) { + repaintManager->sync(q_func(), region); } } @@ -5411,7 +5411,7 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset } void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, - QPainter *sharedPainter, QWidgetBackingStore *backingStore) + QPainter *sharedPainter, QWidgetRepaintManager *repaintManager) { if (rgn.isEmpty()) return; @@ -5426,7 +5426,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP QWidgetEffectSourcePrivate *sourced = static_cast (source->d_func()); if (!sourced->context) { - QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore); + QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, repaintManager); sourced->context = &context; if (!sharedPainter) { setSystemClip(pdev->paintEngine(), pdev->devicePixelRatioF(), rgn.translated(offset)); @@ -5452,8 +5452,8 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP // Native widgets need to be marked dirty on screen so painting will be done in correct context // Same check as in the no effects case below. - if (backingStore && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) - backingStore->markDirtyOnScreen(rgn, q, offset); + if (repaintManager && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) + repaintManager->markDirtyOnScreen(rgn, q, offset); return; } @@ -5481,7 +5481,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP //clip away the new area #ifndef QT_NO_PAINT_DEBUG - bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted); + bool flushed = QWidgetRepaintManager::flushPaint(q, toBePainted); #endif QPaintEngine *paintEngine = pdev->paintEngine(); if (paintEngine) { @@ -5543,11 +5543,11 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP // This widget renders into a texture which is composed later. We just need to // punch a hole in the backingstore, so the texture will be visible. beginBackingStorePainting(); - if (!q->testAttribute(Qt::WA_AlwaysStackOnTop) && backingStore) { + if (!q->testAttribute(Qt::WA_AlwaysStackOnTop) && repaintManager) { QPainter p(q); p.setCompositionMode(QPainter::CompositionMode_Source); p.fillRect(q->rect(), Qt::transparent); - } else if (!backingStore) { + } else if (!repaintManager) { // We are not drawing to a backingstore: fall back to QImage QImage img = grabFramebuffer(); // grabFramebuffer() always sets the format to RGB32 @@ -5572,8 +5572,8 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP } // Native widgets need to be marked dirty on screen so painting will be done in correct context - if (backingStore && !onScreen && !asRoot && (q->internalWinId() || (q->nativeParentWidget() && !q->nativeParentWidget()->isWindow()))) - backingStore->markDirtyOnScreen(toBePainted, q, offset); + if (repaintManager && !onScreen && !asRoot && (q->internalWinId() || (q->nativeParentWidget() && !q->nativeParentWidget()->isWindow()))) + repaintManager->markDirtyOnScreen(toBePainted, q, offset); //restore if (paintEngine) { @@ -5599,7 +5599,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP #ifndef QT_NO_PAINT_DEBUG if (flushed) - QWidgetBackingStore::unflushPaint(q, toBePainted); + QWidgetRepaintManager::unflushPaint(q, toBePainted); #endif } else if (q->isWindow()) { QPaintEngine *engine = pdev->paintEngine(); @@ -5619,8 +5619,8 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP } if (recursive && !children.isEmpty()) { - paintSiblingsRecursive(pdev, children, children.size() - 1, rgn, offset, flags & ~DrawAsRoot - , sharedPainter, backingStore); + paintSiblingsRecursive(pdev, children, children.size() - 1, rgn, offset, flags & ~DrawAsRoot, + sharedPainter, repaintManager); } } @@ -5712,7 +5712,7 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, const QPoint &offset, int flags - , QPainter *sharedPainter, QWidgetBackingStore *backingStore) + , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager) { QWidget *w = 0; QRect boundingRect; @@ -5747,8 +5747,8 @@ void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectLis QRegion wr(rgn); if (wd->isOpaque) wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect; - paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags - , sharedPainter, backingStore); + paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags, + sharedPainter, repaintManager); } if (w->updatesEnabled() @@ -5761,7 +5761,7 @@ void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectLis wRegion.translate(-widgetPos); if (hasMask) wRegion &= wd->extra->mask; - wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, backingStore); + wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, repaintManager); } } @@ -5796,7 +5796,7 @@ void QWidgetEffectSourcePrivate::draw(QPainter *painter) toBePainted &= wd->extra->mask; wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags, - context->sharedPainter, context->backingStore); + context->sharedPainter, context->repaintManager); } QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, @@ -8173,8 +8173,8 @@ void QWidgetPrivate::hide_helper() } } - if (QWidgetBackingStore *bs = maybeBackingStore()) - bs->removeDirtyWidget(q); + if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) + repaintManager->removeDirtyWidget(q); #ifndef QT_NO_ACCESSIBILITY if (wasVisible) { @@ -10680,12 +10680,12 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) } #endif - if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { + if (QWidgetRepaintManager *oldPaintManager = oldtlw->d_func()->maybeRepaintManager()) { if (newParent) - oldBs->removeDirtyWidget(this); + oldPaintManager->removeDirtyWidget(this); // Move the widget and all its static children from // the old backing store to the new one. - oldBs->moveStaticWidgets(this); + oldPaintManager->moveStaticWidgets(this); } // ### fixme: Qt 6: Remove AA_ImmediateWidgetCreation. @@ -11039,7 +11039,7 @@ void QWidgetPrivate::repaint(T r) QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) - tlwExtra->widgetBackingStore->markDirty(r, q, QWidgetBackingStore::UpdateNow); + tlwExtra->repaintManager->markDirty(r, q, QWidgetRepaintManager::UpdateNow); } /*! @@ -11114,7 +11114,7 @@ void QWidgetPrivate::update(T r) QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) - tlwExtra->widgetBackingStore->markDirty(clipped, q); + tlwExtra->repaintManager->markDirty(clipped, q); } /*! @@ -11395,11 +11395,11 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) break; case Qt::WA_StaticContents: - if (QWidgetBackingStore *bs = d->maybeBackingStore()) { + if (QWidgetRepaintManager *repaintManager = d->maybeRepaintManager()) { if (on) - bs->addStaticWidget(this); + repaintManager->addStaticWidget(this); else - bs->removeStaticWidget(this); + repaintManager->removeStaticWidget(this); } break; case Qt::WA_TranslucentBackground: @@ -12204,14 +12204,14 @@ void QWidget::setBackingStore(QBackingStore *store) deleteBackingStore(d); topData->backingStore = store; - QWidgetBackingStore *bs = d->maybeBackingStore(); - if (!bs) + QWidgetRepaintManager *repaintManager = d->maybeRepaintManager(); + if (!repaintManager) return; if (isTopLevel()) { - if (bs->store != oldStore && bs->store != store) - delete bs->store; - bs->store = store; + if (repaintManager->store != oldStore && repaintManager->store != store) + delete repaintManager->store; + repaintManager->store = store; } } @@ -12227,9 +12227,8 @@ QBackingStore *QWidget::backingStore() const if (extra && extra->backingStore) return extra->backingStore; - QWidgetBackingStore *bs = d->maybeBackingStore(); - - return bs ? bs->store : 0; + QWidgetRepaintManager *repaintManager = d->maybeRepaintManager(); + return repaintManager ? repaintManager->store : nullptr; } void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const -- cgit v1.2.3 From 14fc3f4b0d69a2395dc734d9bf72b943508e0450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 14 Aug 2019 14:32:56 +0200 Subject: Upgrade QWidgetPrivate::DrawWidgetFlag to QFlags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows for easier debugging of the paint cycle. Change-Id: Iab85bccb99198a02f33c0beeccd4e3914375358d Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index d1ad0c0a01..d792b48467 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2353,7 +2353,7 @@ bool QWidgetPrivate::updateBrushOrigin(QPainter *painter, const QBrush &brush) c return true; } -void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const +void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, DrawWidgetFlags flags) const { Q_Q(const QWidget); @@ -5410,7 +5410,7 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset #endif } -void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, +void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, QPainter *sharedPainter, QWidgetRepaintManager *repaintManager) { if (rgn.isEmpty()) @@ -5508,7 +5508,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP beginBackingStorePainting(); #endif QPainter p(q); - paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0); + paintBackground(&p, toBePainted, (asRoot || onScreen) ? (flags | DrawAsRoot) : DrawWidgetFlags()); #ifndef QT_NO_OPENGL endBackingStorePainting(); #endif @@ -5691,7 +5691,7 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, } // Set backingstore flags. - int flags = DrawPaintOnScreen | DrawInvisible; + DrawWidgetFlags flags = DrawPaintOnScreen | DrawInvisible; if (renderFlags & QWidget::DrawWindowBackground) flags |= DrawAsRoot; @@ -5711,7 +5711,7 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, } void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, - const QPoint &offset, int flags + const QPoint &offset, DrawWidgetFlags flags , QPainter *sharedPainter, QWidgetRepaintManager *repaintManager) { QWidget *w = 0; -- cgit v1.2.3 From f556505f63a4255b681ba8a32e1f29ccb79725ce Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 24 May 2019 22:06:09 +0200 Subject: QWidget: replace manual memory management with unique_ptr [6/N]: extra Had to port a lot of caching temporaries, too. Decided to leave them as crefs to unique_ptr to catch any mischief users may be doing with the raw pointer instead (like deleting it). Also fixed a use of 0 as nullptr (by standardizing on pointer-to-bool conversion, as is done everywhere else in qwidget.cpp), and made one impregnable if condition readable. Change-Id: Ifdc240bf352c52de0bc3c186fa7a5f4cb2882dd0 Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qwidget.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 066dfaa183..2edbe05e32 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -148,7 +148,6 @@ extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp QWidgetPrivate::QWidgetPrivate(int version) : QObjectPrivate(version) - , extra(0) , focus_next(0) , focus_prev(0) , focus_child(0) @@ -1553,7 +1552,7 @@ QWidget::~QWidget() while (w->d_func()->extra && w->d_func()->extra->focus_proxy) w = w->d_func()->extra->focus_proxy; QWidget *window = w->window(); - QWExtra *e = window ? window->d_func()->extra : 0; + QWExtra *e = window ? window->d_func()->extra.get() : nullptr ; if (!e || !e->proxyWidget || (w->parentWidget() && w->parentWidget()->d_func()->focus_child == this)) #endif clearFocus(); @@ -1732,7 +1731,7 @@ void QWidgetPrivate::createTLExtra() void QWidgetPrivate::createExtra() { if (!extra) { // if not exists - extra = new QWExtra; + extra = qt_make_unique(); extra->glContext = 0; #if QT_CONFIG(graphicsview) extra->proxyWidget = 0; @@ -1780,9 +1779,8 @@ void QWidgetPrivate::deleteExtra() deleteTLSysExtra(); // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra() } - delete extra; // extra->xic destroyed in QWidget::destroy() - extra = 0; + extra.reset(); } } @@ -1853,7 +1851,7 @@ QRegion QWidgetPrivate::overlappedRegion(const QRect &rect, bool breakAfterFirst const QRect siblingRect = sibling->d_func()->effectiveRectFor(sibling->data->crect); if (qRectIntersects(siblingRect, r)) { - const QWExtra *siblingExtra = sibling->d_func()->extra; + const auto &siblingExtra = sibling->d_func()->extra; if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) { continue; @@ -3858,7 +3856,7 @@ QSize QWidget::sizeIncrement() const QSize QWidget::baseSize() const { Q_D(const QWidget); - return (d->extra != 0 && d->extra->topextra != 0) + return (d->extra && d->extra->topextra) ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh) : QSize(0, 0); } @@ -5858,7 +5856,7 @@ QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint * QGraphicsProxyWidget *QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin) { if (origin) { - QWExtra *extra = origin->d_func()->extra; + const auto &extra = origin->d_func()->extra; if (extra && extra->proxyWidget) return extra->proxyWidget; return nearestGraphicsProxyWidget(origin->parentWidget()); @@ -6404,7 +6402,7 @@ bool QWidget::hasFocus() const w = w->d_func()->extra->focus_proxy; #if QT_CONFIG(graphicsview) if (QWidget *window = w->window()) { - QWExtra *e = window->d_func()->extra; + const auto &e = window->d_func()->extra; if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w) return true; } @@ -6465,7 +6463,7 @@ void QWidget::setFocus(Qt::FocusReason reason) #if QT_CONFIG(graphicsview) QWidget *previousProxyFocus = 0; - if (QWExtra *topData = window()->d_func()->extra) { + if (const auto &topData = window()->d_func()->extra) { if (topData->proxyWidget && topData->proxyWidget->hasFocus()) { previousProxyFocus = topData->proxyWidget->widget()->focusWidget(); if (previousProxyFocus && previousProxyFocus->focusProxy()) @@ -6478,7 +6476,7 @@ void QWidget::setFocus(Qt::FocusReason reason) #if QT_CONFIG(graphicsview) // Update proxy state - if (QWExtra *topData = window()->d_func()->extra) { + if (const auto &topData = window()->d_func()->extra) { if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) { f->d_func()->updateFocusChild(); topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1; @@ -6519,7 +6517,7 @@ void QWidget::setFocus(Qt::FocusReason reason) } #endif #if QT_CONFIG(graphicsview) - if (QWExtra *topData = window()->d_func()->extra) { + if (const auto &topData = window()->d_func()->extra) { if (topData->proxyWidget) { if (previousProxyFocus && previousProxyFocus != f) { // Send event to self @@ -6532,7 +6530,7 @@ void QWidget::setFocus(Qt::FocusReason reason) if (!isHidden()) { #if QT_CONFIG(graphicsview) // Update proxy state - if (QWExtra *topData = window()->d_func()->extra) + if (const auto &topData = window()->d_func()->extra) if (topData->proxyWidget && topData->proxyWidget->hasFocus()) topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget(); #endif @@ -6669,7 +6667,7 @@ void QWidget::clearFocus() } #if QT_CONFIG(graphicsview) - QWExtra *topData = d_func()->extra; + const auto &topData = d_func()->extra; if (topData && topData->proxyWidget) topData->proxyWidget->clearFocus(); #endif @@ -6835,7 +6833,7 @@ bool QWidget::isActiveWindow() const return true; #if QT_CONFIG(graphicsview) - if (QWExtra *tlwExtra = tlw->d_func()->extra) { + if (const auto &tlwExtra = tlw->d_func()->extra) { if (isVisible() && tlwExtra->proxyWidget) return tlwExtra->proxyWidget->isActiveWindow(); } @@ -10325,7 +10323,7 @@ void QWidget::setSizePolicy(QSizePolicy policy) d->size_policy = policy; #if QT_CONFIG(graphicsview) - if (QWExtra *extra = d->extra) { + if (const auto &extra = d->extra) { if (extra->proxyWidget) extra->proxyWidget->setSizePolicy(policy); } -- cgit v1.2.3 From e2a1fb90154d8c0dd9b5def17c7062a0bdbebfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 20 Aug 2019 17:46:01 +0200 Subject: widgets: Remove unused function qt_dirtyRegion Change-Id: I7e6dbc4fb777a2323d65b73164d8645d6efc95a4 Reviewed-by: Marc Mutz --- src/widgets/kernel/qwidget.cpp | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index d792b48467..113c569591 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -860,22 +860,6 @@ QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid -/***************************************************************************** - QWidget utility functions - *****************************************************************************/ - -QRegion qt_dirtyRegion(QWidget *widget) -{ - if (!widget) - return QRegion(); - - QWidgetRepaintManager *repaintManager = qt_widget_private(widget)->maybeRepaintManager(); - if (!repaintManager) - return QRegion(); - - return repaintManager->dirtyRegion(widget); -} - /***************************************************************************** QWidget member functions *****************************************************************************/ -- cgit v1.2.3 From ce73b4db62574fc966192e6a4f65b7e2b2280e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 20 Aug 2019 14:26:05 +0200 Subject: Remove dead code from Qt 4 times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The benefit of keeping this code around was to inspire or inform changes in the areas to take into account possibly missing features in Qt 5, but at this point that benefit is questionable. We can always use the history to learn about missing pieces if needed. Change-Id: I87a02dc451e9027be9b97554427bf8a1c6b2c025 Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 402 ++--------------------------------------- 1 file changed, 16 insertions(+), 386 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 113c569591..0a7566614b 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -61,13 +61,6 @@ #ifndef QT_NO_ACCESSIBILITY # include "qaccessible.h" #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC -# include "qt_mac_p.h" -# include "qt_cocoa_helpers_mac_p.h" -# include "qmainwindow.h" -# include "qtoolbar.h" -# include -#endif #include #include "private/qwidgetwindow_p.h" #include "qpainter.h" @@ -91,9 +84,6 @@ #endif #include #include -#if 0 // Used to be included in Qt4 for Q_WS_MAC -# include -#endif #include #include "qwidget_p.h" @@ -129,20 +119,12 @@ QT_BEGIN_NAMESPACE -#if 0 // Used to be included in Qt4 for Q_WS_MAC -bool qt_mac_clearDirtyOnWidgetInsideDrawWidget = false; -#endif - static inline bool qRectIntersects(const QRect &r1, const QRect &r2) { return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) && qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom())); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC -# define QT_NO_PAINT_DEBUG -#endif - extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp @@ -202,17 +184,6 @@ QWidgetPrivate::QWidgetPrivate(int version) #if defined(Q_OS_WIN) , noPaintOnScreen(0) #endif -#if 0 // Used to be included in Qt4 for Q_WS_X11 - , picture(0) -#elif 0 // Used to be included in Qt4 for Q_WS_WIN - #ifndef QT_NO_GESTURES - , nativeGesturePanEnabled(0) - #endif -#elif 0 // Used to be included in Qt4 for Q_WS_MAC - , needWindowChange(0) - , window_event(0) - , qd_hd(0) -#endif { if (Q_UNLIKELY(!qApp)) { qFatal("QWidget: Must construct a QApplication before a QWidget"); @@ -231,16 +202,7 @@ QWidgetPrivate::QWidgetPrivate(int version) isWidget = true; memset(high_attributes, 0, sizeof(high_attributes)); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - drawRectOriginalAdded = false; - originalDrawMethod = true; - changeMethods = false; - isInUnifiedToolbar = false; - unifiedSurface = 0; - toolbar_ancestor = 0; - flushRequested = false; - touchEventsEnabled = false; -#endif + #ifdef QWIDGET_EXTRA_DEBUG static int count = 0; qDebug() << "widgets" << ++count; @@ -985,17 +947,12 @@ void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w) // Only enable this on non-Mac platforms. Since the old way of doing this would // interpret WindowSystemMenuHint as a close button and we can't change that behavior // we can't just add this in. -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC if ((flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint)) # ifdef Q_OS_WIN && type != Qt::Dialog // QTBUG-2027, allow for menu-less dialogs. # endif ) { flags |= Qt::WindowSystemMenuHint; -#else - if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint - | Qt::WindowSystemMenuHint)) { -#endif flags |= Qt::WindowTitleHint; flags &= ~Qt::FramelessWindowHint; } @@ -1050,13 +1007,6 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) } #endif -#if 0 // Used to be included in Qt4 for Q_WS_X11 - if (desktopWidget) { - // make sure the widget is created on the same screen as the - // programmer specified desktop widget - xinfo = desktopWidget->d_func()->xinfo; - } -#endif if (targetScreen >= 0) { topData()->initialScreenIndex = targetScreen; if (QWindow *window = q->windowHandle()) @@ -1084,9 +1034,6 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) mustHaveWindowHandle = 1; q->setAttribute(Qt::WA_NativeWindow); } -//#if 0 // Used to be included in Qt4 for Q_WS_MAC -// q->setAttribute(Qt::WA_NativeWindow); -//#endif q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute() adjustQuitOnCloseAttribute(); @@ -1110,9 +1057,6 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque()); } data.fnt = QFont(data.fnt, q); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - data.fnt.x11SetScreen(xinfo.screen()); -#endif q->setAttribute(Qt::WA_PendingMoveEvent); q->setAttribute(Qt::WA_PendingResizeEvent); @@ -1128,20 +1072,8 @@ void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) QCoreApplication::postEvent(q, new QEvent(QEvent::PolishRequest)); extraPaintEngine = 0; - -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // If we add a child to the unified toolbar, we have to redirect the painting. - if (parentWidget && parentWidget->d_func() && parentWidget->d_func()->isInUnifiedToolbar) { - if (parentWidget->d_func()->unifiedSurface) { - QWidget *toolbar = parentWidget->d_func()->toolbar_ancestor; - parentWidget->d_func()->unifiedSurface->recursiveRedirect(toolbar, toolbar, toolbar->d_func()->toolbar_offset); - } - } -#endif } - - void QWidgetPrivate::createRecursively() { Q_Q(QWidget); @@ -1248,15 +1180,6 @@ void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) << "Alien?" << !testAttribute(Qt::WA_NativeWindow); #endif -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ && QT_CONFIG(draganddrop) - // Unregister the dropsite (if already registered) before we - // re-create the widget with a native window. - if (testAttribute(Qt::WA_WState_Created) && !internalWinId() && testAttribute(Qt::WA_NativeWindow) - && d->extra && d->extra->dropTarget) { - d->registerDropSite(false); - } -#endif - d->updateIsOpaque(); setAttribute(Qt::WA_WState_Created); // set created flag @@ -1558,14 +1481,7 @@ QWidget::~QWidget() // and if that also doesn't work, then give up } } - } - -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ || 0 /* Used to be included in Qt4 for Q_WS_X11 */|| 0 /* Used to be included in Qt4 for Q_WS_MAC */ - else if (!internalWinId() && isVisible()) { - qApp->d_func()->sendSyntheticEnterLeave(this); - } -#endif - else if (isVisible()) { + } else if (isVisible()) { qApp->d_func()->sendSyntheticEnterLeave(this); } @@ -1609,15 +1525,6 @@ QWidget::~QWidget() d->blockSig = blocked; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // QCocoaView holds a pointer back to this widget. Clear it now - // to make sure it's not followed later on. The lifetime of the - // QCocoaView might exceed the lifetime of this widget in cases - // where Cocoa itself holds references to it. - extern void qt_mac_clearCocoaViewQWidgetPointers(QWidget *); - qt_mac_clearCocoaViewQWidgetPointers(this); -#endif - if (!d->children.isEmpty()) d->deleteChildren(); @@ -1664,9 +1571,6 @@ void QWidgetPrivate::setWinId(WId id) // set widget identifier const WId oldWinId = data.winid; data.winid = id; -#if 0 // Used to be included in Qt4 for Q_WS_X11 - hd = id; // X11: hd == ident -#endif if (mapper && id && !userDesktopWidget) { mapper->insert(data.winid, q); } @@ -1698,9 +1602,7 @@ void QWidgetPrivate::createTLExtra() x->embedded = 0; x->window = 0; x->initialScreenIndex = -1; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - x->wasMaximized = false; -#endif + #ifdef QWIDGET_EXTRA_DEBUG static int count = 0; qDebug() << "tlextra" << ++count; @@ -2097,11 +1999,6 @@ void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirt if (disableSubtractOpaqueSiblings || q->isWindow()) return; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (q->d_func()->isInUnifiedToolbar) - return; -#endif - QRect clipBoundingRect; bool dirtyClipBoundingRect = true; @@ -2234,13 +2131,6 @@ void QWidgetPrivate::updateIsOpaque() #endif // QT_CONFIG(graphicseffect) Q_Q(QWidget); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) { - setOpaque(false); - return; - } -#endif - if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) { setOpaque(true); return; @@ -2293,20 +2183,9 @@ static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrus Q_ASSERT(painter); if (brush.style() == Qt::TexturePattern) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // Optimize pattern filling on mac by using HITheme directly - // when filling with the standard widget background. - // Defined in qmacstyle_mac.cpp - extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush); - qt_mac_fill_background(painter, rgn, brush); -#else - { - const QRect rect(rgn.boundingRect()); - painter->setClipRegion(rgn); - painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); - } -#endif - + const QRect rect(rgn.boundingRect()); + painter->setClipRegion(rgn); + painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); } else if (brush.gradient() && (brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode || brush.gradient()->coordinateMode() == QGradient::ObjectMode)) { @@ -2380,11 +2259,7 @@ void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, Draw visible widgets. */ -#if 0 // Used to be included in Qt4 for Q_WS_MAC - extern QPointer qt_button_down; -#else - extern QWidget *qt_button_down; -#endif +extern QWidget *qt_button_down; void QWidgetPrivate::deactivateWidgetCleanup() { @@ -3053,15 +2928,6 @@ bool QWidget::isFullScreen() const */ void QWidget::showFullScreen() { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // If the unified toolbar is enabled, we have to disable it before going fullscreen. - QMainWindow *mainWindow = qobject_cast(this); - if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) { - mainWindow->setUnifiedTitleAndToolBarOnMac(false); - QMainWindowLayout *mainLayout = qobject_cast(mainWindow->layout()); - mainLayout->activateUnifiedToolbarAfterFullScreen = true; - } -#endif ensurePolished(); setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized)) @@ -3089,18 +2955,6 @@ void QWidget::showMaximized() setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) | Qt::WindowMaximized); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // If the unified toolbar was enabled before going fullscreen, we have to enable it back. - QMainWindow *mainWindow = qobject_cast(this); - if (mainWindow) - { - QMainWindowLayout *mainLayout = qobject_cast(mainWindow->layout()); - if (mainLayout->activateUnifiedToolbarAfterFullScreen) { - mainWindow->setUnifiedTitleAndToolBarOnMac(true); - mainLayout->activateUnifiedToolbarAfterFullScreen = false; - } - } -#endif setVisible(true); } @@ -3118,18 +2972,6 @@ void QWidget::showNormal() setWindowState(windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // If the unified toolbar was enabled before going fullscreen, we have to enable it back. - QMainWindow *mainWindow = qobject_cast(this); - if (mainWindow) - { - QMainWindowLayout *mainLayout = qobject_cast(mainWindow->layout()); - if (mainLayout->activateUnifiedToolbarAfterFullScreen) { - mainWindow->setUnifiedTitleAndToolBarOnMac(true); - mainLayout->activateUnifiedToolbarAfterFullScreen = false; - } - } -#endif setVisible(true); } @@ -3345,13 +3187,6 @@ void QWidgetPrivate::setEnabled_helper(bool enable) if (w && !w->testAttribute(attribute)) w->d_func()->setEnabled_helper(enable); } -#if 0 // Used to be included in Qt4 for Q_WS_X11 - if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { - // enforce the windows behavior of clearing the cursor on - // disabled widgets - qt_x11_enforce_cursor(q); - } -#endif #ifndef QT_NO_CURSOR if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { // enforce the windows behavior of clearing the cursor on @@ -3359,9 +3194,6 @@ void QWidgetPrivate::setEnabled_helper(bool enable) qt_qpa_set_cursor(q, false); } #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - setEnabled_helper_sys(enable); -#endif #ifndef QT_NO_IM if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) { QWidget *focusWidget = effectiveFocusWidget(); @@ -4456,13 +4288,7 @@ const QPalette &QWidget::palette() const ) { data->pal.setCurrentColorGroup(QPalette::Active); } else { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp - if (qt_mac_can_clickThrough(this)) - data->pal.setCurrentColorGroup(QPalette::Active); - else -#endif - data->pal.setCurrentColorGroup(QPalette::Inactive); + data->pal.setCurrentColorGroup(QPalette::Inactive); } return data->pal; } @@ -4725,10 +4551,7 @@ void QWidgetPrivate::updateFont(const QFont &font) #endif data.fnt = QFont(font, q); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - // make sure the font set on this widget is associated with the correct screen - data.fnt.x11SetScreen(xinfo.screen()); -#endif + // Combine new mask with natural mask and propagate to children. #if QT_CONFIG(graphicsview) if (!q->parentWidget() && extra && extra->proxyWidget) { @@ -4902,11 +4725,8 @@ QCursor QWidget::cursor() const void QWidget::setCursor(const QCursor &cursor) { Q_D(QWidget); -// On Mac we must set the cursor even if it is the ArrowCursor. -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC if (cursor.shape() != Qt::ArrowCursor || (d->extra && d->extra->curs)) -#endif { d->createExtra(); d->extra->curs = qt_make_unique(cursor); @@ -5333,11 +5153,9 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset Q_ASSERT(!toBePainted.isEmpty()); Q_Q(QWidget); -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC const QTransform originalTransform = painter->worldTransform(); const bool useDeviceCoordinates = originalTransform.isScaling(); if (!useDeviceCoordinates) { -#endif // Render via a pixmap. const QRect rect = toBePainted.boundingRect(); const QSize size = rect.size(); @@ -5360,7 +5178,6 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset if (restore) painter->setRenderHints(QPainter::SmoothPixmapTransform, false); -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC } else { // Render via a pixmap in device coordinates (to avoid pixmap scaling). QTransform transform = originalTransform; @@ -5391,7 +5208,6 @@ void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset painter->drawPixmap(deviceRect.topLeft(), pixmap); painter->setTransform(originalTransform); } -#endif } void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, DrawWidgetFlags flags, @@ -5471,15 +5287,6 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP if (paintEngine) { setRedirected(pdev, -offset); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // (Alien support) Special case for Mac when redirecting: If the paint device - // is of the Widget type we need to set WA_WState_InPaintEvent since painting - // outside the paint event is not supported on QWidgets. The attributeis - // restored further down. - if (pdev->devType() == QInternal::Widget) - static_cast(pdev)->setAttribute(Qt::WA_WState_InPaintEvent); - -#endif if (sharedPainter) setSystemClip(pdev->paintEngine(), pdev->devicePixelRatioF(), toBePainted); else @@ -5561,10 +5368,6 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP //restore if (paintEngine) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (pdev->devType() == QInternal::Widget) - static_cast(pdev)->setAttribute(Qt::WA_WState_InPaintEvent, false); -#endif restoreRedirected(); if (!sharedPainter) paintEngine->d_func()->systemRect = QRect(); @@ -5635,7 +5438,6 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, if (paintRegion.isEmpty()) return; -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : 0; // Use the target's shared painter if set (typically set when doing @@ -5648,7 +5450,6 @@ void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, setSharedPainter(targetPainter); } } -#endif // Use the target's redirected device if set and adjust offset and paint // region accordingly. This is typically the case when people call render @@ -6440,11 +6241,7 @@ void QWidget::setFocus(Qt::FocusReason reason) if (!f) f = this; - if (QApplication::focusWidget() == f -#if 0 // Used to be included in Qt4 for Q_WS_WIN - && GetFocus() == f->internalWinId() -#endif - ) + if (QApplication::focusWidget() == f) return; #if QT_CONFIG(graphicsview) @@ -6661,17 +6458,10 @@ void QWidget::clearFocus() if (hasFocus()) { // Update proxy state QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason); -#if 0 // Used to be included in Qt4 for Q_WS_WIN - if (!(windowType() == Qt::Popup) && GetFocus() == internalWinId()) - SetFocus(0); - else -#endif - { #ifndef QT_NO_ACCESSIBILITY - QAccessibleEvent event(this, QAccessible::Focus); - QAccessible::updateAccessibility(&event); + QAccessibleEvent event(this, QAccessible::Focus); + QAccessible::updateAccessibility(&event); #endif - } } } @@ -7315,18 +7105,6 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) */ QByteArray QWidget::saveGeometry() const { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // We check if the window was maximized during this invocation. If so, we need to record the - // starting position as 0,0. - Q_D(const QWidget); - QRect newFramePosition = frameGeometry(); - QRect newNormalPosition = normalGeometry(); - if(d->topData()->wasMaximized && !(windowState() & Qt::WindowMaximized)) { - // Change the starting position - newFramePosition.moveTo(0, 0); - newNormalPosition.moveTo(0, 0); - } -#endif QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_4_0); @@ -7341,13 +7119,8 @@ QByteArray QWidget::saveGeometry() const stream << magicNumber << majorVersion << minorVersion -#if 0 // Used to be included in Qt4 for Q_WS_MAC - << newFramePosition - << newNormalPosition -#else << frameGeometry() << normalGeometry() -#endif << qint32(screenNumber) << quint8(windowState() & Qt::WindowMaximized) << quint8(windowState() & Qt::WindowFullScreen) @@ -7467,11 +7240,6 @@ bool QWidget::restoreGeometry(const QByteArray &geometry) // that would make the window "lost". This happens if: // - The restored geometry is completely oustside the available geometry // - The title bar is outside the available geometry. - // - (Mac only) The window is higher than the available geometry. It must - // be possible to bring the size grip on screen by moving the window. -#if 0 // Used to be included in Qt4 for Q_WS_MAC - restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight)); -#endif checkRestoredGeometry(availableGeometry, &restoredGeometry, frameHeight); checkRestoredGeometry(availableGeometry, &restoredNormalGeometry, frameHeight); @@ -7991,14 +7759,6 @@ void QWidgetPrivate::show_helper() Q_UNUSED(isEmbedded); #endif - // On Windows, show the popup now so that our own focus handling - // stores the correct old focus widget even if it's stolen in the - // showevent -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ || 0 /* Used to be included in Qt4 for Q_WS_MAC */ - if (!isEmbedded && q->windowType() == Qt::Popup) - qApp->d_func()->openPopup(q); -#endif - // send the show event before showing the window QShowEvent showEvent; QCoreApplication::sendEvent(q, &showEvent); @@ -8123,12 +7883,6 @@ void QWidgetPrivate::hide_helper() if (!isEmbedded && (q->windowType() == Qt::Popup)) qApp->d_func()->closePopup(q); -#if 0 // Used to be included in Qt4 for Q_WS_WIN - if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget() - && !q->parentWidget()->isHidden() && q->isActiveWindow()) - q->parentWidget()->activateWindow(); // Activate parent -#endif - q->setAttribute(Qt::WA_Mapped, false); hide_sys(); @@ -8313,16 +8067,6 @@ void QWidgetPrivate::setVisible(bool visible) QEvent showToParentEvent(QEvent::ShowToParent); QCoreApplication::sendEvent(q, &showToParentEvent); } else { // hide -#if 0 // Used to be included in Qt4 for Q_WS_WIN - // reset WS_DISABLED style in a Blocked window - if(isWindow() && testAttribute(Qt::WA_WState_Created) - && QApplicationPrivate::isBlockedByModal(this)) - { - LONG dwStyle = GetWindowLong(winId(), GWL_STYLE); - dwStyle &= ~WS_DISABLED; - SetWindowLong(winId(), GWL_STYLE, dwStyle); - } -#endif if (QApplicationPrivate::hidden_focus_widget == q) QApplicationPrivate::hidden_focus_widget = 0; @@ -8395,23 +8139,7 @@ void QWidgetPrivate::hideChildren(bool spontaneous) QWidget *widget = qobject_cast(childList.at(i)); if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden)) continue; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - // Before doing anything we need to make sure that we don't leave anything in a non-consistent state. - // When hiding a widget we need to make sure that no mouse_down events are active, because - // the mouse_up event will never be received by a hidden widget or one of its descendants. - // The solution is simple, before going through with this we check if there are any mouse_down events in - // progress, if so we check if it is related to this widget or not. If so, we just reset the mouse_down and - // then we continue. - // In X11 and Windows we send a mouse_release event, however we don't do that here because we were already - // ignoring that from before. I.e. Carbon did not send the mouse release event, so we will not send the - // mouse release event. There are two ways to interpret this: - // 1. If we don't send the mouse release event, the widget might get into an inconsistent state, i.e. it - // might be waiting for a release event that will never arrive. - // 2. If we send the mouse release event, then the widget might decide to trigger an action that is not - // supposed to trigger because it is not visible. - if(widget == qt_button_down) - qt_button_down = 0; -#endif + if (spontaneous) widget->setAttribute(Qt::WA_Mapped, false); else @@ -8646,11 +8374,9 @@ QSize QWidgetPrivate::adjustedSize() const s.setWidth(qMax(s.width(), 200)); if (exp & Qt::Vertical) s.setHeight(qMax(s.height(), 100)); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - QRect screen = QDesktopWidgetPrivate::screenGeometry(q->x11Info().screen()); -#else // all others + QRect screen = QDesktopWidgetPrivate::screenGeometry(q->pos()); -#endif + s.setWidth(qMin(s.width(), screen.width()*2/3)); s.setHeight(qMin(s.height(), screen.height()*2/3)); @@ -8775,26 +8501,6 @@ bool QWidget::isAncestorOf(const QWidget *child) const return false; } -#if 0 // Used to be included in Qt4 for Q_WS_WIN -inline void setDisabledStyle(QWidget *w, bool setStyle) -{ - // set/reset WS_DISABLED style. - if(w && w->isWindow() && w->isVisible() && w->isEnabled()) { - LONG dwStyle = GetWindowLong(w->winId(), GWL_STYLE); - LONG newStyle = dwStyle; - if (setStyle) - newStyle |= WS_DISABLED; - else - newStyle &= ~WS_DISABLED; - if (newStyle != dwStyle) { - SetWindowLong(w->winId(), GWL_STYLE, newStyle); - // we might need to repaint in some situations (eg. menu) - w->repaint(); - } - } -} -#endif - /***************************************************************************** QWidget event handling *****************************************************************************/ @@ -9211,9 +8917,6 @@ bool QWidget::event(QEvent *event) } } } -#if 0 // Used to be included in Qt4 for Q_WS_WIN - setDisabledStyle(this, (event->type() == QEvent::WindowBlocked)); -#endif break; #ifndef QT_NO_TOOLTIP case QEvent::ToolTip: @@ -9238,9 +8941,6 @@ bool QWidget::event(QEvent *event) case QEvent::EmbeddingControl: d->topData()->frameStrut.setCoords(0 ,0, 0, 0); data->fstrut_dirty = false; -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ || 0 /* Used to be included in Qt4 for Q_WS_X11 */ - d->topData()->embedded = 1; -#endif break; #ifndef QT_NO_ACTION case QEvent::ActionAdded: @@ -9263,11 +8963,6 @@ bool QWidget::event(QEvent *event) } break; } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - case QEvent::MacGLWindowChange: - d->needWindowChange = false; - break; -#endif case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: @@ -9379,11 +9074,6 @@ void QWidget::changeEvent(QEvent * event) case QEvent::MacSizeChange: updateGeometry(); break; -#elif 0 // Used to be included in Qt4 for Q_WS_MAC - case QEvent::ToolTipChange: - case QEvent::MouseTrackingChange: - qt_mac_update_mouseTracking(this); - break; #endif default: @@ -10695,7 +10385,7 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all // platforms). if (newParent -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ || defined(QT_OPENGL_ES) +#if defined(QT_OPENGL_ES) || (f & Qt::MSWindowsOwnDC) #endif ) { @@ -10714,15 +10404,6 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) QCoreApplication::sendEvent(parent, &e); } -//### already hidden above ---> must probably do something smart on the mac -// #if 0 // Used to be included in Qt4 for Q_WS_MAC -// extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp -// if(!qt_mac_is_macdrawer(q)) //special case -// q->setAttribute(Qt::WA_WState_Hidden); -// #else -// q->setAttribute(Qt::WA_WState_Hidden); -//#endif - if (parent && d->sendChildEvents && d->polished) { QChildEvent e(QEvent::ChildPolished, this); QCoreApplication::sendEvent(parent, &e); @@ -11204,23 +10885,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) case Qt::WA_NoChildEventsFromChildren: d->receiveChildEvents = !on; break; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - case Qt::WA_MacOpaqueSizeGrip: - d->macUpdateOpaqueSizeGrip(); - break; - case Qt::WA_MacShowFocusRect: - if (hasFocus()) { - clearFocus(); - setFocus(); - } - break; - case Qt::WA_Hover: - qt_mac_update_mouseTracking(this); - break; - case Qt::WA_MacAlwaysShowToolWindow: - d->macUpdateHideOnSuspend(); - break; -#endif case Qt::WA_MacNormalSize: case Qt::WA_MacSmallSize: case Qt::WA_MacMiniSize: @@ -11298,15 +10962,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) } case Qt::WA_PaintOnScreen: d->updateIsOpaque(); -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ || 0 /* Used to be included in Qt4 for Q_WS_X11 */ || 0 /* Used to be included in Qt4 for Q_WS_MAC */ - // Recreate the widget if it's already created as an alien widget and - // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id. - // So must their children. - if (on) { - setAttribute(Qt::WA_NativeWindow); - d->enforceNativeChildren(); - } -#endif Q_FALLTHROUGH(); case Qt::WA_OpaquePaintEvent: d->updateIsOpaque(); @@ -11318,9 +10973,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) d->updateSystemBackground(); break; case Qt::WA_TransparentForMouseEvents: -#if 0 // Used to be included in Qt4 for Q_WS_MAC - d->macUpdateIgnoreMouseEvents(); -#endif break; case Qt::WA_InputMethodEnabled: { #ifndef QT_NO_IM @@ -11337,20 +10989,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) d->resolveFont(); d->resolveLocale(); break; -#if 0 // Used to be included in Qt4 for Q_WS_X11 - case Qt::WA_NoX11EventCompression: - if (!d->extra) - d->createExtra(); - d->extra->compress_events = on; - break; - case Qt::WA_X11OpenGLOverlay: - d->updateIsOpaque(); - break; - case Qt::WA_X11DoNotAcceptFocus: - if (testAttribute(Qt::WA_WState_Created)) - d->updateX11AcceptFocus(); - break; -#endif case Qt::WA_DontShowOnScreen: { if (on && isVisible()) { // Make sure we keep the current state and only hide the widget @@ -11393,10 +11031,6 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) break; case Qt::WA_AcceptTouchEvents: -#if 0 /* Used to be included in Qt4 for Q_WS_WIN */ || 0 /* Used to be included in Qt4 for Q_WS_MAC */ - if (on) - d->registerTouchWindow(); -#endif break; default: break; @@ -12012,10 +11646,8 @@ QRect QWidgetPrivate::frameStrut() const } if (data.fstrut_dirty -#if 1 // Used to be excluded in Qt4 for Q_WS_WIN // ### Fix properly for 4.3 && q->isVisible() -#endif && q->testAttribute(Qt::WA_WState_Created)) const_cast(this)->updateFrameStrut(); @@ -12942,10 +12574,8 @@ void QWidget::setMask(const QRegion &newMask) d->extra->mask = newMask; d->extra->hasMask = !newMask.isEmpty(); -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC if (!testAttribute(Qt::WA_WState_Created)) return; -#endif d->setMask_sys(newMask); -- cgit v1.2.3 From b455a863a1df61337f36f2e8b43101ca21514697 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 5 Apr 2019 14:20:06 +0200 Subject: Add screen() accessor to QWidget Base it on QWidgetPrivate::associatedScreen(), but make a larger effort to find a screen in case the widget is not shown yet. Rename QDesktopScreenWidget::screen() to something else to avoid clashes. Task-number: QTBUG-62094 Task-number: QTBUG-53022 Change-Id: I36ba5ef5f0645a4ac89da0b38a391f7057b2f49c Reviewed-by: Shawn Rutledge --- src/widgets/kernel/qwidget.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 0a7566614b..e286782d6f 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2445,7 +2445,7 @@ WId QWidget::effectiveWinId() const \since 5.0 - \sa winId() + \sa winId(), screen() */ QWindow *QWidget::windowHandle() const { @@ -2453,6 +2453,29 @@ QWindow *QWidget::windowHandle() const return d->windowHandle(); } +/*! + Returns the screen the widget is on. + + \since 5.14 + + \sa windowHandle() +*/ +QScreen *QWidget::screen() const +{ + Q_D(const QWidget); + if (auto associatedScreen = d->associatedScreen()) + return associatedScreen; + if (auto topLevel = window()) { + if (auto topData = qt_widget_private(topLevel)->topData()) { + if (auto initialScreen = QGuiApplicationPrivate::screen_list.value(topData->initialScreenIndex)) + return initialScreen; + } + if (auto screenByPos = QGuiApplication::screenAt(topLevel->geometry().center())) + return screenByPos; + } + return QGuiApplication::primaryScreen(); +} + #ifndef QT_NO_STYLE_STYLESHEET /*! -- cgit v1.2.3 From 44fc2914be67055bbe609790fb7eaf1a643758e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 21 Aug 2019 11:09:50 +0200 Subject: Goodbye showYellowThing The code hasn't been working for at least 5 years, and is just making the repaint manager more complex. We can always re-introduce the feature at a later point. Change-Id: Ib07c782c821f3e653f9452f6fbfe2f87effccc92 Fixes: QTBUG-36435 Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e286782d6f..00d91a13c9 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5303,9 +5303,6 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP q->setAttribute(Qt::WA_WState_InPaintEvent); //clip away the new area -#ifndef QT_NO_PAINT_DEBUG - bool flushed = QWidgetRepaintManager::flushPaint(q, toBePainted); -#endif QPaintEngine *paintEngine = pdev->paintEngine(); if (paintEngine) { setRedirected(pdev, -offset); @@ -5406,11 +5403,6 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP if (paintEngine && paintEngine->autoDestruct()) { delete paintEngine; } - -#ifndef QT_NO_PAINT_DEBUG - if (flushed) - QWidgetRepaintManager::unflushPaint(q, toBePainted); -#endif } else if (q->isWindow()) { QPaintEngine *engine = pdev->paintEngine(); if (engine) { -- cgit v1.2.3 From 68cc2c2779aa8f75c14415ecbd19a9c6fdee6ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 21 Aug 2019 15:16:22 +0200 Subject: widgets: Don't rely on QWidget friending QWidgetRepaintManager Change-Id: Id9fc28eb62103d38eaa51261f61a2294db85e0d6 Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 00d91a13c9..d098d9cc04 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -11840,9 +11840,9 @@ void QWidget::setBackingStore(QBackingStore *store) return; if (isTopLevel()) { - if (repaintManager->store != oldStore && repaintManager->store != store) - delete repaintManager->store; - repaintManager->store = store; + if (repaintManager->backingStore() != oldStore && repaintManager->backingStore() != store) + delete repaintManager->backingStore(); + repaintManager->setBackingStore(store); } } @@ -11859,7 +11859,7 @@ QBackingStore *QWidget::backingStore() const return extra->backingStore; QWidgetRepaintManager *repaintManager = d->maybeRepaintManager(); - return repaintManager ? repaintManager->store : nullptr; + return repaintManager ? repaintManager->backingStore() : nullptr; } void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const -- cgit v1.2.3 From 36cf237ea1ca1522e37c3d4e66f08dc00bc3295d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 15 Aug 2019 14:00:25 +0200 Subject: QWidget: two small fixes - Use QPointer::data() instead of a C-style cast - Remove an abuse of Q_UNLIKELY. Q_UNLIKELY is for error code. Using it for conditions that have a good chance of being true in normal operations just caused all the error handling code to be paged in needlessly. Change-Id: I542a5b938b032ca84f2cf1f78fbc45049a12ad1a Reviewed-by: Friedemann Kleint --- src/widgets/kernel/qwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index d098d9cc04..049ddb0213 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -6181,7 +6181,7 @@ void QWidget::setFocusProxy(QWidget * w) QWidget *QWidget::focusProxy() const { Q_D(const QWidget); - return d->extra ? (QWidget *)d->extra->focus_proxy : nullptr; + return d->extra ? d->extra->focus_proxy.data() : nullptr; } @@ -11932,7 +11932,7 @@ QOpenGLContext *QWidgetPrivate::shareContext() const #ifdef QT_NO_OPENGL return 0; #else - if (Q_UNLIKELY(!extra || !extra->topextra || !extra->topextra->window)) + if (!extra || !extra->topextra || !extra->topextra->window) return 0; if (!extra->topextra->shareContext) { -- cgit v1.2.3 From 16868bd6a247d419d7c15ae10ff2c667e6110b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 21 Aug 2019 17:29:39 +0200 Subject: widgets: Clean up and reorder QWidgetRepaintManager implementation Group functions by related areas and order them roughly by their flow in a normal app repaint cycle. Change-Id: I7a963f612134b3fdbaf748e0432606825b8db64e Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 049ddb0213..c2caf7a421 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1775,6 +1775,42 @@ void QWidgetPrivate::syncBackingStore(const QRegion ®ion) } } +void QWidgetPrivate::repaint_sys(const QRegion &rgn) +{ + if (data.in_destructor) + return; + + if (shouldDiscardSyncRequest()) + return; + + Q_Q(QWidget); + if (q->testAttribute(Qt::WA_StaticContents)) { + if (!extra) + createExtra(); + extra->staticContentsSize = data.crect.size(); + } + + QPaintEngine *engine = q->paintEngine(); + + // QGLWidget does not support partial updates if: + // 1) The context is double buffered + // 2) The context is single buffered and auto-fill background is enabled. + const bool noPartialUpdateSupport = (engine && (engine->type() == QPaintEngine::OpenGL + || engine->type() == QPaintEngine::OpenGL2)) + && (usesDoubleBufferedGLContext || q->autoFillBackground()); + QRegion toBePainted(noPartialUpdateSupport ? q->rect() : rgn); + + toBePainted &= clipRect(); + clipToEffectiveMask(toBePainted); + if (toBePainted.isEmpty()) + return; // Nothing to repaint. + + drawWidget(q, toBePainted, QPoint(), QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawPaintOnScreen, 0); + + if (Q_UNLIKELY(q->paintingActive())) + qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); +} + void QWidgetPrivate::setUpdatesEnabled_helper(bool enable) { Q_Q(QWidget); -- cgit v1.2.3 From 36d734b3f8db4fc1fce932cf5f1a6684b2dc10db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 22 Aug 2019 17:27:29 +0200 Subject: widgets: Rename markDirtyOnScreen to markNeedsFlush Including renaming the member touched by this function. This leaves the logic for appendDirtyOnScreenWidget, which still needs investigating. Change-Id: I405a5e3757f0a79992f88d9f70867aeb7b9764d8 Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index c2caf7a421..c0f5954885 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5312,7 +5312,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP // Native widgets need to be marked dirty on screen so painting will be done in correct context // Same check as in the no effects case below. if (repaintManager && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) - repaintManager->markDirtyOnScreen(rgn, q, offset); + repaintManager->markNeedsFlush(q, rgn, offset); return; } @@ -5420,7 +5420,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP // Native widgets need to be marked dirty on screen so painting will be done in correct context if (repaintManager && !onScreen && !asRoot && (q->internalWinId() || (q->nativeParentWidget() && !q->nativeParentWidget()->isWindow()))) - repaintManager->markDirtyOnScreen(toBePainted, q, offset); + repaintManager->markNeedsFlush(q, toBePainted, offset); //restore if (paintEngine) { -- cgit v1.2.3 From e8c70fb07f01b492b721451c00496f860eb40be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 23 Aug 2019 15:19:52 +0200 Subject: widgets: Rename QWidgetPrivate::repaint_sys to paintOnScreen Change-Id: Ic853e42cbed9b770bef0e1d7c7376c861bceb891 Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index c0f5954885..c0c7f5cf3d 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1758,8 +1758,8 @@ QRegion QWidgetPrivate::overlappedRegion(const QRect &rect, bool breakAfterFirst void QWidgetPrivate::syncBackingStore() { - if (paintOnScreen()) { - repaint_sys(dirty); + if (shouldPaintOnScreen()) { + paintOnScreen(dirty); dirty = QRegion(); } else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) { repaintManager->sync(); @@ -1768,14 +1768,14 @@ void QWidgetPrivate::syncBackingStore() void QWidgetPrivate::syncBackingStore(const QRegion ®ion) { - if (paintOnScreen()) - repaint_sys(region); + if (shouldPaintOnScreen()) + paintOnScreen(region); else if (QWidgetRepaintManager *repaintManager = maybeRepaintManager()) { repaintManager->sync(q_func(), region); } } -void QWidgetPrivate::repaint_sys(const QRegion &rgn) +void QWidgetPrivate::paintOnScreen(const QRegion &rgn) { if (data.in_destructor) return; @@ -2138,7 +2138,7 @@ void QWidgetPrivate::clipToEffectiveMask(QRegion ®ion) const } } -bool QWidgetPrivate::paintOnScreen() const +bool QWidgetPrivate::shouldPaintOnScreen() const { #if defined(QT_NO_BACKINGSTORE) return true; @@ -5276,7 +5276,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP return; const bool asRoot = flags & DrawAsRoot; - bool onScreen = paintOnScreen(); + bool onScreen = shouldPaintOnScreen(); Q_Q(QWidget); #if QT_CONFIG(graphicseffect) -- cgit v1.2.3 From ebec918722a283410624af6df38345b9dfc0b8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 26 Aug 2019 15:10:49 +0200 Subject: widgets: Simplify markNeedsFlush in QWidgetPrivate::drawWidget QWidgetRepaintManager::markNeedsFlush already ignores paintOnScreen widgets. Change-Id: I8b5d6f79c8fd60115f77d65aef05cc4baf840bdd Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index c024f7f1f3..9e8c0cb500 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5309,7 +5309,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP // Native widgets need to be marked dirty on screen so painting will be done in correct context // Same check as in the no effects case below. - if (repaintManager && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) + if (repaintManager && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) repaintManager->markNeedsFlush(q, rgn, offset); return; @@ -5417,7 +5417,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP } // Native widgets need to be marked dirty on screen so painting will be done in correct context - if (repaintManager && !onScreen && !asRoot && (q->internalWinId() || (q->nativeParentWidget() && !q->nativeParentWidget()->isWindow()))) + if (repaintManager && !asRoot && (q->internalWinId() || (q->nativeParentWidget() && !q->nativeParentWidget()->isWindow()))) repaintManager->markNeedsFlush(q, toBePainted, offset); //restore -- cgit v1.2.3 From 984df39c79e6129250fd0f8516fbfb2e28bcefd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 26 Aug 2019 17:34:35 +0200 Subject: widgets: Add logging for widget painting Change-Id: I551ec290812369e3848c1096fed7e813cd9e1cd6 Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 9e8c0cb500..45be132e59 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -119,6 +119,8 @@ QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(lcWidgetPainting, "qt.widgets.painting", QtWarningMsg); + static inline bool qRectIntersects(const QRect &r1, const QRect &r2) { return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) && @@ -5273,10 +5275,14 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP if (rgn.isEmpty()) return; + Q_Q(QWidget); + + qCInfo(lcWidgetPainting) << "Drawing" << rgn << "of" << q << "at" << offset + << "into paint device" << pdev << "with" << flags; + const bool asRoot = flags & DrawAsRoot; bool onScreen = shouldPaintOnScreen(); - Q_Q(QWidget); #if QT_CONFIG(graphicseffect) if (graphicsEffect && graphicsEffect->isEnabled()) { QGraphicsEffectSource *source = graphicsEffect->d_func()->source; -- cgit v1.2.3 From 79bf1b7e348d186934b14c417859a48bf9b3a06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 26 Aug 2019 22:08:59 +0200 Subject: widgets: Mark widgets as needing flush during painting Except for the case of syncing in response to an expose event, where the platform asked us to flush a specific region, we should strive to only flush parts that have been repainted. And we should flush those parts to their nearest native child, instead of unconditionally flushing the root/top level widget as well. By allowing drawWidget to schedule the flush we automatically flush the minimal region, to the right widgets. Change-Id: I73c143761d4a0da6991433b41dea0a0bc83a448a Reviewed-by: Paul Olav Tvete --- src/widgets/kernel/qwidget.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/widgets/kernel/qwidget.cpp') diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 45be132e59..cf5a81c204 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5313,9 +5313,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP } sourced->context = 0; - // Native widgets need to be marked dirty on screen so painting will be done in correct context - // Same check as in the no effects case below. - if (repaintManager && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) + if (repaintManager) repaintManager->markNeedsFlush(q, rgn, offset); return; @@ -5422,8 +5420,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP sendPaintEvent(toBePainted); } - // Native widgets need to be marked dirty on screen so painting will be done in correct context - if (repaintManager && !asRoot && (q->internalWinId() || (q->nativeParentWidget() && !q->nativeParentWidget()->isWindow()))) + if (repaintManager) repaintManager->markNeedsFlush(q, toBePainted, offset); //restore -- cgit v1.2.3