summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.cpp
blob: ff2f966477beb6e5967cc5ccdbc70eba09c32aac (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (C) 2016 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 "qeglfsemulatorscreen.h"

QT_BEGIN_NAMESPACE

using namespace Qt::StringLiterals;

QEglFSEmulatorScreen::QEglFSEmulatorScreen(const QJsonObject &screenDescription)
    : QEglFSScreen(eglGetDisplay(EGL_DEFAULT_DISPLAY))
    , m_id(0)
{
    initFromJsonObject(screenDescription);
}

QRect QEglFSEmulatorScreen::geometry() const
{
    return m_geometry;
}

QRect QEglFSEmulatorScreen::rawGeometry() const
{
    return QRect(QPoint(0, 0), m_geometry.size());
}

int QEglFSEmulatorScreen::depth() const
{
    return m_depth;
}

QImage::Format QEglFSEmulatorScreen::format() const
{
    return m_format;
}

QSizeF QEglFSEmulatorScreen::physicalSize() const
{
    return m_physicalSize;
}

QDpi QEglFSEmulatorScreen::logicalDpi() const
{
    return logicalBaseDpi();
}

QDpi QEglFSEmulatorScreen::logicalBaseDpi() const
{
    return QDpi(100, 100);
}

qreal QEglFSEmulatorScreen::refreshRate() const
{
    return m_refreshRate;
}

Qt::ScreenOrientation QEglFSEmulatorScreen::nativeOrientation() const
{
    return m_nativeOrientation;
}

Qt::ScreenOrientation QEglFSEmulatorScreen::orientation() const
{
    return m_orientation;
}

uint QEglFSEmulatorScreen::id() const
{
    return m_id;
}

QString QEglFSEmulatorScreen::name() const
{
    return m_description;
}

void QEglFSEmulatorScreen::initFromJsonObject(const QJsonObject &description)
{
    QJsonValue value;

    value = description.value("id"_L1);
    if (!value.isUndefined() && value.isDouble())
        m_id = value.toInt();

    value = description.value("description"_L1);
    if (!value.isUndefined() && value.isString())
        m_description = value.toString();

    value = description.value("geometry"_L1);
    if (!value.isUndefined() && value.isObject()) {
        QJsonObject geometryObject = value.toObject();
        value = geometryObject.value("x"_L1);
        if (!value.isUndefined() && value.isDouble())
            m_geometry.setX(value.toInt());
        value = geometryObject.value("y"_L1);
        if (!value.isUndefined() && value.isDouble())
            m_geometry.setY(value.toInt());
        value = geometryObject.value("width"_L1);
        if (!value.isUndefined() && value.isDouble())
            m_geometry.setWidth(value.toInt());
        value = geometryObject.value("height"_L1);
        if (!value.isUndefined() && value.isDouble())
            m_geometry.setHeight(value.toInt());
    }

    value = description.value("depth"_L1);
    if (!value.isUndefined() && value.isDouble())
        m_depth = value.toInt();

    value = description.value("format"_L1);
    if (!value.isUndefined() && value.isDouble())
        m_format = static_cast<QImage::Format>(value.toInt());

    value = description.value("physicalSize"_L1);
    if (!value.isUndefined() && value.isObject()) {
        QJsonObject physicalSizeObject = value.toObject();
        value = physicalSizeObject.value("width"_L1);
        if (!value.isUndefined() && value.isDouble())
            m_physicalSize.setWidth(value.toInt());
        value = physicalSizeObject.value("height"_L1);
        if (!value.isUndefined() && value.isDouble())
            m_physicalSize.setHeight(value.toInt());
    }


    value = description.value("refreshRate"_L1);
    if (!value.isUndefined() && value.isDouble())
        m_refreshRate = value.toDouble();

    value = description.value("nativeOrientation"_L1);
    if (!value.isUndefined() && value.isDouble())
        m_nativeOrientation = static_cast<Qt::ScreenOrientation>(value.toInt());

    value = description.value("orientation"_L1);
    if (!value.isUndefined() && value.isDouble())
        m_orientation = static_cast<Qt::ScreenOrientation>(value.toInt());
}

QT_END_NAMESPACE