summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-24 22:06:09 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-08-14 20:36:19 +0200
commit94d7603d5114eacaf648e0b0d2dcae5e161e0217 (patch)
tree92f56c03deef3dbdc44a2c2a2ccc5c224b9897e9
parent1d496a4a1085e6a3ebaa0448b8d6c4da6f8f50d6 (diff)
QWidget: replace manual memory management with unique_ptr [1/N]: widgetTextures
Use a vector<unique_ptr> (QVector cannot hold move-only classes), adapt to different API. Change-Id: Iece4b1bfcb35a02aac05935963e1e7f8c986b18d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/widgets/kernel/qwidget.cpp1
-rw-r--r--src/widgets/kernel/qwidget_p.h5
-rw-r--r--src/widgets/kernel/qwidgetbackingstore.cpp25
3 files changed, 17 insertions, 14 deletions
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;
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 7cb9a3895a..8fb325c763 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -75,6 +75,9 @@
#include <private/qgesture_p.h>
#include <qpa/qplatformbackingstore.h>
+#include <vector>
+#include <memory>
+
QT_BEGIN_NAMESPACE
// Extra QWidget data
@@ -184,7 +187,7 @@ struct QTLWExtra {
// ### TODO replace initialScreenIndex with QScreen *, in case the screens change at runtime
int initialScreenIndex; // Screen number when passing a QDesktop[Screen]Widget as parent.
- QVector<QPlatformTextureList *> widgetTextures;
+ std::vector<std::unique_ptr<QPlatformTextureList>> widgetTextures;
// *************************** Cross-platform bit fields ****************************
uint opacity : 8;
diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp
index ee54d9dce3..8b0094a93c 100644
--- a/src/widgets/kernel/qwidgetbackingstore.cpp
+++ b/src/widgets/kernel/qwidgetbackingstore.cpp
@@ -68,6 +68,8 @@
# include <qpa/qplatformnativeinterface.h>
#endif
+#include <private/qmemory_p.h>
+
QT_BEGIN_NAMESPACE
extern QRegion qt_dirtyRegion(QWidget *);
@@ -963,15 +965,15 @@ static void findAllTextureWidgetsRecursively(QWidget *tlw, QWidget *widget)
// textureChildSeen does not take native child widgets into account and that's good.
if (QWidgetPrivate::get(widget)->textureChildSeen) {
QVector<QWidget *> nativeChildren;
- QScopedPointer<QPlatformTextureList> tl(new QPlatformTextureList);
+ auto tl = qt_make_unique<QPlatformTextureList>();
// Look for texture widgets (incl. widget itself) from 'widget' down,
// but skip subtrees with a parent of a native child widget.
- findTextureWidgetsRecursively(tlw, widget, tl.data(), &nativeChildren);
+ findTextureWidgetsRecursively(tlw, widget, tl.get(), &nativeChildren);
// tl may be empty regardless of textureChildSeen if we have native or hidden children.
if (!tl->isEmpty())
- QWidgetPrivate::get(tlw)->topData()->widgetTextures.append(tl.take());
+ QWidgetPrivate::get(tlw)->topData()->widgetTextures.push_back(std::move(tl));
// Native child widgets, if there was any, get their own separate QPlatformTextureList.
- foreach (QWidget *ncw, nativeChildren) {
+ for (QWidget *ncw : qAsConst(nativeChildren)) {
if (QWidgetPrivate::get(ncw)->textureChildSeen)
findAllTextureWidgetsRecursively(tlw, ncw);
}
@@ -980,12 +982,12 @@ static void findAllTextureWidgetsRecursively(QWidget *tlw, QWidget *widget)
static QPlatformTextureList *widgetTexturesFor(QWidget *tlw, QWidget *widget)
{
- foreach (QPlatformTextureList *tl, QWidgetPrivate::get(tlw)->topData()->widgetTextures) {
+ for (const auto &tl : QWidgetPrivate::get(tlw)->topData()->widgetTextures) {
Q_ASSERT(!tl->isEmpty());
for (int i = 0; i < tl->count(); ++i) {
QWidget *w = static_cast<QWidget *>(tl->source(i));
if ((hasPlatformWindow(w) && w == widget) || (!hasPlatformWindow(w) && w->nativeParentWidget() == widget))
- return tl;
+ return tl.get();
}
}
@@ -1064,14 +1066,14 @@ bool QWidgetBackingStore::syncAllowed()
if (textureListWatcher && !textureListWatcher->isLocked()) {
textureListWatcher->deleteLater();
textureListWatcher = 0;
- } else if (!tlwExtra->widgetTextures.isEmpty()) {
+ } else if (!tlwExtra->widgetTextures.empty()) {
bool skipSync = false;
- foreach (QPlatformTextureList *tl, tlwExtra->widgetTextures) {
+ for (const auto &tl : tlwExtra->widgetTextures) {
if (tl->isLocked()) {
if (!textureListWatcher)
textureListWatcher = new QPlatformTextureListWatcher(this);
if (!textureListWatcher->isLocked())
- textureListWatcher->watch(tl);
+ textureListWatcher->watch(tl.get());
skipSync = true;
}
}
@@ -1243,7 +1245,6 @@ void QWidgetBackingStore::doSync()
// The search is cut at native widget boundaries, meaning that each native child widget
// has its own list for the subtree below it.
QTLWExtra *tlwExtra = tlw->d_func()->topData();
- qDeleteAll(tlwExtra->widgetTextures);
tlwExtra->widgetTextures.clear();
findAllTextureWidgetsRecursively(tlw, tlw);
qt_window_private(tlw->windowHandle())->compositing = false; // will get updated in qt_flush()
@@ -1289,7 +1290,7 @@ void QWidgetBackingStore::doSync()
}
#ifndef QT_NO_OPENGL
- foreach (QPlatformTextureList *tl, tlwExtra->widgetTextures) {
+ for (const auto &tl : tlwExtra->widgetTextures) {
for (int i = 0; i < tl->count(); ++i) {
QWidget *w = static_cast<QWidget *>(tl->source(i));
if (dirtyRenderToTextureWidgets.contains(w)) {
@@ -1386,7 +1387,7 @@ void QWidgetBackingStore::flush(QWidget *widget)
// Render-to-texture widgets are not in dirtyOnScreen so flush if we have not done it above.
if (!flushed && !hasDirtyOnScreenWidgets) {
#ifndef QT_NO_OPENGL
- if (!tlw->d_func()->topData()->widgetTextures.isEmpty()) {
+ if (!tlw->d_func()->topData()->widgetTextures.empty()) {
QPlatformTextureList *tl = widgetTexturesFor(tlw, tlw);
if (tl) {
QWidget *target = widget ? widget : tlw;