summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-12-14 12:14:11 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2017-12-14 13:11:51 +0000
commitd48c502ce535c913424440557cdfe7fa6e383dea (patch)
tree0f2dc77f1c32b8d354a7679cdab0db0e1ff95c44 /src/widgets
parent3d65284b60bfc8e01c4ea4b86344a508b6f49358 (diff)
Share QWidget update and repaint code for QRect and QRegion
QWidgetBackingStore::markDirty has an optimization for QRect, so we don't want to unify these two functions by calling update/repaint(QRegion(rect)). Change-Id: Id2a42f478f71863da45697041e0ab0130c74b9d2 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qwidget.cpp74
-rw-r--r--src/widgets/kernel/qwidget_p.h7
2 files changed, 35 insertions, 46 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index a82f97270d..b57a0d4779 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -11012,21 +11012,7 @@ void QWidget::repaint(int x, int y, int w, int h)
void QWidget::repaint(const QRect &rect)
{
Q_D(QWidget);
-
- if (testAttribute(Qt::WA_WState_ConfigPending)) {
- update(rect);
- return;
- }
-
- if (!isVisible() || !updatesEnabled() || rect.isEmpty())
- return;
-
- QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
- if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
- tlwExtra->inRepaint = true;
- tlwExtra->backingStoreTracker->markDirty(rect, this, QWidgetBackingStore::UpdateNow);
- tlwExtra->inRepaint = false;
- }
+ d->repaint(rect);
}
/*!
@@ -11037,19 +11023,21 @@ void QWidget::repaint(const QRect &rect)
void QWidget::repaint(const QRegion &rgn)
{
Q_D(QWidget);
+ d->repaint(rgn);
+}
- if (testAttribute(Qt::WA_WState_ConfigPending)) {
- update(rgn);
- return;
- }
+template <typename T>
+void QWidgetPrivate::repaint(T r)
+{
+ Q_Q(QWidget);
- if (!isVisible() || !updatesEnabled() || rgn.isEmpty())
+ if (!q->isVisible() || !q->updatesEnabled() || r.isEmpty())
return;
- QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
+ QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
tlwExtra->inRepaint = true;
- tlwExtra->backingStoreTracker->markDirty(rgn, this, QWidgetBackingStore::UpdateNow);
+ tlwExtra->backingStoreTracker->markDirty(r, q, QWidgetBackingStore::UpdateNow);
tlwExtra->inRepaint = false;
}
}
@@ -11091,22 +11079,8 @@ void QWidget::update()
*/
void QWidget::update(const QRect &rect)
{
- if (!isVisible() || !updatesEnabled())
- return;
-
- QRect r = rect & QWidget::rect();
-
- if (r.isEmpty())
- return;
-
- if (testAttribute(Qt::WA_WState_InPaintEvent)) {
- QApplication::postEvent(this, new QUpdateLaterEvent(r));
- return;
- }
-
- QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
- if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore)
- tlwExtra->backingStoreTracker->markDirty(r, this);
+ Q_D(QWidget);
+ d->update(rect);
}
/*!
@@ -11116,25 +11090,33 @@ void QWidget::update(const QRect &rect)
*/
void QWidget::update(const QRegion &rgn)
{
- if (!isVisible() || !updatesEnabled())
+ Q_D(QWidget);
+ d->update(rgn);
+}
+
+template <typename T>
+void QWidgetPrivate::update(T r)
+{
+ Q_Q(QWidget);
+
+ if (!q->isVisible() || !q->updatesEnabled())
return;
- QRegion r = rgn & QWidget::rect();
+ T clipped = r & q->rect();
- if (r.isEmpty())
+ if (clipped.isEmpty())
return;
- if (testAttribute(Qt::WA_WState_InPaintEvent)) {
- QApplication::postEvent(this, new QUpdateLaterEvent(r));
+ if (q->testAttribute(Qt::WA_WState_InPaintEvent)) {
+ QApplication::postEvent(q, new QUpdateLaterEvent(clipped));
return;
}
- QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
+ QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore)
- tlwExtra->backingStoreTracker->markDirty(r, this);
+ tlwExtra->backingStoreTracker->markDirty(clipped, q);
}
-
/*!
\internal
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 0c012d1932..15704f32c9 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -342,6 +342,13 @@ public:
QPainter *sharedPainter() const;
void setSharedPainter(QPainter *painter);
QWidgetBackingStore *maybeBackingStore() const;
+
+ template <typename T>
+ void repaint(T t);
+
+ template <typename T>
+ void update(T t);
+
void init(QWidget *desktopWidget, Qt::WindowFlags f);
void create_sys(WId window, bool initializeWindow, bool destroyOldWindow);
void createRecursively();