Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dprofileradapter.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include <QCoreApplication>
7#include <private/qqmldebugconnector_p.h>
8#include <private/qversionedpacket_p.h>
9#include <private/qqmldebugserviceinterfaces_p.h>
10
12
13using QQmlDebugPacket = QVersionedPacket<QQmlDebugConnector>;
14
15QQuick3DProfilerAdapter::QQuick3DProfilerAdapter(QObject *parent) :
16 QQmlAbstractProfilerAdapter(parent), next(0)
17{
18 QQuick3DProfiler::initialize(this);
19 // We can always do DirectConnection here as all methods are protected by mutexes
20 connect(this, &QQmlAbstractProfilerAdapter::profilingEnabled,
21 QQuick3DProfiler::s_instance, &QQuick3DProfiler::startProfilingImpl, Qt::DirectConnection);
22 connect(this, &QQmlAbstractProfilerAdapter::profilingEnabledWhileWaiting,
23 QQuick3DProfiler::s_instance, &QQuick3DProfiler::startProfilingImpl, Qt::DirectConnection);
24 connect(this, &QQmlAbstractProfilerAdapter::referenceTimeKnown,
25 QQuick3DProfiler::s_instance, &QQuick3DProfiler::setTimer, Qt::DirectConnection);
26 connect(this, &QQmlAbstractProfilerAdapter::profilingDisabled,
27 QQuick3DProfiler::s_instance, &QQuick3DProfiler::stopProfilingImpl, Qt::DirectConnection);
28 connect(this, &QQmlAbstractProfilerAdapter::profilingDisabledWhileWaiting,
29 QQuick3DProfiler::s_instance, &QQuick3DProfiler::stopProfilingImpl, Qt::DirectConnection);
30 connect(this, &QQmlAbstractProfilerAdapter::dataRequested,
31 QQuick3DProfiler::s_instance, &QQuick3DProfiler::reportDataImpl, Qt::DirectConnection);
32 connect(QQuick3DProfiler::s_instance, &QQuick3DProfiler::dataReady,
33 this, &QQuick3DProfilerAdapter::receiveData, Qt::DirectConnection);
34}
35
36QQuick3DProfilerAdapter::~QQuick3DProfilerAdapter()
37{
38 if (service)
39 service->removeGlobalProfiler(this);
40}
41
42
43// convert to QByteArrays that can be sent to the debug client
44static void QQuick3DProfilerDataToByteArrays(const QQuick3DProfilerData &data,
45 QList<QByteArray> &messages,
46 const QHash<int, QByteArray> &eventData)
47{
48 QQmlDebugPacket ds;
49
50 // packet header
51 ds << data.time << data.messageType << data.detailType;
52 // packet data
53 switch (data.messageType) {
54 case QQuick3DProfiler::Event:
55 break;
56 case QQuick3DProfiler::Quick3DFrame:
57 if (data.detailType == QQuick3DProfiler::Quick3DEventData) {
58 ds << eventData[data.subdata1];
59 } else {
60 ds << data.subdata1 << data.subdata2;
61 if (data.ids[0] || data.ids[1])
62 ds << data.ids[0] << data.ids[1];
63 }
64 break;
65 default:
66 Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type.");
67 break;
68 }
69
70 messages.append(ds.squeezedData());
71 ds.clear();
72}
73
74qint64 QQuick3DProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages)
75{
76 while (next < m_data.size()) {
77 if (m_data[next].time <= until && messages.size() <= s_numMessagesPerBatch)
78 QQuick3DProfilerDataToByteArrays(m_data[next++], messages, m_eventData);
79 else
80 return m_data[next].time;
81 }
82 m_data.clear();
83 next = 0;
84 return -1;
85}
86
87void QQuick3DProfilerAdapter::receiveData(const QVector<QQuick3DProfilerData> &new_data, const QHash<int, QByteArray> &eventData)
88{
89 if (m_data.isEmpty())
90 m_data = new_data;
91 else
92 m_data.append(new_data);
93 m_eventData = eventData;
94 service->dataReady(this);
95}
96
97QT_END_NAMESPACE
static void QQuick3DProfilerDataToByteArrays(const QQuick3DProfilerData &data, QList< QByteArray > &messages, const QHash< int, QByteArray > &eventData)