| 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 | #include "platform/qplatformsurfacecapture_p.h" |
| 5 | #include "qvideoframe.h" |
| 6 | #include "qguiapplication.h" |
| 7 | #include "qdebug.h" |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | QPlatformSurfaceCapture::QPlatformSurfaceCapture(Source initialSource) : m_source(initialSource) |
| 12 | { |
| 13 | Q_ASSERT(std::visit([](auto source) { return source == decltype(source){}; }, initialSource)); |
| 14 | qRegisterMetaType<QVideoFrame>(); |
| 15 | } |
| 16 | |
| 17 | void QPlatformSurfaceCapture::setActive(bool active) |
| 18 | { |
| 19 | if (m_active == active) |
| 20 | return; |
| 21 | |
| 22 | if (!setActiveInternal(active)) |
| 23 | return; |
| 24 | |
| 25 | m_active = active; |
| 26 | emit activeChanged(active); |
| 27 | } |
| 28 | |
| 29 | bool QPlatformSurfaceCapture::isActive() const |
| 30 | { |
| 31 | return m_active; |
| 32 | } |
| 33 | |
| 34 | void QPlatformSurfaceCapture::setSource(Source source) |
| 35 | { |
| 36 | Q_ASSERT(source.index() == m_source.index()); |
| 37 | |
| 38 | if (m_source == source) |
| 39 | return; |
| 40 | |
| 41 | if (m_active) |
| 42 | setActiveInternal(false); |
| 43 | |
| 44 | m_source = source; |
| 45 | |
| 46 | if (m_active && !setActiveInternal(true)) { |
| 47 | m_active = false; |
| 48 | emit activeChanged(false); |
| 49 | } |
| 50 | |
| 51 | std::visit(visitor: [this](auto source) { emit sourceChanged(source); }, variants&: m_source); |
| 52 | } |
| 53 | |
| 54 | QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error() const |
| 55 | { |
| 56 | return m_error.code(); |
| 57 | } |
| 58 | |
| 59 | QString QPlatformSurfaceCapture::errorString() const |
| 60 | { |
| 61 | return m_error.description(); |
| 62 | } |
| 63 | |
| 64 | void QPlatformSurfaceCapture::updateError(Error error, const QString &errorString) |
| 65 | { |
| 66 | m_error.setAndNotify(code: error, description: errorString, notifier&: *this); |
| 67 | } |
| 68 | |
| 69 | bool QPlatformSurfaceCapture::checkScreenWithError(ScreenSource &screen) |
| 70 | { |
| 71 | if (!screen) |
| 72 | screen = QGuiApplication::primaryScreen(); |
| 73 | |
| 74 | if (screen) |
| 75 | return true; |
| 76 | |
| 77 | updateError(error: NotFound, errorString: QLatin1String("No screens found")); |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | QT_END_NAMESPACE |
| 82 | |
| 83 | #include "moc_qplatformsurfacecapture_p.cpp" |
| 84 |
