on xenial help sign in
apply the render mode more async
commit2bf3c1829f1495e7a8d3e405728e1b184d28ba12 authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 5 Dec 2016, 19:04 (10 years ago) parentdf0b199
2 files changed+37−12
src/DebuggingController.cpp+28−12 src/DebuggingController.h+9
src/DebuggingController.cpp+28−12
@@ -35,29 +35,45 @@ void DebuggingController::SetSceneGraphVisualizer(const QString &visualizer)
3535 Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
3636 QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
3737 if (qquickWindow) {
38− QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
39− winPriv->customRenderMode = visualizer.toLatin1();
40− qquickWindow->update();
4138
4239#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
4340 // Qt does some performance optimizations that break custom render modes.
4441 // Thus the optimizations are only applied if there is no custom render mode set.
4542 // So we need to make the scenegraph recheck whether a custom render mode is set.
4643 // We do this by simply recreating the renderer.
47−
48− QQuickItemPrivate *contentPriv = QQuickItemPrivate::get(qquickWindow->contentItem());
49− QSGNode *rootNode = contentPriv->itemNode();
50− while (rootNode->parent())
51− rootNode = rootNode->parent();
52−
53− delete winPriv->renderer;
54− winPriv->renderer = winPriv->context->createRenderer();
55− winPriv->renderer->setRootNode(static_cast<QSGRootNode *>(rootNode));
44+ QMutexLocker lock(&m_renderModeMutex);
45+ m_pendingRenderMode = visualizer;
46+ connect(qquickWindow, &QQuickWindow::beforeSynchronizing, this, &DebuggingController::applyRenderMode, Qt::DirectConnection);
47+#else
48+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
49+ winPriv->customRenderMode = visualizer.toLatin1();
5650#endif
51+ qquickWindow->update();
5752 }
5853 }
5954}
6055
56+void DebuggingController::applyRenderMode() {
57+ QQuickWindow *qquickWindow = qobject_cast<QQuickWindow*>(sender());
58+
59+ QMutexLocker lock(&m_renderModeMutex);
60+ disconnect(qquickWindow, &QQuickWindow::beforeSynchronizing, this, &DebuggingController::applyRenderMode);
61+
62+
63+#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
64+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
65+ QQuickItemPrivate *contentPriv = QQuickItemPrivate::get(qquickWindow->contentItem());
66+ QSGNode *rootNode = contentPriv->itemNode();
67+ while (rootNode->parent())
68+ rootNode = rootNode->parent();
69+
70+ winPriv->customRenderMode = m_pendingRenderMode.toLatin1();
71+ delete winPriv->renderer;
72+ winPriv->renderer = winPriv->context->createRenderer();
73+ winPriv->renderer->setRootNode(static_cast<QSGRootNode *>(rootNode));
74+#endif
75+}
76+
6177void DebuggingController::SetSlowAnimations(bool slowAnimations)
6278{
6379 QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
src/DebuggingController.h+9
@@ -22,6 +22,8 @@
2222
2323#include <QQmlEngine>
2424#include <QQmlExtensionPlugin>
25+#include <QQuickWindow>
26+#include <QMutex>
2527
2628#include "unitydbusobject.h"
2729
@@ -50,5 +52,12 @@ public Q_SLOTS:
5052 * Set the QLoggingCategory filter rules.
5153 */
5254 Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
55+
56+private Q_SLOTS:
57+ void applyRenderMode();
58+
59+private:
60+ QMutex m_renderModeMutex;
61+ QString m_pendingRenderMode;
5362};
5463#endif // DEBUGGINGCONTROLLER_H