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_p.h
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
4#ifndef QPLATFORMSURFACECAPTURE_H
5#define QPLATFORMSURFACECAPTURE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/private/qerrorinfo_p.h>
19#include <QtMultimedia/private/qplatformvideosource_p.h>
20#include <QtMultimedia/qcapturablewindow.h>
21#include <QtGui/qscreen.h>
22#include <QtCore/qpointer.h>
23
24#include <variant>
25
26QT_BEGIN_NAMESPACE
27
28class QVideoFrame;
29
30class Q_MULTIMEDIA_EXPORT QPlatformSurfaceCapture : public QPlatformVideoSource
31{
32 Q_OBJECT
33
34public:
35 enum class Error {
36 NoError = 0,
37 InternalError = 1,
38 CapturingNotSupported = 2,
39 CaptureFailed = 4,
40 NotFound = 5,
41 };
42
43 using ScreenSource = QPointer<QScreen>;
44 using WindowSource = QCapturableWindow;
45
46 using Source = std::variant<ScreenSource, WindowSource>;
47
48 explicit QPlatformSurfaceCapture(Source initialSource);
49
50 // When capturing a Window, we should never include the drop shadow of that Window.
51 // Ideally, when configured with QCapturableWindow constructed from a QWindow,
52 // our output frames should always have sizes matching that QWindow.
53 //
54 // If the property ignoreCursor() is set to true, we should provide a hint for the backend
55 // to not capture the cursor if possible.
56 //
57 // This method must be implemented as blocking. If the function fails for some reason,
58 // the error property can not be set to NoError.
59 void setActive(bool active) override;
60 bool isActive() const override;
61
62 void setSource(Source source);
63
64 template<typename Type>
65 Type source() const {
66 Q_ASSERT(std::holds_alternative<Type>(m_source));
67 return *std::get_if<Type>(&m_source);
68 }
69
70 Source source() const { return m_source; }
71
72 Error error() const;
73 QString errorString() const final;
74
75 void setFrameRate(std::optional<qreal>);
76 [[nodiscard]] std::optional<qreal> frameRate() const;
77
78 void setIgnoreCursor(bool);
79 // Applied on next stream start.
80 [[nodiscard]] bool ignoreCursor() const;
81
82protected:
83 virtual bool setActiveInternal(bool) = 0;
84
85 bool checkScreenWithError(ScreenSource &screen);
86
87public Q_SLOTS:
88 void updateError(Error error, const QString &errorString);
89
90Q_SIGNALS:
91 void sourceChanged(WindowSource);
92 void sourceChanged(ScreenSource);
93 void errorOccurred(Error error, QString errorString);
94 void frameRateChanged(std::optional<qreal>);
95
96private:
97 std::optional<qreal> m_frameRate;
98 QErrorInfo<Error> m_error;
99 Source m_source;
100 bool m_active = false;
101
102 // While not part of public API, this setting tends to impact
103 // integration tests.
104 bool m_ignoreCursor = false;
105};
106
107QT_END_NAMESPACE
108
109#endif // QPLATFORMSURFACECAPTURE_H
Combined button and popup list for selecting options.