on xenial help sign in
apply the render mode more async
2bf3c18Michael Zanetti
src/DebuggingController.cpp+28−12
@@ -35,29 +35,45 @@ void DebuggingController::SetSceneGraphVisualizer(const QString &visualizer)
35 Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
35 Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
36 QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
36 QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
37 if (qquickWindow) {
37 if (qquickWindow) {
38− QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
39− winPriv->customRenderMode = visualizer.toLatin1();
40− qquickWindow->update();
41
38
42#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
39#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
43 // Qt does some performance optimizations that break custom render modes.
40 // Qt does some performance optimizations that break custom render modes.
44 // Thus the optimizations are only applied if there is no custom render mode set.
41 // Thus the optimizations are only applied if there is no custom render mode set.
45 // So we need to make the scenegraph recheck whether a custom render mode is set.
42 // So we need to make the scenegraph recheck whether a custom render mode is set.
46 // We do this by simply recreating the renderer.
43 // We do this by simply recreating the renderer.
47−
44+ QMutexLocker lock(&m_renderModeMutex);
48− QQuickItemPrivate *contentPriv = QQuickItemPrivate::get(qquickWindow->contentItem());
45+ m_pendingRenderMode = visualizer;
49− QSGNode *rootNode = contentPriv->itemNode();
46+ connect(qquickWindow, &QQuickWindow::beforeSynchronizing, this, &DebuggingController::applyRenderMode, Qt::DirectConnection);
50− while (rootNode->parent())
47+#else
51− rootNode = rootNode->parent();
48+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
52−
49+ winPriv->customRenderMode = visualizer.toLatin1();
53− delete winPriv->renderer;
54− winPriv->renderer = winPriv->context->createRenderer();
55− winPriv->renderer->setRootNode(static_cast<QSGRootNode *>(rootNode));
56#endif
50#endif
51+ qquickWindow->update();
57 }
52 }
58 }
53 }
59}
54}
60
55
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+
61void DebuggingController::SetSlowAnimations(bool slowAnimations)
77void DebuggingController::SetSlowAnimations(bool slowAnimations)
62{
78{
63 QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
79 QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
src/DebuggingController.h+9
@@ -22,6 +22,8 @@
22
22
23#include <QQmlEngine>
23#include <QQmlEngine>
24#include <QQmlExtensionPlugin>
24#include <QQmlExtensionPlugin>
25+#include <QQuickWindow>
26+#include <QMutex>
25
27
26#include "unitydbusobject.h"
28#include "unitydbusobject.h"
27
29
@@ -50,5 +52,12 @@ public Q_SLOTS:
50 * Set the QLoggingCategory filter rules.
52 * Set the QLoggingCategory filter rules.
51 */
53 */
52 Q_SCRIPTABLE void SetLoggingFilterRules(const QString &filterRules);
54 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;
53};
62};
54#endif // DEBUGGINGCONTROLLER_H
63#endif // DEBUGGINGCONTROLLER_H