@@ -0,0 +1,92 @@
2+ * Copyright (C) 2016 - Canonical Ltd.
4+ * This program is free software: you can redistribute it and/or modify it
5+ * under the terms of the GNU Lesser General Public License, as
6+ * published by the Free Software Foundation; either version 2.1 or 3.0
9+ * This program is distributed in the hope that it will be useful, but
10+ * WITHOUT ANY WARRANTY; without even the implied warranties of
11+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12+ * PURPOSE. See the applicable version of the GNU Lesser General Public
13+ * License for more details.
15+ * You should have received a copy of both the GNU Lesser General Public
16+ * License along with this program. If not, see <http://www.gnu.org/licenses/>
19+#include "DebuggingController.h"
21+#include <QGuiApplication>
23+#include <private/qquickwindow_p.h>
24+#include <private/qabstractanimationjob_p.h>
25+#include <private/qquickitem_p.h>
26+#include <private/qsgrenderer_p.h>
29+class ApplySceneGraphVisualizationJob : public QRunnable
32+ ApplySceneGraphVisualizationJob(QQuickWindow *window, QByteArray renderMode)
33+ : m_window(window), m_renderMode(renderMode){}
36+ qDebug() << "Setting custom render mode to:" << m_renderMode;
38+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(m_window);
40+ winPriv->customRenderMode = m_renderMode;
41+ delete winPriv->renderer;
42+ winPriv->renderer = nullptr;
44+ QTimer::singleShot(10, m_window, &QQuickWindow::update); // force another frame
47+ QQuickWindow *m_window;
48+ QByteArray m_renderMode;
51+DebuggingController::DebuggingController(QObject *parent):
52+ UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent)
56+void DebuggingController::SetSceneGraphVisualizer(const QString &visualizer)
58+ QByteArray pendingRenderMode;
59+ QStringList supportedRenderModes = {"clip", "overdraw", "changes", "batches"};
60+ if (supportedRenderModes.contains(visualizer)) {
61+ pendingRenderMode = visualizer.toLatin1();
64+ Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
65+ QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
68+#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
69+ // Qt does some performance optimizations that break custom render modes.
70+ // Thus the optimizations are only applied if there is no custom render mode set.
71+ // So we need to make the scenegraph recheck whether a custom render mode is set.
72+ // We do this by simply recreating the renderer.
73+ qquickWindow->scheduleRenderJob(new ApplySceneGraphVisualizationJob(qquickWindow, pendingRenderMode),
74+ QQuickWindow::AfterSwapStage);
76+ QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
77+ winPriv->customRenderMode = visualizer.toLatin1();
79+ qquickWindow->update();
84+void DebuggingController::SetSlowAnimations(bool slowAnimations)
86+ QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
89+void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
91+ QLoggingCategory::setFilterRules(filterRules);