QWidgetBackingStore: clean up around dirtyOnScreenWidgets
The QVector dirtyOnScreenWidgets was aggregated by pointer, which makes no sense, as a QVector is just as large as a pointer (and even in Qt 6, when it will be larger, it's not going to be horrible). But this complicated the code quite a bit. Aggregate by value instead (it's just one of three such vectors now). Drive-by fixes: - use QVector::removeAll() instead of rolling your own - port two indexed loops to ranged ones. In the first case, it's safe, as the loop body clearly doesn't touch the iteratee (it's just a std::accumulate). In the second, the question no longer applies, as we're now using a consume loop. Change-Id: Icd4ac13bb4a6f9a783f0adf2fb6a5bdfacd1f91a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
3e79151fa2
commit
cb3e1e551f
@ -397,15 +397,12 @@ QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const
|
|||||||
// Append the region that needs flush.
|
// Append the region that needs flush.
|
||||||
r += dirtyOnScreen;
|
r += dirtyOnScreen;
|
||||||
|
|
||||||
if (dirtyOnScreenWidgets) { // Only in use with native child widgets.
|
for (QWidget *w : dirtyOnScreenWidgets) {
|
||||||
for (int i = 0; i < dirtyOnScreenWidgets->size(); ++i) {
|
if (widgetDirty && w != widget && !widget->isAncestorOf(w))
|
||||||
QWidget *w = dirtyOnScreenWidgets->at(i);
|
continue;
|
||||||
if (widgetDirty && w != widget && !widget->isAncestorOf(w))
|
QWidgetPrivate *wd = w->d_func();
|
||||||
continue;
|
Q_ASSERT(wd->needsFlush);
|
||||||
QWidgetPrivate *wd = w->d_func();
|
r += wd->needsFlush->translated(w->mapTo(tlw, QPoint()));
|
||||||
Q_ASSERT(wd->needsFlush);
|
|
||||||
r += wd->needsFlush->translated(w->mapTo(tlw, QPoint()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widgetDirty) {
|
if (widgetDirty) {
|
||||||
@ -686,8 +683,8 @@ void QWidgetBackingStore::removeDirtyWidget(QWidget *w)
|
|||||||
if (!w)
|
if (!w)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dirtyWidgetsRemoveAll(w);
|
dirtyWidgets.removeAll(w);
|
||||||
dirtyOnScreenWidgetsRemoveAll(w);
|
dirtyOnScreenWidgets.removeAll(w);
|
||||||
dirtyRenderToTextureWidgets.removeAll(w);
|
dirtyRenderToTextureWidgets.removeAll(w);
|
||||||
resetWidget(w);
|
resetWidget(w);
|
||||||
|
|
||||||
@ -719,7 +716,6 @@ void QWidgetBackingStore::updateLists(QWidget *cur)
|
|||||||
|
|
||||||
QWidgetBackingStore::QWidgetBackingStore(QWidget *topLevel)
|
QWidgetBackingStore::QWidgetBackingStore(QWidget *topLevel)
|
||||||
: tlw(topLevel),
|
: tlw(topLevel),
|
||||||
dirtyOnScreenWidgets(0),
|
|
||||||
updateRequestSent(0),
|
updateRequestSent(0),
|
||||||
textureListWatcher(0),
|
textureListWatcher(0),
|
||||||
perfFrames(0)
|
perfFrames(0)
|
||||||
@ -737,8 +733,6 @@ QWidgetBackingStore::~QWidgetBackingStore()
|
|||||||
resetWidget(dirtyWidgets.at(c));
|
resetWidget(dirtyWidgets.at(c));
|
||||||
for (int c = 0; c < dirtyRenderToTextureWidgets.size(); ++c)
|
for (int c = 0; c < dirtyRenderToTextureWidgets.size(); ++c)
|
||||||
resetWidget(dirtyRenderToTextureWidgets.at(c));
|
resetWidget(dirtyRenderToTextureWidgets.at(c));
|
||||||
|
|
||||||
delete dirtyOnScreenWidgets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVector<QRect> getSortedRectsToScroll(const QRegion ®ion, int dx, int dy)
|
static QVector<QRect> getSortedRectsToScroll(const QRegion ®ion, int dx, int dy)
|
||||||
@ -1373,7 +1367,7 @@ void QWidgetBackingStore::doSync()
|
|||||||
*/
|
*/
|
||||||
void QWidgetBackingStore::flush(QWidget *widget)
|
void QWidgetBackingStore::flush(QWidget *widget)
|
||||||
{
|
{
|
||||||
const bool hasDirtyOnScreenWidgets = dirtyOnScreenWidgets && !dirtyOnScreenWidgets->isEmpty();
|
const bool hasDirtyOnScreenWidgets = !dirtyOnScreenWidgets.isEmpty();
|
||||||
bool flushed = false;
|
bool flushed = false;
|
||||||
|
|
||||||
// Flush the region in dirtyOnScreen.
|
// Flush the region in dirtyOnScreen.
|
||||||
@ -1400,15 +1394,13 @@ void QWidgetBackingStore::flush(QWidget *widget)
|
|||||||
if (!hasDirtyOnScreenWidgets)
|
if (!hasDirtyOnScreenWidgets)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int i = 0; i < dirtyOnScreenWidgets->size(); ++i) {
|
for (QWidget *w : qExchange(dirtyOnScreenWidgets, {})) {
|
||||||
QWidget *w = dirtyOnScreenWidgets->at(i);
|
|
||||||
QWidgetPrivate *wd = w->d_func();
|
QWidgetPrivate *wd = w->d_func();
|
||||||
Q_ASSERT(wd->needsFlush);
|
Q_ASSERT(wd->needsFlush);
|
||||||
QPlatformTextureList *widgetTexturesForNative = wd->textureChildSeen ? widgetTexturesFor(tlw, w) : 0;
|
QPlatformTextureList *widgetTexturesForNative = wd->textureChildSeen ? widgetTexturesFor(tlw, w) : 0;
|
||||||
qt_flush(w, *wd->needsFlush, store, tlw, widgetTexturesForNative, this);
|
qt_flush(w, *wd->needsFlush, store, tlw, widgetTexturesForNative, this);
|
||||||
*wd->needsFlush = QRegion();
|
*wd->needsFlush = QRegion();
|
||||||
}
|
}
|
||||||
dirtyOnScreenWidgets->clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -129,7 +129,7 @@ private:
|
|||||||
QRegion dirtyFromPreviousSync;
|
QRegion dirtyFromPreviousSync;
|
||||||
QVector<QWidget *> dirtyWidgets;
|
QVector<QWidget *> dirtyWidgets;
|
||||||
QVector<QWidget *> dirtyRenderToTextureWidgets;
|
QVector<QWidget *> dirtyRenderToTextureWidgets;
|
||||||
QVector<QWidget *> *dirtyOnScreenWidgets;
|
QVector<QWidget *> dirtyOnScreenWidgets;
|
||||||
QList<QWidget *> staticWidgets;
|
QList<QWidget *> staticWidgets;
|
||||||
QBackingStore *store;
|
QBackingStore *store;
|
||||||
uint updateRequestSent : 1;
|
uint updateRequestSent : 1;
|
||||||
@ -190,17 +190,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void dirtyWidgetsRemoveAll(QWidget *widget)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
while (i < dirtyWidgets.size()) {
|
|
||||||
if (dirtyWidgets.at(i) == widget)
|
|
||||||
dirtyWidgets.remove(i);
|
|
||||||
else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void addStaticWidget(QWidget *widget)
|
inline void addStaticWidget(QWidget *widget)
|
||||||
{
|
{
|
||||||
if (!widget)
|
if (!widget)
|
||||||
@ -246,26 +235,8 @@ private:
|
|||||||
if (!widget)
|
if (!widget)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!dirtyOnScreenWidgets) {
|
if (!dirtyOnScreenWidgets.contains(widget))
|
||||||
dirtyOnScreenWidgets = new QVector<QWidget *>;
|
dirtyOnScreenWidgets.append(widget);
|
||||||
dirtyOnScreenWidgets->append(widget);
|
|
||||||
} else if (!dirtyOnScreenWidgets->contains(widget)) {
|
|
||||||
dirtyOnScreenWidgets->append(widget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void dirtyOnScreenWidgetsRemoveAll(QWidget *widget)
|
|
||||||
{
|
|
||||||
if (!widget || !dirtyOnScreenWidgets)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
while (i < dirtyOnScreenWidgets->size()) {
|
|
||||||
if (dirtyOnScreenWidgets->at(i) == widget)
|
|
||||||
dirtyOnScreenWidgets->remove(i);
|
|
||||||
else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void resetWidget(QWidget *widget)
|
inline void resetWidget(QWidget *widget)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user