diff options
Diffstat (limited to 'src/plugins/platforms/eglfs/deviceintegration')
8 files changed, 559 insertions, 0 deletions
diff --git a/src/plugins/platforms/eglfs/deviceintegration/deviceintegration.pro b/src/plugins/platforms/eglfs/deviceintegration/deviceintegration.pro index d86a67b4f4..52cc5739aa 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/deviceintegration.pro +++ b/src/plugins/platforms/eglfs/deviceintegration/deviceintegration.pro @@ -9,5 +9,7 @@ qtConfig(eglfs_mali): SUBDIRS += eglfs_mali qtConfig(eglfs_viv): SUBDIRS += eglfs_viv qtConfig(eglfs_viv_wl): SUBDIRS += eglfs_viv_wl +SUBDIRS += eglfs_emu + eglfs_kms_egldevice.depends = eglfs_kms_support eglfs_kms.depends = eglfs_kms_support diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/eglfs_emu.json b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/eglfs_emu.json new file mode 100644 index 0000000000..3aa38abd7a --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/eglfs_emu.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "eglfs_emu" ] +} diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/eglfs_emu.pro b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/eglfs_emu.pro new file mode 100644 index 0000000000..609f04e8a9 --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/eglfs_emu.pro @@ -0,0 +1,27 @@ +TARGET = qeglfs-emu-integration + +QT += core-private gui-private eglfsdeviceintegration-private + +INCLUDEPATH += $$PWD/../../api +CONFIG += egl + +# Avoid X11 header collision +DEFINES += QT_EGL_NO_X11 + +OTHER_FILES += $$PWD/eglfs_emu.json + +PLUGIN_TYPE = egldeviceintegrations +PLUGIN_CLASS_NAME = QEglFSEmulatorIntegrationPlugin +load(qt_plugin) + +DISTFILES += \ + eglfs_emu.json + +SOURCES += \ + qeglfsemumain.cpp \ + qeglfsemulatorintegration.cpp \ + qeglfsemulatorscreen.cpp + +HEADERS += \ + qeglfsemulatorintegration.h \ + qeglfsemulatorscreen.h diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorintegration.cpp new file mode 100644 index 0000000000..8a059ba973 --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorintegration.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qeglfsemulatorintegration.h" +#include "qeglfsemulatorscreen.h" +#include "private/qeglfsintegration_p.h" + +#include <private/qguiapplication_p.h> +#include <QtEglSupport/private/qeglconvenience_p.h> +#include <QtEglSupport/private/qeglplatformcontext_p.h> + +#include <QtCore/QJsonDocument> +#include <QtCore/QJsonArray> +#include <QtCore/QJsonParseError> + +QT_BEGIN_NAMESPACE + +QEglFSEmulatorIntegration::QEglFSEmulatorIntegration() +{ + // The Qt Emulator provides the ability to render to multiple displays + // In addition to the usual EGL and OpenGLESv2 API's, there are also a + // few additional API's that enable the client (this plugin) to query + // the available screens and their properties, as well as the ability + // to select which screen is the active render target (as this is + // usually handled in a platform specific way and not by EGL itself). + + getDisplays = reinterpret_cast<PFNQGSGETDISPLAYSPROC>(eglGetProcAddress("qgsGetDisplays")); + setDisplay = reinterpret_cast<PFNQGSSETDISPLAYPROC>(eglGetProcAddress("qgsSetDisplay")); +} + +void QEglFSEmulatorIntegration::platformInit() +{ +} + +void QEglFSEmulatorIntegration::platformDestroy() +{ +} + +bool QEglFSEmulatorIntegration::usesDefaultScreen() +{ + // This makes it possible to remotely query and then register our own set of screens + return false; +} + +void QEglFSEmulatorIntegration::screenInit() +{ + QEglFSIntegration *integration = static_cast<QEglFSIntegration *>(QGuiApplicationPrivate::platformIntegration()); + + // Use qgsGetDisplays() call to retrieve the available screens from the Emulator + if (getDisplays) { + QByteArray displaysInfo = getDisplays(); + QJsonParseError error; + QJsonDocument displaysDocument = QJsonDocument::fromJson(displaysInfo, &error); + if (error.error == QJsonParseError::NoError) { + // Document should be an array of screen objects + if (displaysDocument.isArray()){ + QJsonArray screenArray = displaysDocument.array(); + for (auto screenValue : screenArray) { + if (screenValue.isObject()) + integration->addScreen(new QEglFSEmulatorScreen(screenValue.toObject())); + } + } + } else { + qWarning() << "eglfs_emu: Failed to parse display info JSON with error: " << error.errorString(); + } + } else { + qFatal("EGL library doesn't support Emulator extensions"); + } +} + +bool QEglFSEmulatorIntegration::hasCapability(QPlatformIntegration::Capability cap) const +{ + switch (cap) { + case QPlatformIntegration::ThreadedPixmaps: + case QPlatformIntegration::OpenGL: + case QPlatformIntegration::ThreadedOpenGL: + return true; + default: + return false; + } +} + +EGLNativeWindowType QEglFSEmulatorIntegration::createNativeWindow(QPlatformWindow *platformWindow, + const QSize &size, + const QSurfaceFormat &format) +{ + Q_UNUSED(size); + Q_UNUSED(format); + static QAtomicInt uniqueWindowId(1); + QEglFSEmulatorScreen *screen = static_cast<QEglFSEmulatorScreen *>(platformWindow->screen()); + if (screen && setDisplay) { + // Let the emulator know which screen the window surface is attached to + setDisplay(screen->id()); + } + return EGLNativeWindowType(qintptr(uniqueWindowId.fetchAndAddRelaxed(1))); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorintegration.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorintegration.h new file mode 100644 index 0000000000..513a5063fb --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorintegration.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEGLFSEMULATORINTEGRATION_H +#define QEGLFSEMULATORINTEGRATION_H + +#include "private/qeglfsdeviceintegration_p.h" + +#include <QtCore/QLoggingCategory> +#include <QtCore/QFunctionPointer> + +typedef const char *(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC) (); +typedef void (EGLAPIENTRYP PFNQGSSETDISPLAYPROC) (uint screen); + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(qLcEglfsEmuDebug) + +class QEglFSEmulatorIntegration : public QEglFSDeviceIntegration +{ +public: + QEglFSEmulatorIntegration(); + + void platformInit() override; + void platformDestroy() override; + bool usesDefaultScreen() override; + void screenInit() override; + bool hasCapability(QPlatformIntegration::Capability cap) const override; + + PFNQGSGETDISPLAYSPROC getDisplays; + PFNQGSSETDISPLAYPROC setDisplay; + + EGLNativeWindowType createNativeWindow(QPlatformWindow *platformWindow, const QSize &size, const QSurfaceFormat &format) override; +}; + +QT_END_NAMESPACE + +#endif // QEGLFSEMULATORINTEGRATION_H diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.cpp new file mode 100644 index 0000000000..4546088327 --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.cpp @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qeglfsemulatorscreen.h" + +QT_BEGIN_NAMESPACE + +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 +{ + const QSizeF ps = m_physicalSize; + const QSize s = m_geometry.size(); + + if (!ps.isEmpty() && !s.isEmpty()) + return QDpi(25.4 * s.width() / ps.width(), + 25.4 * s.height() / ps.height()); + else + return QDpi(100, 100); +} + +qreal QEglFSEmulatorScreen::pixelDensity() const +{ + return m_pixelDensity; +} + +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; +} + +void QEglFSEmulatorScreen::initFromJsonObject(const QJsonObject &description) +{ + QJsonValue value; + + value = description.value(QLatin1String("id")); + if (!value.isUndefined() && value.isDouble()) + m_id = value.toInt(); + + value = description.value(QLatin1String("description")); + if (!value.isUndefined() && value.isString()) + m_description = value.toString(); + + value = description.value(QLatin1String("geometry")); + if (!value.isUndefined() && value.isObject()) { + QJsonObject geometryObject = value.toObject(); + value = geometryObject.value(QLatin1String("x")); + if (!value.isUndefined() && value.isDouble()) + m_geometry.setX(value.toInt()); + value = geometryObject.value(QLatin1String("y")); + if (!value.isUndefined() && value.isDouble()) + m_geometry.setY(value.toInt()); + value = geometryObject.value(QLatin1String("width")); + if (!value.isUndefined() && value.isDouble()) + m_geometry.setWidth(value.toInt()); + value = geometryObject.value(QLatin1String("height")); + if (!value.isUndefined() && value.isDouble()) + m_geometry.setHeight(value.toInt()); + } + + value = description.value(QLatin1String("depth")); + if (!value.isUndefined() && value.isDouble()) + m_depth = value.toInt(); + + value = description.value(QLatin1String("format")); + if (!value.isUndefined() && value.isDouble()) + m_format = static_cast<QImage::Format>(value.toInt()); + + value = description.value(QLatin1String("physicalSize")); + if (!value.isUndefined() && value.isObject()) { + QJsonObject physicalSizeObject = value.toObject(); + value = physicalSizeObject.value(QLatin1String("width")); + if (!value.isUndefined() && value.isDouble()) + m_physicalSize.setWidth(value.toInt()); + value = physicalSizeObject.value(QLatin1String("height")); + if (!value.isUndefined() && value.isDouble()) + m_physicalSize.setHeight(value.toInt()); + } + + value = description.value(QLatin1String("pixelDensity")); + if (!value.isUndefined() && value.isDouble()) + m_pixelDensity = value.toDouble(); + + value = description.value(QLatin1String("refreshRate")); + if (!value.isUndefined() && value.isDouble()) + m_refreshRate = value.toDouble(); + + value = description.value(QLatin1String("nativeOrientation")); + if (!value.isUndefined() && value.isDouble()) + m_nativeOrientation = static_cast<Qt::ScreenOrientation>(value.toInt()); + + value = description.value(QLatin1String("orientation")); + if (!value.isUndefined() && value.isDouble()) + m_orientation = static_cast<Qt::ScreenOrientation>(value.toInt()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.h new file mode 100644 index 0000000000..3e5113c9c2 --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemulatorscreen.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEGLFSEMULATORSCREEN_H +#define QEGLFSEMULATORSCREEN_H + +#include <QtCore/QJsonObject> + +#include "qeglfsemulatorintegration.h" +#include "private/qeglfsscreen_p.h" + +QT_BEGIN_NAMESPACE + +class QEglFSEmulatorScreen : public QEglFSScreen +{ +public: + QEglFSEmulatorScreen(const QJsonObject &screenDescription); + + QRect geometry() const override; + QRect rawGeometry() const override; + int depth() const override; + QImage::Format format() const override; + QSizeF physicalSize() const override; + QDpi logicalDpi() const override; + qreal pixelDensity() const override; + qreal refreshRate() const override; + Qt::ScreenOrientation nativeOrientation() const override; + Qt::ScreenOrientation orientation() const override; + + uint id() const; + +private: + void initFromJsonObject(const QJsonObject &description); + + QString m_description; + QRect m_geometry; + int m_depth; + QImage::Format m_format; + QSizeF m_physicalSize; + float m_pixelDensity; + float m_refreshRate; + Qt::ScreenOrientation m_nativeOrientation; + Qt::ScreenOrientation m_orientation; + uint m_id; +}; + +QT_END_NAMESPACE + +#endif // QEGLFSEMULATORSCREEN_H diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemumain.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemumain.cpp new file mode 100644 index 0000000000..5899d666d8 --- /dev/null +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_emu/qeglfsemumain.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qeglfsdeviceintegration_p.h" +#include "qeglfsemulatorintegration.h" + +QT_BEGIN_NAMESPACE + +class QEglFSEmulatorIntegrationPlugin : public QEglFSDeviceIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QEglFSDeviceIntegrationFactoryInterface_iid FILE "eglfs_emu.json") + +public: + QEglFSDeviceIntegration *create() Q_DECL_OVERRIDE { return new QEglFSEmulatorIntegration; } +}; + +QT_END_NAMESPACE + +#include "qeglfsemumain.moc" |