From 8c4067a1cac0d93ced039955d1b1f3b8820e5cc8 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 7 Aug 2015 12:55:03 +0200 Subject: Rename files and classes to Qt Project standard Change-Id: Ie694227780bc0c8cdd9398e45e2e0a5d73c8a7d4 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../mirclient/qmirclientnativeinterface.cpp | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp (limited to 'src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp') diff --git a/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp b/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp new file mode 100644 index 0000000000..072b02ec4e --- /dev/null +++ b/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2014 Canonical, Ltd. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License version 3, as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, + * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +// Qt +#include +#include +#include +#include + +// Local +#include "qmirclientnativeinterface.h" +#include "qmirclientscreen.h" +#include "qmirclientglcontext.h" + +class QMirClientResourceMap : public QMap +{ +public: + QMirClientResourceMap() + : QMap() { + insert("egldisplay", QMirClientNativeInterface::EglDisplay); + insert("eglcontext", QMirClientNativeInterface::EglContext); + insert("nativeorientation", QMirClientNativeInterface::NativeOrientation); + insert("display", QMirClientNativeInterface::Display); + } +}; + +Q_GLOBAL_STATIC(QMirClientResourceMap, ubuntuResourceMap) + +QMirClientNativeInterface::QMirClientNativeInterface() + : mGenericEventFilterType(QByteArrayLiteral("Event")) + , mNativeOrientation(nullptr) +{ +} + +QMirClientNativeInterface::~QMirClientNativeInterface() +{ + delete mNativeOrientation; + mNativeOrientation = nullptr; +} + +void* QMirClientNativeInterface::nativeResourceForContext( + const QByteArray& resourceString, QOpenGLContext* context) +{ + if (!context) + return nullptr; + + const QByteArray kLowerCaseResource = resourceString.toLower(); + + if (!ubuntuResourceMap()->contains(kLowerCaseResource)) + return nullptr; + + const ResourceType kResourceType = ubuntuResourceMap()->value(kLowerCaseResource); + + if (kResourceType == QMirClientNativeInterface::EglContext) + return static_cast(context->handle())->eglContext(); + else + return nullptr; +} + +void* QMirClientNativeInterface::nativeResourceForWindow(const QByteArray& resourceString, QWindow* window) +{ + const QByteArray kLowerCaseResource = resourceString.toLower(); + if (!ubuntuResourceMap()->contains(kLowerCaseResource)) + return NULL; + const ResourceType kResourceType = ubuntuResourceMap()->value(kLowerCaseResource); + if (kResourceType == QMirClientNativeInterface::EglDisplay) { + if (window) { + return static_cast(window->screen()->handle())->eglDisplay(); + } else { + return static_cast( + QGuiApplication::primaryScreen()->handle())->eglDisplay(); + } + } else if (kResourceType == QMirClientNativeInterface::NativeOrientation) { + // Return the device's native screen orientation. + if (window) { + QMirClientScreen *ubuntuScreen = static_cast(window->screen()->handle()); + mNativeOrientation = new Qt::ScreenOrientation(ubuntuScreen->nativeOrientation()); + } else { + QPlatformScreen *platformScreen = QGuiApplication::primaryScreen()->handle(); + mNativeOrientation = new Qt::ScreenOrientation(platformScreen->nativeOrientation()); + } + return mNativeOrientation; + } else { + return NULL; + } +} + +void* QMirClientNativeInterface::nativeResourceForScreen(const QByteArray& resourceString, QScreen* screen) +{ + const QByteArray kLowerCaseResource = resourceString.toLower(); + if (!ubuntuResourceMap()->contains(kLowerCaseResource)) + return NULL; + const ResourceType kResourceType = ubuntuResourceMap()->value(kLowerCaseResource); + if (kResourceType == QMirClientNativeInterface::Display) { + if (!screen) + screen = QGuiApplication::primaryScreen(); + return static_cast(screen->handle())->eglNativeDisplay(); + } else + return NULL; +} -- cgit v1.2.3