1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qeglfsemulatorscreen.h"
41
42QT_BEGIN_NAMESPACE
43
44QEglFSEmulatorScreen::QEglFSEmulatorScreen(const QJsonObject &screenDescription)
45 : QEglFSScreen(eglGetDisplay(EGL_DEFAULT_DISPLAY))
46 , m_id(0)
47{
48 initFromJsonObject(description: screenDescription);
49}
50
51QRect QEglFSEmulatorScreen::geometry() const
52{
53 return m_geometry;
54}
55
56QRect QEglFSEmulatorScreen::rawGeometry() const
57{
58 return QRect(QPoint(0, 0), m_geometry.size());
59}
60
61int QEglFSEmulatorScreen::depth() const
62{
63 return m_depth;
64}
65
66QImage::Format QEglFSEmulatorScreen::format() const
67{
68 return m_format;
69}
70
71QSizeF QEglFSEmulatorScreen::physicalSize() const
72{
73 return m_physicalSize;
74}
75
76QDpi QEglFSEmulatorScreen::logicalDpi() const
77{
78 const QSizeF ps = m_physicalSize;
79 const QSize s = m_geometry.size();
80
81 if (!ps.isEmpty() && !s.isEmpty())
82 return QDpi(25.4 * s.width() / ps.width(),
83 25.4 * s.height() / ps.height());
84 else
85 return QDpi(100, 100);
86}
87
88qreal QEglFSEmulatorScreen::pixelDensity() const
89{
90 return m_pixelDensity;
91}
92
93qreal QEglFSEmulatorScreen::refreshRate() const
94{
95 return m_refreshRate;
96}
97
98Qt::ScreenOrientation QEglFSEmulatorScreen::nativeOrientation() const
99{
100 return m_nativeOrientation;
101}
102
103Qt::ScreenOrientation QEglFSEmulatorScreen::orientation() const
104{
105 return m_orientation;
106}
107
108uint QEglFSEmulatorScreen::id() const
109{
110 return m_id;
111}
112
113QString QEglFSEmulatorScreen::name() const
114{
115 return m_description;
116}
117
118void QEglFSEmulatorScreen::initFromJsonObject(const QJsonObject &description)
119{
120 QJsonValue value;
121
122 value = description.value(key: QLatin1String("id"));
123 if (!value.isUndefined() && value.isDouble())
124 m_id = value.toInt();
125
126 value = description.value(key: QLatin1String("description"));
127 if (!value.isUndefined() && value.isString())
128 m_description = value.toString();
129
130 value = description.value(key: QLatin1String("geometry"));
131 if (!value.isUndefined() && value.isObject()) {
132 QJsonObject geometryObject = value.toObject();
133 value = geometryObject.value(key: QLatin1String("x"));
134 if (!value.isUndefined() && value.isDouble())
135 m_geometry.setX(value.toInt());
136 value = geometryObject.value(key: QLatin1String("y"));
137 if (!value.isUndefined() && value.isDouble())
138 m_geometry.setY(value.toInt());
139 value = geometryObject.value(key: QLatin1String("width"));
140 if (!value.isUndefined() && value.isDouble())
141 m_geometry.setWidth(value.toInt());
142 value = geometryObject.value(key: QLatin1String("height"));
143 if (!value.isUndefined() && value.isDouble())
144 m_geometry.setHeight(value.toInt());
145 }
146
147 value = description.value(key: QLatin1String("depth"));
148 if (!value.isUndefined() && value.isDouble())
149 m_depth = value.toInt();
150
151 value = description.value(key: QLatin1String("format"));
152 if (!value.isUndefined() && value.isDouble())
153 m_format = static_cast<QImage::Format>(value.toInt());
154
155 value = description.value(key: QLatin1String("physicalSize"));
156 if (!value.isUndefined() && value.isObject()) {
157 QJsonObject physicalSizeObject = value.toObject();
158 value = physicalSizeObject.value(key: QLatin1String("width"));
159 if (!value.isUndefined() && value.isDouble())
160 m_physicalSize.setWidth(value.toInt());
161 value = physicalSizeObject.value(key: QLatin1String("height"));
162 if (!value.isUndefined() && value.isDouble())
163 m_physicalSize.setHeight(value.toInt());
164 }
165
166 value = description.value(key: QLatin1String("pixelDensity"));
167 if (!value.isUndefined() && value.isDouble())
168 m_pixelDensity = value.toDouble();
169
170 value = description.value(key: QLatin1String("refreshRate"));
171 if (!value.isUndefined() && value.isDouble())
172 m_refreshRate = value.toDouble();
173
174 value = description.value(key: QLatin1String("nativeOrientation"));
175 if (!value.isUndefined() && value.isDouble())
176 m_nativeOrientation = static_cast<Qt::ScreenOrientation>(value.toInt());
177
178 value = description.value(key: QLatin1String("orientation"));
179 if (!value.isUndefined() && value.isDouble())
180 m_orientation = static_cast<Qt::ScreenOrientation>(value.toInt());
181}
182
183QT_END_NAMESPACE
184

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