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// Qt-Security score:significant reason:default
4
5
7
8#include <QCoreApplication>
9#include <private/qqmldebugconnector_p.h>
10#include <private/qversionedpacket_p.h>
11#include <private/qqmldebugserviceinterfaces_p.h>
12
14
15using QQmlDebugPacket = QVersionedPacket<QQmlDebugConnector>;
16
17QQuick3DProfilerAdapter::QQuick3DProfilerAdapter(QObject *parent) :
18 QQmlAbstractProfilerAdapter(parent), next(0)
19{
20 QQuick3DProfiler::initialize(this);
21 // We can always do DirectConnection here as all methods are protected by mutexes
22 connect(this, &QQmlAbstractProfilerAdapter::profilingEnabled,
23 QQuick3DProfiler::s_instance, &QQuick3DProfiler::startProfilingImpl, Qt::DirectConnection);
24 connect(this, &QQmlAbstractProfilerAdapter::profilingEnabledWhileWaiting,
25 QQuick3DProfiler::s_instance, &QQuick3DProfiler::startProfilingImpl, Qt::DirectConnection);
26 connect(this, &QQmlAbstractProfilerAdapter::referenceTimeKnown,
27 QQuick3DProfiler::s_instance, &QQuick3DProfiler::setTimer, Qt::DirectConnection);
28 connect(this, &QQmlAbstractProfilerAdapter::profilingDisabled,
29 QQuick3DProfiler::s_instance, &QQuick3DProfiler::stopProfilingImpl, Qt::DirectConnection);
30 connect(this, &QQmlAbstractProfilerAdapter::profilingDisabledWhileWaiting,
31 QQuick3DProfiler::s_instance, &QQuick3DProfiler::stopProfilingImpl, Qt::DirectConnection);
32 connect(this, &QQmlAbstractProfilerAdapter::dataRequested,
33 QQuick3DProfiler::s_instance, &QQuick3DProfiler::reportDataImpl, Qt::DirectConnection);
34 connect(QQuick3DProfiler::s_instance, &QQuick3DProfiler::dataReady,
35 this, &QQuick3DProfilerAdapter::receiveData, Qt::DirectConnection);
36}
37
38QQuick3DProfilerAdapter::~QQuick3DProfilerAdapter()
39{
40 if (service)
41 service->removeGlobalProfiler(this);
42}
43
44
45// convert to QByteArrays that can be sent to the debug client
46static void QQuick3DProfilerDataToByteArrays(const QQuick3DProfilerData &data,
47 QList<QByteArray> &messages,
48 const QHash<int, QByteArray> &eventData)
49{
50 QQmlDebugPacket ds;
51
52 // packet header
53 ds << data.time << data.messageType << data.detailType;
54 // packet data
55 switch (data.messageType) {
56 case QQuick3DProfiler::Event:
57 break;
58 case QQuick3DProfiler::Quick3DFrame:
59 if (data.detailType == QQuick3DProfiler::Quick3DEventData) {
60 ds << eventData[data.subdata1];
61 } else {
62 ds << data.subdata1 << data.subdata2;
63 if (data.ids[0] || data.ids[1])
64 ds << data.ids[0] << data.ids[1];
65 }
66 break;
67 default:
68 Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type.");
69 break;
70 }
71
72 messages.append(ds.squeezedData());
73 ds.clear();
74}
75
76qint64 QQuick3DProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages)
77{
78 while (next < m_data.size()) {
79 if (m_data[next].time <= until && messages.size() <= s_numMessagesPerBatch)
80 QQuick3DProfilerDataToByteArrays(m_data[next++], messages, m_eventData);
81 else
82 return m_data[next].time;
83 }
84 m_data.clear();
85 next = 0;
86 return -1;
87}
88
89void QQuick3DProfilerAdapter::receiveData(const QVector<QQuick3DProfilerData> &new_data, const QHash<int, QByteArray> &eventData)
90{
91 if (m_data.isEmpty())
92 m_data = new_data;
93 else
94 m_data.append(new_data);
95 m_eventData = eventData;
96 service->dataReady(this);
97}
98
99QT_END_NAMESPACE
Combined button and popup list for selecting options.
static void QQuick3DProfilerDataToByteArrays(const QQuick3DProfilerData &data, QList< QByteArray > &messages, const QHash< int, QByteArray > &eventData)