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 "qplatformvideosource_p.h" |
19 | #include "qscreen.h" |
20 | #include "qcapturablewindow.h" |
21 | #include "qpointer.h" |
22 | |
23 | #include <optional> |
24 | #include <variant> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QVideoFrame; |
29 | |
30 | class Q_MULTIMEDIA_EXPORT QPlatformSurfaceCapture : public QPlatformVideoSource |
31 | { |
32 | Q_OBJECT |
33 | |
34 | public: |
35 | enum 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 | void setActive(bool active) override; |
51 | bool isActive() const override; |
52 | |
53 | void setSource(Source source); |
54 | |
55 | template<typename Type> |
56 | Type source() const { |
57 | return *q_check_ptr(std::get_if<Type>(&m_source)); |
58 | } |
59 | |
60 | Source source() const { return m_source; } |
61 | |
62 | Error error() const; |
63 | QString errorString() const; |
64 | |
65 | protected: |
66 | virtual bool setActiveInternal(bool) = 0; |
67 | |
68 | bool checkScreenWithError(ScreenSource &screen); |
69 | |
70 | public Q_SLOTS: |
71 | void updateError(Error error, const QString &errorString); |
72 | |
73 | Q_SIGNALS: |
74 | void sourceChanged(WindowSource); |
75 | void sourceChanged(ScreenSource); |
76 | void errorChanged(); |
77 | void errorOccurred(Error error, QString errorString); |
78 | |
79 | private: |
80 | Error m_error = NoError; |
81 | QString m_errorString; |
82 | Source m_source; |
83 | bool m_active = false; |
84 | }; |
85 | |
86 | QT_END_NAMESPACE |
87 | |
88 | #endif // QPLATFORMSURFACECAPTURE_H |
89 | |