~mzanetti/unity8/workspace-backend-fix-imports

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (C) 2016 - Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License, as
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 * of the License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 */

#include "DebuggingController.h"

#include <QGuiApplication>
#include <QWindow>
#include <private/qquickwindow_p.h>
#include <private/qabstractanimationjob_p.h>
#include <private/qquickitem_p.h>
#include <private/qsgrenderer_p.h>


class ApplySceneGraphVisualizationJob : public QRunnable
{
public:
    ApplySceneGraphVisualizationJob(QQuickWindow *window, QByteArray renderMode)
        : m_window(window), m_renderMode(renderMode){}
    void run() override
    {
        qDebug() << "Setting custom render mode to:" << m_renderMode;

        QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(m_window);

        winPriv->customRenderMode = m_renderMode;
        delete winPriv->renderer;
        winPriv->renderer = nullptr;

        QTimer::singleShot(10, m_window, &QQuickWindow::update); // force another frame
    }

    QQuickWindow *m_window;
    QByteArray m_renderMode;
};

DebuggingController::DebuggingController(QObject *parent):
    UnityDBusObject(QStringLiteral("/com/canonical/Unity8/Debugging"), QStringLiteral("com.canonical.Unity8"), true, parent),
     m_logOverlay(false)
{
}

void DebuggingController::SetSceneGraphVisualizer(const QString &visualizer)
{
    QByteArray pendingRenderMode;
    QStringList supportedRenderModes = {"clip", "overdraw", "changes", "batches"};
    if (supportedRenderModes.contains(visualizer)) {
        pendingRenderMode = visualizer.toLatin1();
    }

    Q_FOREACH (QWindow *window, QGuiApplication::allWindows()) {
        QQuickWindow* qquickWindow = qobject_cast<QQuickWindow*>(window);
        if (qquickWindow) {

#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
            // Qt does some performance optimizations that break custom render modes.
            // Thus the optimizations are only applied if there is no custom render mode set.
            // So we need to make the scenegraph recheck whether a custom render mode is set.
            // We do this by simply recreating the renderer.
            qquickWindow->scheduleRenderJob(new ApplySceneGraphVisualizationJob(qquickWindow, pendingRenderMode),
                                            QQuickWindow::AfterSwapStage);
#else
            QQuickWindowPrivate *winPriv = QQuickWindowPrivate::get(qquickWindow);
            winPriv->customRenderMode = visualizer.toLatin1();
#endif
            qquickWindow->update();
        }
    }
}

void DebuggingController::SetSlowAnimations(bool slowAnimations)
{
    QUnifiedTimer::instance()->setSlowModeEnabled(slowAnimations);
}

void DebuggingController::SetLoggingFilterRules(const QString &filterRules)
{
    QLoggingCategory::setFilterRules(filterRules);
}

void DebuggingController::SetLogOverlay(bool logOverlay)
{
    if (logOverlay == m_logOverlay) {
        return;
    }

    m_logOverlay = logOverlay;
    Q_EMIT logOverlayChanged(m_logOverlay);
}