1// Copyright (C) 2016 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 "qeglfsemulatorscreen.h"
5
6QT_BEGIN_NAMESPACE
7
8using namespace Qt::StringLiterals;
9
10QEglFSEmulatorScreen::QEglFSEmulatorScreen(const QJsonObject &screenDescription)
11 : QEglFSScreen(eglGetDisplay(EGL_DEFAULT_DISPLAY))
12 , m_id(0)
13{
14 initFromJsonObject(description: screenDescription);
15}
16
17QRect QEglFSEmulatorScreen::geometry() const
18{
19 return m_geometry;
20}
21
22QRect QEglFSEmulatorScreen::rawGeometry() const
23{
24 return QRect(QPoint(0, 0), m_geometry.size());
25}
26
27int QEglFSEmulatorScreen::depth() const
28{
29 return m_depth;
30}
31
32QImage::Format QEglFSEmulatorScreen::format() const
33{
34 return m_format;
35}
36
37QSizeF QEglFSEmulatorScreen::physicalSize() const
38{
39 return m_physicalSize;
40}
41
42QDpi QEglFSEmulatorScreen::logicalDpi() const
43{
44 return logicalBaseDpi();
45}
46
47QDpi QEglFSEmulatorScreen::logicalBaseDpi() const
48{
49 return QDpi(100, 100);
50}
51
52qreal QEglFSEmulatorScreen::refreshRate() const
53{
54 return m_refreshRate;
55}
56
57Qt::ScreenOrientation QEglFSEmulatorScreen::nativeOrientation() const
58{
59 return m_nativeOrientation;
60}
61
62Qt::ScreenOrientation QEglFSEmulatorScreen::orientation() const
63{
64 return m_orientation;
65}
66
67uint QEglFSEmulatorScreen::id() const
68{
69 return m_id;
70}
71
72QString QEglFSEmulatorScreen::name() const
73{
74 return m_description;
75}
76
77void QEglFSEmulatorScreen::initFromJsonObject(const QJsonObject &description)
78{
79 QJsonValue value;
80
81 value = description.value(key: "id"_L1);
82 if (!value.isUndefined() && value.isDouble())
83 m_id = value.toInt();
84
85 value = description.value(key: "description"_L1);
86 if (!value.isUndefined() && value.isString())
87 m_description = value.toString();
88
89 value = description.value(key: "geometry"_L1);
90 if (!value.isUndefined() && value.isObject()) {
91 QJsonObject geometryObject = value.toObject();
92 value = geometryObject.value(key: "x"_L1);
93 if (!value.isUndefined() && value.isDouble())
94 m_geometry.setX(value.toInt());
95 value = geometryObject.value(key: "y"_L1);
96 if (!value.isUndefined() && value.isDouble())
97 m_geometry.setY(value.toInt());
98 value = geometryObject.value(key: "width"_L1);
99 if (!value.isUndefined() && value.isDouble())
100 m_geometry.setWidth(value.toInt());
101 value = geometryObject.value(key: "height"_L1);
102 if (!value.isUndefined() && value.isDouble())
103 m_geometry.setHeight(value.toInt());
104 }
105
106 value = description.value(key: "depth"_L1);
107 if (!value.isUndefined() && value.isDouble())
108 m_depth = value.toInt();
109
110 value = description.value(key: "format"_L1);
111 if (!value.isUndefined() && value.isDouble())
112 m_format = static_cast<QImage::Format>(value.toInt());
113
114 value = description.value(key: "physicalSize"_L1);
115 if (!value.isUndefined() && value.isObject()) {
116 QJsonObject physicalSizeObject = value.toObject();
117 value = physicalSizeObject.value(key: "width"_L1);
118 if (!value.isUndefined() && value.isDouble())
119 m_physicalSize.setWidth(value.toInt());
120 value = physicalSizeObject.value(key: "height"_L1);
121 if (!value.isUndefined() && value.isDouble())
122 m_physicalSize.setHeight(value.toInt());
123 }
124
125
126 value = description.value(key: "refreshRate"_L1);
127 if (!value.isUndefined() && value.isDouble())
128 m_refreshRate = value.toDouble();
129
130 value = description.value(key: "nativeOrientation"_L1);
131 if (!value.isUndefined() && value.isDouble())
132 m_nativeOrientation = static_cast<Qt::ScreenOrientation>(value.toInt());
133
134 value = description.value(key: "orientation"_L1);
135 if (!value.isUndefined() && value.isDouble())
136 m_orientation = static_cast<Qt::ScreenOrientation>(value.toInt());
137}
138
139QT_END_NAMESPACE
140

source code of qtbase/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.cpp