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
qplatformsurfacecapture.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtMultimedia/qvideoframe.h>
7#include <QtGui/qguiapplication.h>
8#include <QtCore/qdebug.h>
9
11
12QPlatformSurfaceCapture::QPlatformSurfaceCapture(Source initialSource) : m_source(initialSource)
13{
14 Q_ASSERT(std::visit([](const auto &source) {
15 return source == decltype(source){};
16 }, initialSource));
17 qRegisterMetaType<QVideoFrame>();
18}
19
20void QPlatformSurfaceCapture::setActive(bool active)
21{
22 if (m_active == active)
23 return;
24
25 if (!setActiveInternal(active))
26 return;
27
28 m_active = active;
29 emit activeChanged(active);
30}
31
32bool QPlatformSurfaceCapture::isActive() const
33{
34 return m_active;
35}
36
37void QPlatformSurfaceCapture::setSource(Source source)
38{
39 Q_ASSERT(source.index() == m_source.index());
40
41 if (m_source == source)
42 return;
43
44 if (m_active)
45 setActiveInternal(false);
46
47 m_source = std::move(source);
48
49 if (m_active && !setActiveInternal(true)) {
50 m_active = false;
51 emit activeChanged(false);
52 }
53
54 std::visit([this](const auto &source) {
55 emit sourceChanged(source);
56 }, m_source);
57}
58
59QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error() const
60{
61 return m_error.code();
62}
63
64QString QPlatformSurfaceCapture::errorString() const
65{
66 return m_error.description();
67}
68
69void QPlatformSurfaceCapture::setFrameRate(std::optional<qreal> frameRate)
70{
71 if (m_frameRate == frameRate)
72 return;
73
74 m_frameRate = frameRate;
75 emit frameRateChanged();
76}
77
78std::optional<qreal> QPlatformSurfaceCapture::frameRate() const
79{
80 return m_frameRate;
81}
82
83void QPlatformSurfaceCapture::updateError(Error error, const QString &errorString)
84{
85 m_error.setAndNotify(error, errorString, *this);
86}
87
88bool QPlatformSurfaceCapture::checkScreenWithError(ScreenSource &screen)
89{
90 if (!screen)
91 screen = QGuiApplication::primaryScreen();
92
93 if (screen)
94 return true;
95
96 updateError(NotFound, QLatin1String("No screens found"));
97 return false;
98}
99
100QT_END_NAMESPACE
101
102#include "moc_qplatformsurfacecapture_p.cpp"
Combined button and popup list for selecting options.