summaryrefslogtreecommitdiffstats
path: root/src/window-lib/systemframetimerimpl.cpp
blob: 8ab8c559793bd41071daf51b303350715ca4c006 (plain)
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
// Copyright (C) 2023 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <qqmlinfo.h>
#include "systemframetimerimpl.h"
#include "applicationmanagerwindow.h"
#include "frametimer.h"
#include "inprocesswindow.h"
#if QT_CONFIG(am_multi_process)
#  include "waylandwindow.h"
#endif


QT_BEGIN_NAMESPACE_AM

SystemFrameTimerImpl::SystemFrameTimerImpl(FrameTimer *frameTimer)
    : FrameTimerImpl(frameTimer)
{ }

bool SystemFrameTimerImpl::connectToSystemWindow(QObject *window)
{
    if (qobject_cast<InProcessWindow *>(window)) {
        qmlWarning(frameTimer()) << "It makes no sense to measure the FPS of a WindowObject in single-process mode."
                                    " FrameTimer won't operate with the given window.";
        return true;
    }
#if QT_CONFIG(am_multi_process)
    if (auto *wlwin = qobject_cast<WaylandWindow *>(window)) {
        auto connectToWaylandSurface = [this](WaylandWindow *waylandWindow) {
            if (m_redrawConnection) {
                QObject::disconnect(m_redrawConnection);
                m_redrawConnection = { };
            }

            if (auto surface = waylandWindow ? waylandWindow->waylandSurface() : nullptr) {
                m_redrawConnection = QObject::connect(surface, &QWaylandQuickSurface::redraw,
                                                      frameTimer(), &FrameTimer::reportFrameSwap);
            }
        };

        m_surfaceChangeConnection = QObject::connect(wlwin, &WaylandWindow::waylandSurfaceChanged,
                                                     frameTimer(), [=]() {
            connectToWaylandSurface(wlwin);
        });
        connectToWaylandSurface(wlwin);
        return true;
    }
#endif
    return false;
}

void SystemFrameTimerImpl::disconnectFromSystemWindow(QObject *window)
{
    Q_UNUSED(window)
#if QT_CONFIG(am_multi_process)
    if (m_redrawConnection) {
        QObject::disconnect(m_redrawConnection);
        m_redrawConnection = { };
    }
    if (m_surfaceChangeConnection) {
        QObject::disconnect(m_surfaceChangeConnection);
        m_surfaceChangeConnection = { };
    }
#endif
}

QT_END_NAMESPACE_AM