Lomiri
Loading...
Searching...
No Matches
DebuggingController.cpp
1/*
2 * Copyright (C) 2016 Canonical Ltd.
3 *
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
7 * of the License.
8 *
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.
14 *
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/>
17 */
18
19#include "DebuggingController.h"
20
21#include <QGuiApplication>
22#include <QWindow>
23#include <private/qquickwindow_p.h>
24#include <private/qabstractanimationjob_p.h>
25#include <private/qquickitem_p.h>
26#include <private/qsgrenderer_p.h>
27
28
29class ApplySceneGraphVisualizationJob : public QRunnable
30{
31public:
32 ApplySceneGraphVisualizationJob(QQuickWindow *window, QByteArray renderMode)
33 : m_window(window), m_renderMode(renderMode){}
34 void run() override
35 {
36 qDebug() << "Setting custom render mode to:" << m_renderMode;
37
38 QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(m_window);
39
40 winPriv->customRenderMode = m_renderMode;
41 delete winPriv->renderer;
42 winPriv->renderer = nullptr;
43
44 QTimer::singleShot(10, m_window, &QQuickWindow::update); // force another frame
45 }
46
47 QQuickWindow *m_window;
48 QByteArray m_renderMode;
49};
50
51DebuggingController::DebuggingController(QObject *parent):
52 LomiriDBusObject(QStringLiteral("/com/lomiri/Shell/Debugging"), QStringLiteral("com.lomiri.Shell"), true, parent)
53{
54}
55
56void DebuggingController::SetSceneGraphVisualizer(const QString &visualizer)
57{
58 QByteArray pendingRenderMode;
59 QStringList supportedRenderModes = {"clip", "overdraw", "changes", "batches"};
60 if (supportedRenderModes.contains(visualizer)) {
61 pendingRenderMode = visualizer.toLatin1();
62 }
63
64 Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
65 QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
66 if (qquickWindow) {
67
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);
75#else
76 QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
77 winPriv->customRenderMode = visualizer.toLatin1();
78#endif
79 qquickWindow->update();
80 }
81 }
82}
83
84void DebuggingController::SetSlowAnimations(bool slowAnimations)
85{
86 QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
87}
88
89void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
90{
91 QLoggingCategory::setFilterRules(filterRules);
92}