summaryrefslogtreecommitdiffstats
path: root/src/multimedia/platform/qplatformsurfacecapture.cpp
blob: a56f48b62b419b03524eeeee37e73dd9b29629df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "platform/qplatformsurfacecapture_p.h"
#include "qvideoframe.h"
#include "qguiapplication.h"
#include "qdebug.h"

QT_BEGIN_NAMESPACE

QPlatformSurfaceCapture::QPlatformSurfaceCapture(Source initialSource) : m_source(initialSource)
{
    Q_ASSERT(std::visit([](auto source) { return source == decltype(source){}; }, initialSource));
    qRegisterMetaType<QVideoFrame>();
}

void QPlatformSurfaceCapture::setActive(bool active)
{
    if (m_active == active)
        return;

    if (!setActiveInternal(active))
        return;

    m_active = active;
    emit activeChanged(active);
}

bool QPlatformSurfaceCapture::isActive() const
{
    return m_active;
}

void QPlatformSurfaceCapture::setSource(Source source)
{
    Q_ASSERT(source.index() == m_source.index());

    if (m_source == source)
        return;

    if (m_active)
        setActiveInternal(false);

    m_source = source;

    if (m_active && !setActiveInternal(true)) {
        m_active = false;
        emit activeChanged(false);
    }

    std::visit([this](auto source) { emit sourceChanged(source); }, m_source);
}

QPlatformSurfaceCapture::Error QPlatformSurfaceCapture::error() const
{
    return m_error.code();
}

QString QPlatformSurfaceCapture::errorString() const
{
    return m_error.description();
}

void QPlatformSurfaceCapture::updateError(Error error, const QString &errorString)
{
    m_error.setAndNotify(error, errorString, *this);
}

bool QPlatformSurfaceCapture::checkScreenWithError(ScreenSource &screen)
{
    if (!screen)
        screen = QGuiApplication::primaryScreen();

    if (screen)
        return true;

    updateError(NotFound, QLatin1String("No screens found"));
    return false;
}

QT_END_NAMESPACE

#include "moc_qplatformsurfacecapture_p.cpp"