| 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 | |
| 42 | QT_BEGIN_NAMESPACE |
| 43 | |
| 44 | QEglFSEmulatorScreen::QEglFSEmulatorScreen(const QJsonObject &screenDescription) |
| 45 | : QEglFSScreen(eglGetDisplay(EGL_DEFAULT_DISPLAY)) |
| 46 | , m_id(0) |
| 47 | { |
| 48 | initFromJsonObject(screenDescription); |
| 49 | } |
| 50 | |
| 51 | QRect QEglFSEmulatorScreen::geometry() const |
| 52 | { |
| 53 | return m_geometry; |
| 54 | } |
| 55 | |
| 56 | QRect QEglFSEmulatorScreen::rawGeometry() const |
| 57 | { |
| 58 | return QRect(QPoint(0, 0), m_geometry.size()); |
| 59 | } |
| 60 | |
| 61 | int QEglFSEmulatorScreen::depth() const |
| 62 | { |
| 63 | return m_depth; |
| 64 | } |
| 65 | |
| 66 | QImage::Format QEglFSEmulatorScreen::format() const |
| 67 | { |
| 68 | return m_format; |
| 69 | } |
| 70 | |
| 71 | QSizeF QEglFSEmulatorScreen::physicalSize() const |
| 72 | { |
| 73 | return m_physicalSize; |
| 74 | } |
| 75 | |
| 76 | QDpi QEglFSEmulatorScreen::logicalDpi() const |
| 77 | { |
| 78 | return logicalBaseDpi(); |
| 79 | } |
| 80 | |
| 81 | QDpi QEglFSEmulatorScreen::logicalBaseDpi() const |
| 82 | { |
| 83 | return QDpi(100, 100); |
| 84 | } |
| 85 | |
| 86 | qreal QEglFSEmulatorScreen::refreshRate() const |
| 87 | { |
| 88 | return m_refreshRate; |
| 89 | } |
| 90 | |
| 91 | Qt::ScreenOrientation QEglFSEmulatorScreen::nativeOrientation() const |
| 92 | { |
| 93 | return m_nativeOrientation; |
| 94 | } |
| 95 | |
| 96 | Qt::ScreenOrientation QEglFSEmulatorScreen::orientation() const |
| 97 | { |
| 98 | return m_orientation; |
| 99 | } |
| 100 | |
| 101 | uint QEglFSEmulatorScreen::id() const |
| 102 | { |
| 103 | return m_id; |
| 104 | } |
| 105 | |
| 106 | QString QEglFSEmulatorScreen::name() const |
| 107 | { |
| 108 | return m_description; |
| 109 | } |
| 110 | |
| 111 | void QEglFSEmulatorScreen::initFromJsonObject(const QJsonObject &description) |
| 112 | { |
| 113 | QJsonValue value; |
| 114 | |
| 115 | value = description.value(QLatin1String("id")); |
| 116 | if (!value.isUndefined() && value.isDouble()) |
| 117 | m_id = value.toInt(); |
| 118 | |
| 119 | value = description.value(QLatin1String("description")); |
| 120 | if (!value.isUndefined() && value.isString()) |
| 121 | m_description = value.toString(); |
| 122 | |
| 123 | value = description.value(QLatin1String("geometry")); |
| 124 | if (!value.isUndefined() && value.isObject()) { |
| 125 | QJsonObject geometryObject = value.toObject(); |
| 126 | value = geometryObject.value(QLatin1String("x")); |
| 127 | if (!value.isUndefined() && value.isDouble()) |
| 128 | m_geometry.setX(value.toInt()); |
| 129 | value = geometryObject.value(QLatin1String("y")); |
| 130 | if (!value.isUndefined() && value.isDouble()) |
| 131 | m_geometry.setY(value.toInt()); |
| 132 | value = geometryObject.value(QLatin1String("width")); |
| 133 | if (!value.isUndefined() && value.isDouble()) |
| 134 | m_geometry.setWidth(value.toInt()); |
| 135 | value = geometryObject.value(QLatin1String("height")); |
| 136 | if (!value.isUndefined() && value.isDouble()) |
| 137 | m_geometry.setHeight(value.toInt()); |
| 138 | } |
| 139 | |
| 140 | value = description.value(QLatin1String("depth")); |
| 141 | if (!value.isUndefined() && value.isDouble()) |
| 142 | m_depth = value.toInt(); |
| 143 | |
| 144 | value = description.value(QLatin1String("format")); |
| 145 | if (!value.isUndefined() && value.isDouble()) |
| 146 | m_format = static_cast<QImage::Format>(value.toInt()); |
| 147 | |
| 148 | value = description.value(QLatin1String("physicalSize")); |
| 149 | if (!value.isUndefined() && value.isObject()) { |
| 150 | QJsonObject physicalSizeObject = value.toObject(); |
| 151 | value = physicalSizeObject.value(QLatin1String("width")); |
| 152 | if (!value.isUndefined() && value.isDouble()) |
| 153 | m_physicalSize.setWidth(value.toInt()); |
| 154 | value = physicalSizeObject.value(QLatin1String("height")); |
| 155 | if (!value.isUndefined() && value.isDouble()) |
| 156 | m_physicalSize.setHeight(value.toInt()); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | value = description.value(QLatin1String("refreshRate")); |
| 161 | if (!value.isUndefined() && value.isDouble()) |
| 162 | m_refreshRate = value.toDouble(); |
| 163 | |
| 164 | value = description.value(QLatin1String("nativeOrientation")); |
| 165 | if (!value.isUndefined() && value.isDouble()) |
| 166 | m_nativeOrientation = static_cast<Qt::ScreenOrientation>(value.toInt()); |
| 167 | |
| 168 | value = description.value(QLatin1String("orientation")); |
| 169 | if (!value.isUndefined() && value.isDouble()) |
| 170 | m_orientation = static_cast<Qt::ScreenOrientation>(value.toInt()); |
| 171 | } |
| 172 | |
| 173 | QT_END_NAMESPACE |
| 174 |