From b6b853b1b64175c191e776ffbf297bdc9de0a0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 27 Jul 2011 15:10:16 +0200 Subject: Initial OpenWFD support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I06f71073ec58af1a431edb997f3a359800320196 Reviewed-on: http://codereview.qt.nokia.com/2288 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/plugins/platforms/openwfd/main.cpp | 72 +++++ src/plugins/platforms/openwfd/openwf.pro | 41 +++ .../platforms/openwfd/qopenwfdbackingstore.cpp | 25 ++ .../platforms/openwfd/qopenwfdbackingstore.h | 65 +++++ src/plugins/platforms/openwfd/qopenwfddevice.cpp | 317 +++++++++++++++++++++ src/plugins/platforms/openwfd/qopenwfddevice.h | 113 ++++++++ src/plugins/platforms/openwfd/qopenwfdevent.cpp | 46 +++ src/plugins/platforms/openwfd/qopenwfdevent.h | 51 ++++ .../platforms/openwfd/qopenwfdglcontext.cpp | 97 +++++++ src/plugins/platforms/openwfd/qopenwfdglcontext.h | 68 +++++ .../platforms/openwfd/qopenwfdintegration.cpp | 145 ++++++++++ .../platforms/openwfd/qopenwfdintegration.h | 85 ++++++ .../platforms/openwfd/qopenwfdnativeinterface.cpp | 141 +++++++++ .../platforms/openwfd/qopenwfdnativeinterface.h | 76 +++++ .../platforms/openwfd/qopenwfdoutputbuffer.cpp | 90 ++++++ .../platforms/openwfd/qopenwfdoutputbuffer.h | 69 +++++ src/plugins/platforms/openwfd/qopenwfdport.cpp | 212 ++++++++++++++ src/plugins/platforms/openwfd/qopenwfdport.h | 89 ++++++ src/plugins/platforms/openwfd/qopenwfdportmode.cpp | 63 ++++ src/plugins/platforms/openwfd/qopenwfdportmode.h | 74 +++++ src/plugins/platforms/openwfd/qopenwfdscreen.cpp | 192 +++++++++++++ src/plugins/platforms/openwfd/qopenwfdscreen.h | 91 ++++++ src/plugins/platforms/openwfd/qopenwfdwindow.cpp | 61 ++++ src/plugins/platforms/openwfd/qopenwfdwindow.h | 61 ++++ 24 files changed, 2344 insertions(+) create mode 100644 src/plugins/platforms/openwfd/main.cpp create mode 100644 src/plugins/platforms/openwfd/openwf.pro create mode 100644 src/plugins/platforms/openwfd/qopenwfdbackingstore.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdbackingstore.h create mode 100644 src/plugins/platforms/openwfd/qopenwfddevice.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfddevice.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdevent.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdevent.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdglcontext.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdglcontext.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdintegration.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdintegration.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdnativeinterface.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdnativeinterface.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdoutputbuffer.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdoutputbuffer.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdport.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdport.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdportmode.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdportmode.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdscreen.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdscreen.h create mode 100644 src/plugins/platforms/openwfd/qopenwfdwindow.cpp create mode 100644 src/plugins/platforms/openwfd/qopenwfdwindow.h (limited to 'src') diff --git a/src/plugins/platforms/openwfd/main.cpp b/src/plugins/platforms/openwfd/main.cpp new file mode 100644 index 0000000000..c0159e7218 --- /dev/null +++ b/src/plugins/platforms/openwfd/main.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "qopenwfdintegration.h" + +QT_BEGIN_NAMESPACE + +class QOpenWFDIntegrationPlugin : public QPlatformIntegrationPlugin +{ +public: + QStringList keys() const; + QPlatformIntegration *create(const QString&, const QStringList&); +}; + +QStringList QOpenWFDIntegrationPlugin::keys() const +{ + QStringList list; + list << "OpenWFD"; + return list; +} + +QPlatformIntegration* QOpenWFDIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + Q_UNUSED(paramList); + if (system.toLower() == "openwfd") + return new QOpenWFDIntegration; + + return 0; +} + +Q_EXPORT_PLUGIN2(openwfd, QOpenWFDIntegrationPlugin) + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/openwfd/openwf.pro b/src/plugins/platforms/openwfd/openwf.pro new file mode 100644 index 0000000000..d913a84411 --- /dev/null +++ b/src/plugins/platforms/openwfd/openwf.pro @@ -0,0 +1,41 @@ +TARGET = qopenwf + +load(qt_plugin) +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms + +QT += core-private gui-private platformsupport-private + +CONFIG += qpa/genericunixfontdatabase + +HEADERS += \ + qopenwfddevice.h \ + qopenwfdintegration.h \ + qopenwfdnativeinterface.h \ + qopenwfdscreen.h \ + qopenwfdbackingstore.h \ + qopenwfdevent.h \ + qopenwfdglcontext.h \ + qopenwfdoutputbuffer.h \ + qopenwfdport.h \ + qopenwfdwindow.h \ + qopenwfdportmode.h + +SOURCES += \ + main.cpp \ + qopenwfddevice.cpp \ + qopenwfdintegration.cpp \ + qopenwfdnativeinterface.cpp \ + qopenwfdscreen.cpp \ + qopenwfdbackingstore.cpp \ + qopenwfdevent.cpp \ + qopenwfdglcontext.cpp \ + qopenwfdoutputbuffer.cpp \ + qopenwfdport.cpp \ + qopenwfdportmode.cpp \ + qopenwfdwindow.cpp + +LIBS += -lWFD -lgbm -lGLESv2 -lEGL + +target.path += $$[QT_INSTALL_PLUGINS]/platforms +INSTALLS += target + diff --git a/src/plugins/platforms/openwfd/qopenwfdbackingstore.cpp b/src/plugins/platforms/openwfd/qopenwfdbackingstore.cpp new file mode 100644 index 0000000000..2638d8cd5a --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdbackingstore.cpp @@ -0,0 +1,25 @@ +#include "qopenwfdbackingstore.h" + +QOpenWFDBackingStore::QOpenWFDBackingStore(QWindow *window) + : QPlatformBackingStore(window) +{ +} + +QPaintDevice * QOpenWFDBackingStore::paintDevice() +{ + return &mImage; +} + +//we don't support flush yet :) +void QOpenWFDBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) +{ + Q_UNUSED(window); + Q_UNUSED(region); + Q_UNUSED(offset); +} + +void QOpenWFDBackingStore::resize(const QSize &size, const QRegion &staticContents) +{ + Q_UNUSED(staticContents); + mImage = QImage(size,QImage::Format_RGB32); +} diff --git a/src/plugins/platforms/openwfd/qopenwfdbackingstore.h b/src/plugins/platforms/openwfd/qopenwfdbackingstore.h new file mode 100644 index 0000000000..c173de6c19 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdbackingstore.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDBACKINGSTORE_H +#define QOPENWFDBACKINGSTORE_H + +#include +#include + +class QOpenWFDBackingStore : public QPlatformBackingStore +{ +public: + QOpenWFDBackingStore(QWindow *window); + + QPaintDevice *paintDevice(); + + // 'window' can be a child window, in which case 'region' is in child window coordinates and + // offset is the (child) window's offset in relation to the window surface. + void flush(QWindow *window, const QRegion ®ion, const QPoint &offset); + + void resize(const QSize &size, const QRegion &staticContents); + +private: + QImage mImage; +}; + +#endif // QOPENWFDBACKINGSTORE_H diff --git a/src/plugins/platforms/openwfd/qopenwfddevice.cpp b/src/plugins/platforms/openwfd/qopenwfddevice.cpp new file mode 100644 index 0000000000..fb63468725 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfddevice.cpp @@ -0,0 +1,317 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfddevice.h" + +#include "qopenwfdport.h" +#include "qopenwfdscreen.h" + +#include + +#include +#include + +QOpenWFDDevice::QOpenWFDDevice(QOpenWFDIntegration *integration, WFDint device_enumeration) + : mIntegration(integration) + , mDeviceEnum(device_enumeration) + , mCommitedDevice(false) + , mWaitingForBindSourceEvent(false) +{ + mDevice = wfdCreateDevice(WFD_DEFAULT_DEVICE_ID,WFD_NONE); + if (mDevice == WFD_INVALID_HANDLE) + qDebug() << "failed to create device"; + + mEvent = wfdCreateEvent(mDevice,0); + if (mEvent == WFD_INVALID_HANDLE) + qDebug() << "failed to create event handle"; + + //initialize pipelines for device. + wfdEnumeratePipelines(mDevice,WFD_NONE,0,WFD_NONE); + + initializeGbmAndEgl(); + + WFDint numberOfPorts = wfdEnumeratePorts(mDevice,0,0,0); + WFDint port_enumerations[numberOfPorts]; + WFDint actualNumberOfPorts = wfdEnumeratePorts(mDevice,port_enumerations,numberOfPorts,WFD_NONE); + Q_ASSERT(actualNumberOfPorts == numberOfPorts); + + for (int i = 0; i < actualNumberOfPorts; i++) + { + QOpenWFDPort *port = new QOpenWFDPort(this,port_enumerations[i]); + if (port->attached()) { + mPorts.append(port); + } else { + delete port; + } + } + + int copyFd = wfdDeviceEventGetFD(mDevice,mEvent); + mEventSocketNotifier = new QSocketNotifier(copyFd,QSocketNotifier::Read,this); + connect(mEventSocketNotifier,SIGNAL(activated(int)),SLOT(readEvents())); + + mCommitedDevice = true; + commit(WFD_COMMIT_ENTIRE_DEVICE, handle()); +} + +QOpenWFDDevice::~QOpenWFDDevice() +{ + delete mEventSocketNotifier; + wfdDestroyEvent(mDevice,mEvent); + + for (int i = 0; i < mPorts.size(); i++) { + //probably don't need to remove them from the list + QList keys = mUsedPipelines.keys(mPorts.at(i)); + for (int keyIndex = 0; keyIndex < keys.size(); keyIndex++) { + mUsedPipelines.remove(keys.at(keyIndex)); + } + //but we have to delete them :) + delete mPorts[i]; + } + + eglDestroyContext(mEglDisplay,mEglContext); + eglTerminate(mEglDisplay); + + gbm_device_destroy(mGbmDevice); + + wfdDestroyDevice(mDevice); +} + +WFDDevice QOpenWFDDevice::handle() const +{ + return mDevice; +} + +QOpenWFDIntegration * QOpenWFDDevice::integration() const +{ + return mIntegration; +} + +bool QOpenWFDDevice::isPipelineUsed(WFDint pipelineId) +{ + return mUsedPipelines.contains(pipelineId); +} + +void QOpenWFDDevice::addToUsedPipelineSet(WFDint pipelineId,QOpenWFDPort *port) +{ + mUsedPipelines.insert(pipelineId,port); +} + +void QOpenWFDDevice::removeFromUsedPipelineSet(WFDint pipelineId) +{ + mUsedPipelines.remove(pipelineId); +} + +gbm_device * QOpenWFDDevice::gbmDevice() const + +{ + return mGbmDevice; +} + +EGLDisplay QOpenWFDDevice::eglDisplay() const +{ + return mEglDisplay; +} + +EGLContext QOpenWFDDevice::eglContext() const +{ + return mEglContext; +} + +void QOpenWFDDevice::commit(WFDCommitType type, WFDHandle handle) +{ + if (mCommitedDevice) { + wfdDeviceCommit(mDevice,type,handle); + } +} + +void QOpenWFDDevice::waitForPipelineBindSourceCompleteEvent() +{ + mWaitingForBindSourceEvent = true; + + while (mWaitingForBindSourceEvent) { + readEvents(WFD_FOREVER); + } +} + +void QOpenWFDDevice::readEvents(WFDtime wait) +{ + WFDEventType type = wfdDeviceEventWait(mDevice,mEvent,wait); + + if (type == WFD_EVENT_NONE || type == WFD_EVENT_DESTROYED) { + return; + } + switch (type) { + case WFD_EVENT_INVALID: + case WFD_EVENT_NONE: + return; + case WFD_EVENT_DESTROYED: + qDebug() << "Event or Device destoryed!"; + return; + case WFD_EVENT_PORT_ATTACH_DETACH: + handlePortAttachDetach(); + break; + case WFD_EVENT_PORT_PROTECTION_FAILURE: + qDebug() << "Port protection event handling not implemented"; + break; + case WFD_EVENT_PIPELINE_BIND_SOURCE_COMPLETE: + handlePipelineBindSourceComplete(); + break; + case WFD_EVENT_PIPELINE_BIND_MASK_COMPLETE: + qDebug() << "Pipeline bind mask event handling not implemented"; + break; + default: + qDebug() << "Not recognised event type"; + break; + } + + +} + +void QOpenWFDDevice::initializeGbmAndEgl() +{ + + qDebug() << "initializing GBM and EGL"; + int fd = wfdGetDeviceAttribi(mDevice,WFD_DEVICE_ID); + if (fd < 0) { + qDebug() << "failed to get WFD_DEVICE_ID"; + } + + mGbmDevice = gbm_create_device(fd); + + setenv("EGL_PLATFORM", "drm",1); + + mEglDisplay = eglGetDisplay(mGbmDevice); + + EGLint minor, major; + + if (!eglInitialize(mEglDisplay,&major,&minor)) { + qDebug() << "failed to initialize egl"; + } + + QByteArray eglExtensions = eglQueryString(mEglDisplay, EGL_EXTENSIONS); + if (!eglExtensions.contains("EGL_KHR_surfaceless_opengl")) { + qDebug() << "This egl implementation does not have the required EGL extension EGL_KHR_surfaceless_opengl"; + } + + eglBindAPI(EGL_OPENGL_ES_API); + + EGLint contextAttribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + mEglContext = eglCreateContext(mEglDisplay,NULL,EGL_NO_CONTEXT,contextAttribs); + if (mEglContext == EGL_NO_CONTEXT) { + qDebug() << "Failed to create EGL context"; + } + + eglCreateImage = (PFNEGLCREATEIMAGEKHRPROC) eglGetProcAddress("eglCreateImageKHR"); + if (!eglCreateImage) { + qWarning("failed to load extension eglCreateImageKHR"); + } + + eglDestroyImage = (PFNEGLDESTROYIMAGEKHRPROC) eglGetProcAddress("eglDestroyImageKHR"); + if (!eglDestroyImage) { + qWarning("failed to load extension eglDestoryImageKHR"); + } + + glEglImageTargetRenderBufferStorage = (PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES"); + if (!glEglImageTargetRenderBufferStorage) { + qWarning("failed to load extension glEGLImageTargetRenderbufferStorageOES"); + } +} + +void QOpenWFDDevice::handlePortAttachDetach() +{ + WFDint id = wfdGetEventAttribi(mDevice,mEvent,WFD_EVENT_PORT_ATTACH_PORT_ID); + if (id == WFD_INVALID_PORT_ID) + return; + + WFDint attachState = wfdGetEventAttribi(mDevice,mEvent,WFD_EVENT_PORT_ATTACH_STATE); + if (attachState == WFD_TRUE) { + int indexToAdd = -1; + for (int i = 0; i < mPorts.size(); i++) { + if (mPorts.at(i)->portId() == id) { + indexToAdd = i; + qDebug() << "found index to attach"; + break; + } + } + if (indexToAdd >= 0) { + mPorts[indexToAdd]->attach(); + } else { + mPorts.append(new QOpenWFDPort(this,id)); + } + + } else { + int indexToDelete = -1; + for (int i = 0; i < mPorts.size(); i++) { + if (mPorts.at(i)->portId() == id) { + indexToDelete = i; + break; + } + } + if (indexToDelete >= 0) { + QOpenWFDPort *portToDelete = mPorts.at(indexToDelete); + mPorts.removeAt(indexToDelete); + delete portToDelete; + } + } +} + +void QOpenWFDDevice::handlePipelineBindSourceComplete() +{ + mWaitingForBindSourceEvent = false; + + WFDint overflow = wfdGetEventAttribi(mDevice,mEvent, WFD_EVENT_PIPELINE_BIND_QUEUE_OVERFLOW); + if (overflow == WFD_TRUE) { + qDebug() << "PIPELINE_BIND_QUEUE_OVERFLOW event occured"; + } + + WFDint pipelineId = wfdGetEventAttribi(mDevice,mEvent,WFD_EVENT_PIPELINE_BIND_PIPELINE_ID); + for (int i = 0; i < mPorts.size(); i++) { + if (pipelineId != WFD_INVALID_PIPELINE_ID && mUsedPipelines.contains(pipelineId)) { + QOpenWFDPort *port = mUsedPipelines.value(pipelineId); + port->screen()->pipelineBindSourceComplete(); + break; + } + } +} diff --git a/src/plugins/platforms/openwfd/qopenwfddevice.h b/src/plugins/platforms/openwfd/qopenwfddevice.h new file mode 100644 index 0000000000..83a5539124 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfddevice.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDDEVICE_H +#define QOPENWFDDEVICE_H + +#include "qopenwfdintegration.h" + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +class QOpenWFDPort; + +class QOpenWFDDevice : public QObject +{ + Q_OBJECT +public: + QOpenWFDDevice(QOpenWFDIntegration *integration, WFDint handle); + ~QOpenWFDDevice(); + WFDDevice handle() const; + QOpenWFDIntegration *integration() const; + + + bool isPipelineUsed(WFDint pipelineId); + void addToUsedPipelineSet(WFDint pipelineId, QOpenWFDPort *port); + void removeFromUsedPipelineSet(WFDint pipelineId); + + gbm_device *gbmDevice() const; + EGLDisplay eglDisplay() const; + EGLContext eglContext() const; + + PFNEGLCREATEIMAGEKHRPROC eglCreateImage; + PFNEGLDESTROYIMAGEKHRPROC eglDestroyImage; + PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEglImageTargetRenderBufferStorage; + + void commit(WFDCommitType type, WFDHandle handle); + bool isDeviceInitializedAndCommited() const { return mCommitedDevice; } + + void waitForPipelineBindSourceCompleteEvent(); + +public slots: + void readEvents(WFDtime wait = 0); +private: + void initializeGbmAndEgl(); + void handlePortAttachDetach(); + void handlePipelineBindSourceComplete(); + QOpenWFDIntegration *mIntegration; + WFDint mDeviceEnum; + WFDDevice mDevice; + + WFDEvent mEvent; + QSocketNotifier *mEventSocketNotifier; + + QList mPorts; + + QMap mUsedPipelines; + + struct gbm_device *mGbmDevice; + EGLDisplay mEglDisplay; + EGLContext mEglContext; + + bool mCommitedDevice; + bool mWaitingForBindSourceEvent; +}; + +#endif // QOPENWFDDEVICE_H diff --git a/src/plugins/platforms/openwfd/qopenwfdevent.cpp b/src/plugins/platforms/openwfd/qopenwfdevent.cpp new file mode 100644 index 0000000000..748dde65e7 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdevent.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdevent.h" + +QOpenWFDEvent::QOpenWFDEvent() +{ +} diff --git a/src/plugins/platforms/openwfd/qopenwfdevent.h b/src/plugins/platforms/openwfd/qopenwfdevent.h new file mode 100644 index 0000000000..3010fdb55b --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdevent.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDEVENT_H +#define QOPENWFDEVENT_H + +class QOpenWFDEvent +{ +public: + QOpenWFDEvent(); +}; + +#endif // QOPENWFDEVENT_H diff --git a/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp b/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp new file mode 100644 index 0000000000..87d7af4a02 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdglcontext.cpp @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdglcontext.h" + +#include "qopenwfdwindow.h" +#include "qopenwfdscreen.h" + +QOpenWFDGLContext::QOpenWFDGLContext(QOpenWFDDevice *device) + : QPlatformGLContext() + , mWfdDevice(device) +{ +} + +QSurfaceFormat QOpenWFDGLContext::format() const +{ + return QSurfaceFormat(); +} + +bool QOpenWFDGLContext::makeCurrent(QPlatformSurface *surface) +{ + EGLDisplay display = mWfdDevice->eglDisplay(); + EGLContext context = mWfdDevice->eglContext(); + if (!eglMakeCurrent(display,EGL_NO_SURFACE,EGL_NO_SURFACE,context)) { + qDebug() << "GLContext: eglMakeCurrent FAILED!"; + } + + QPlatformWindow *window = static_cast(surface); + QOpenWFDScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window->window())); + screen->bindFramebuffer(); + return true; +} + +void QOpenWFDGLContext::doneCurrent() +{ + //do nothing :) +} + +void QOpenWFDGLContext::swapBuffers(QPlatformSurface *surface) +{ + glFlush(); + + QPlatformWindow *window = static_cast(surface); + QOpenWFDScreen *screen = static_cast(QPlatformScreen::platformScreenForWindow(window->window())); + + screen->swapBuffers(); +} + +void (*QOpenWFDGLContext::getProcAddress(const QByteArray &procName)) () +{ + return eglGetProcAddress(procName.data()); +} + +EGLContext QOpenWFDGLContext::eglContext() const +{ + return mWfdDevice->eglContext(); +} + + diff --git a/src/plugins/platforms/openwfd/qopenwfdglcontext.h b/src/plugins/platforms/openwfd/qopenwfdglcontext.h new file mode 100644 index 0000000000..0f53b9653b --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdglcontext.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDGLCONTEXT_H +#define QOPENWFDGLCONTEXT_H + +#include + +#include "qopenwfddevice.h" + +class QOpenWFDGLContext : public QPlatformGLContext +{ +public: + QOpenWFDGLContext(QOpenWFDDevice *device); + + QSurfaceFormat format() const; + + bool makeCurrent(QPlatformSurface *surface); + void doneCurrent(); + + void swapBuffers(QPlatformSurface *surface); + + void (*getProcAddress(const QByteArray &procName)) (); + + EGLContext eglContext() const; +private: + QOpenWFDDevice *mWfdDevice; +}; + +#endif // QOPENWFDGLCONTEXT_H diff --git a/src/plugins/platforms/openwfd/qopenwfdintegration.cpp b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp new file mode 100644 index 0000000000..2494e7f030 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdintegration.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdintegration.h" +#include "qopenwfdscreen.h" +#include "qopenwfdnativeinterface.h" +#include "qopenwfddevice.h" +#include "qopenwfdwindow.h" +#include "qopenwfdglcontext.h" +#include "qopenwfdbackingstore.h" + +#include + +#include +#include +#include + +#include +#include + +#include + +#include + +QOpenWFDIntegration::QOpenWFDIntegration() + : QPlatformIntegration() + , mPrinterSupport(new QGenericUnixPrinterSupport) +{ + QGuiApplicationPrivate::instance()->setEventDispatcher(createEventDispatcher()); + int numberOfDevices = wfdEnumerateDevices(0,0,0); + + WFDint devices[numberOfDevices]; + int actualNumberOfDevices = wfdEnumerateDevices(devices,numberOfDevices,0); + Q_ASSERT(actualNumberOfDevices == numberOfDevices); + + for (int i = 0; i < actualNumberOfDevices; i++) { + mDevices.append(new QOpenWFDDevice(this,devices[i])); + } + + mFontDatabase = new QGenericUnixFontDatabase(); + mNativeInterface = new QOpenWFDNativeInterface; +} + +QOpenWFDIntegration::~QOpenWFDIntegration() +{ + //dont delete screens since they are deleted by the devices + qDebug() << "deleting platform integration"; + for (int i = 0; i < mDevices.size(); i++) { + delete mDevices[i]; + } + + delete mFontDatabase; + delete mNativeInterface; + delete mPrinterSupport; +} + +bool QOpenWFDIntegration::hasCapability(QPlatformIntegration::Capability cap) const +{ + switch (cap) { + case ThreadedPixmaps: return true; + case OpenGL: return true; + default: return QPlatformIntegration::hasCapability(cap); + } +} + +QPlatformWindow *QOpenWFDIntegration::createPlatformWindow(QWindow *window) const +{ + return new QOpenWFDWindow(window); +} + +QPlatformGLContext *QOpenWFDIntegration::createPlatformGLContext(QGuiGLContext *context) const +{ + QOpenWFDScreen *screen = static_cast(context->screen()->handle()); + + return new QOpenWFDGLContext(screen->port()->device()); +} + +QPlatformBackingStore *QOpenWFDIntegration::createPlatformBackingStore(QWindow *window) const +{ + return new QOpenWFDBackingStore(window); +} + +QAbstractEventDispatcher *QOpenWFDIntegration::createEventDispatcher() const +{ + QAbstractEventDispatcher *eventDispatcher = createUnixEventDispatcher(); + return eventDispatcher; +} + +QPlatformFontDatabase *QOpenWFDIntegration::fontDatabase() const +{ + return mFontDatabase; +} + +QPlatformNativeInterface * QOpenWFDIntegration::nativeInterface() const +{ + return mNativeInterface; +} + +QPlatformPrinterSupport * QOpenWFDIntegration::printerSupport() const +{ + return mPrinterSupport; +} + +void QOpenWFDIntegration::addScreen(QOpenWFDScreen *screen) +{ + screenAdded(screen); +} diff --git a/src/plugins/platforms/openwfd/qopenwfdintegration.h b/src/plugins/platforms/openwfd/qopenwfdintegration.h new file mode 100644 index 0000000000..9b7b5329dc --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdintegration.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDINTEGRATION_H +#define QOPENWFDINTEGRATION_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QOpenWFDDevice; +class QOpenWFDScreen; + +class QOpenWFDIntegration : public QPlatformIntegration +{ +public: + QOpenWFDIntegration(); + ~QOpenWFDIntegration(); + + bool hasCapability(Capability cap) const; + QPlatformWindow *createPlatformWindow(QWindow *window) const; + QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; + QPlatformGLContext *createPlatformGLContext(QGuiGLContext *context) const; + + //This should not be a factory interface, but rather a accessor + QAbstractEventDispatcher *createEventDispatcher() const; + + QPlatformFontDatabase *fontDatabase() const; + + QPlatformNativeInterface *nativeInterface()const; + + QPlatformPrinterSupport *printerSupport() const; + + void addScreen(QOpenWFDScreen *screen); +private: + QList mScreens; + QListmDevices; + + QPlatformFontDatabase *mFontDatabase; + QPlatformNativeInterface *mNativeInterface; + QPlatformPrinterSupport *mPrinterSupport; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/openwfd/qopenwfdnativeinterface.cpp b/src/plugins/platforms/openwfd/qopenwfdnativeinterface.cpp new file mode 100644 index 0000000000..e46c0fbfa1 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdnativeinterface.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdnativeinterface.h" + +#include "qopenwfdscreen.h" +#include "qopenwfdwindow.h" +#include "qopenwfdglcontext.h" + +#include +#include + +#include + +#include + +class QOpenWFDResourceMap : public QMap +{ +public: + QOpenWFDResourceMap() + :QMap() + { + insert("wfddevice",QOpenWFDNativeInterface::WFDDevice); + insert("egldisplay",QOpenWFDNativeInterface::EglDisplay); + insert("eglcontext",QOpenWFDNativeInterface::EglContext); + insert("wfdport",QOpenWFDNativeInterface::WFDPort); + insert("wfdpipeline",QOpenWFDNativeInterface::WFDPipeline); + } +}; + +Q_GLOBAL_STATIC(QOpenWFDResourceMap, qOpenWFDResourceMap) + +void *QOpenWFDNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QGuiGLContext *context) +{ + QByteArray lowerCaseResource = resourceString.toLower(); + ResourceType resource = qOpenWFDResourceMap()->value(lowerCaseResource); + void *result = 0; + switch (resource) { + case EglContext: + result = eglContextForContext(context); + break; + default: + result = 0; + } + return result; +} + +void *QOpenWFDNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window) +{ + QByteArray lowerCaseResource = resourceString.toLower(); + ResourceType resource = qOpenWFDResourceMap()->value(lowerCaseResource); + void *result = 0; + switch (resource) { + //What should we do for int wfd handles? This is clearly not the solution + case WFDDevice: + result = (void *)wfdDeviceForWindow(window); + break; + case WFDPort: + result = (void *)wfdPortForWindow(window); + break; + case WFDPipeline: + result = (void *)wfdPipelineForWindow(window); + break; + case EglDisplay: + result = eglDisplayForWindow(window); + break; + default: + result = 0; + } + return result; +} + +WFDHandle QOpenWFDNativeInterface::wfdDeviceForWindow(QWindow *window) +{ + QOpenWFDWindow *openWFDwindow = static_cast(window->handle()); + return openWFDwindow->port()->device()->handle(); +} + +WFDHandle QOpenWFDNativeInterface::wfdPortForWindow(QWindow *window) +{ + QOpenWFDWindow *openWFDwindow = static_cast(window->handle()); + return openWFDwindow->port()->handle(); +} + +WFDHandle QOpenWFDNativeInterface::wfdPipelineForWindow(QWindow *window) + +{ + QOpenWFDWindow *openWFDwindow = static_cast(window->handle()); + return openWFDwindow->port()->pipeline(); + +} + +void *QOpenWFDNativeInterface::eglDisplayForWindow(QWindow *window) +{ + QOpenWFDWindow *openWFDwindow = static_cast(window->handle()); + return openWFDwindow->port()->device()->eglDisplay(); +} + +void * QOpenWFDNativeInterface::eglContextForContext(QGuiGLContext *context) +{ + QOpenWFDGLContext *openWFDContext = static_cast(context->handle()); + return openWFDContext->eglContext(); +} diff --git a/src/plugins/platforms/openwfd/qopenwfdnativeinterface.h b/src/plugins/platforms/openwfd/qopenwfdnativeinterface.h new file mode 100644 index 0000000000..8123bdfda1 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdnativeinterface.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDNATIVEINTERFACE_H +#define QOPENWFDNATIVEINTERFACE_H + +#include + +#include + +class QOpenWFDScreen; + +class QOpenWFDNativeInterface : public QPlatformNativeInterface +{ +public: + enum ResourceType { + WFDDevice, + EglDisplay, + EglContext, + WFDPort, + WFDPipeline + }; + + void *nativeResourceForContext(const QByteArray &resourceString, QGuiGLContext *context); + void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window); + + WFDHandle wfdDeviceForWindow(QWindow *window); + void *eglDisplayForWindow(QWindow *window); + WFDHandle wfdPortForWindow(QWindow *window); + WFDHandle wfdPipelineForWindow(QWindow *window); + + void *eglContextForContext(QGuiGLContext *context); + +private: + static QOpenWFDScreen *qPlatformScreenForWindow(QWindow *window); +}; + +#endif // QOPENWFDNATIVEINTERFACE_H diff --git a/src/plugins/platforms/openwfd/qopenwfdoutputbuffer.cpp b/src/plugins/platforms/openwfd/qopenwfdoutputbuffer.cpp new file mode 100644 index 0000000000..fb3292c31a --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdoutputbuffer.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdoutputbuffer.h" + +#include "qopenwfdport.h" + +QOpenWFDOutputBuffer::QOpenWFDOutputBuffer(const QSize &size, QOpenWFDPort *port) + : mPort(port) + , mAvailable(true) +{ + qDebug() << "creating output buffer for size" << size; + glGenRenderbuffers(1,&mRbo); + glBindRenderbuffer(GL_RENDERBUFFER, mRbo); + + mGbm_buffer = gbm_bo_create(port->device()->gbmDevice(), + size.width(), + size.height(), + GBM_BO_FORMAT_XRGB8888, + GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); + + mEglImage = port->device()->eglCreateImage(port->device()->eglDisplay(),0, EGL_NATIVE_PIXMAP_KHR, mGbm_buffer, 0); + + port->device()->glEglImageTargetRenderBufferStorage(GL_RENDERBUFFER,mEglImage); + + mWfdSource = wfdCreateSourceFromImage(port->device()->handle(),port->pipeline(),mEglImage,WFD_NONE); + if (mWfdSource == WFD_INVALID_HANDLE) { + qWarning("failed to create wfdSource from image"); + } +} + +QOpenWFDOutputBuffer::~QOpenWFDOutputBuffer() +{ + wfdDestroySource(mPort->device()->handle(),mWfdSource); + if (!mPort->device()->eglDestroyImage(mPort->device()->eglDisplay(),mEglImage)) { + qDebug() << "could not delete eglImage"; + } + gbm_bo_destroy(mGbm_buffer); + + glDeleteRenderbuffers(1, &mRbo); +} + +void QOpenWFDOutputBuffer::bindToCurrentFbo() +{ + glFramebufferRenderbuffer(GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, + mRbo); + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + qDebug() << "framebuffer not ready!"; + } +} diff --git a/src/plugins/platforms/openwfd/qopenwfdoutputbuffer.h b/src/plugins/platforms/openwfd/qopenwfdoutputbuffer.h new file mode 100644 index 0000000000..1697f076a9 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdoutputbuffer.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDOUTPUTBUFFER_H +#define QOPENWFDOUTPUTBUFFER_H + +#include "qopenwfdport.h" + +#include +#include + +class QOpenWFDOutputBuffer +{ +public: + QOpenWFDOutputBuffer(const QSize &size, QOpenWFDPort *port); + ~QOpenWFDOutputBuffer(); + void bindToCurrentFbo(); + bool isAvailable() const { return mAvailable; } + void setAvailable(bool available) { mAvailable = available; } + + WFDSource wfdSource() const { return mWfdSource; } +private: + QOpenWFDPort *mPort; + WFDSource mWfdSource; + GLuint mRbo; + EGLImageKHR mEglImage; + struct gbm_bo *mGbm_buffer; + bool mAvailable; +}; + +#endif // QOPENWFDOUTPUTBUFFER_H diff --git a/src/plugins/platforms/openwfd/qopenwfdport.cpp b/src/plugins/platforms/openwfd/qopenwfdport.cpp new file mode 100644 index 0000000000..5f38e48eed --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdport.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdport.h" + +#include "qopenwfdportmode.h" +#include "qopenwfdscreen.h" + +#include + +QOpenWFDPort::QOpenWFDPort(QOpenWFDDevice *device, WFDint portEnumeration) + : mDevice(device) + , mPortId(portEnumeration) + , mAttached(false) + , mPipelineId(WFD_INVALID_PIPELINE_ID) + , mPipeline(WFD_INVALID_HANDLE) +{ + mPort = wfdCreatePort(device->handle(),portEnumeration,0); + WFDint isPortAttached = wfdGetPortAttribi(device->handle(),mPort,WFD_PORT_ATTACHED); + if (isPortAttached) { + attach(); + } +} + +QOpenWFDPort::~QOpenWFDPort() +{ + detach(); + + wfdDestroyPort(mDevice->handle(),mPort); +} + +void QOpenWFDPort::attach() +{ + if (mAttached) { + return; + } + + //just forcing port to be on + wfdSetPortAttribi(mDevice->handle(), mPort, WFD_PORT_POWER_MODE, WFD_POWER_MODE_ON); + + int numberOfPortModes = wfdGetPortModes(mDevice->handle(),mPort,0,0); + WFDPortMode portModes[numberOfPortModes]; + int actualNumberOfPortModes = wfdGetPortModes(mDevice->handle(),mPort,portModes,numberOfPortModes); + Q_ASSERT(actualNumberOfPortModes == numberOfPortModes); + + if (!actualNumberOfPortModes) { + qDebug() << "didn't find any available port modes"; + return; + } + + for (int i = 0; i < actualNumberOfPortModes; i++) { + if (portModes[i] != WFD_INVALID_HANDLE) { + mPortModes.append(QOpenWFDPortMode(this,portModes[i])); + qDebug() << "PortModeAdded:" << mPortModes.at(mPortModes.size()-1); + } + } + + + mPixelSize = setNativeResolutionMode(); + if (mPixelSize.isEmpty()) { + qDebug() << "Could not set native resolution mode in QOpenWFPort"; + } + + WFDfloat physicalWFDSize[2]; + wfdGetPortAttribfv(mDevice->handle(),mPort,WFD_PORT_PHYSICAL_SIZE,2,physicalWFDSize); + mPhysicalSize = QSizeF(physicalWFDSize[0],physicalWFDSize[1]); + + WFDint numAvailablePipelines = wfdGetPortAttribi(mDevice->handle(),mPort,WFD_PORT_PIPELINE_ID_COUNT); + if (!numAvailablePipelines) { + qFatal("Not possible to make screen that is not possible to create WFPort with no pipline"); + } + + WFDint pipeIds[numAvailablePipelines]; + wfdGetPortAttribiv(mDevice->handle(),mPort,WFD_PORT_BINDABLE_PIPELINE_IDS,numAvailablePipelines,pipeIds); + + for (int i = 0; i < numAvailablePipelines; i++) { + if (pipeIds[i] != WFD_INVALID_PIPELINE_ID && !mDevice->isPipelineUsed(pipeIds[i])) { + mPipelineId = pipeIds[i]; + mDevice-> addToUsedPipelineSet(mPipelineId,this); + + mPipeline = wfdCreatePipeline(mDevice->handle(),mPipelineId,WFD_NONE); + if (mPipeline == WFD_INVALID_HANDLE) { + qFatal("Failed to create pipeline for port %p", this); + } + break; + } + } + + if (mPipeline == WFD_INVALID_HANDLE) { + qWarning("Failed to create pipeline and cant bind it to port"); + } + + WFDint geomerty[] = { 0, 0, mPixelSize.width(), mPixelSize.height() }; + + wfdSetPipelineAttribiv(mDevice->handle(),mPipeline, WFD_PIPELINE_SOURCE_RECTANGLE, 4, geomerty); + wfdSetPipelineAttribiv(mDevice->handle(),mPipeline, WFD_PIPELINE_DESTINATION_RECTANGLE, 4, geomerty); + + wfdBindPipelineToPort(mDevice->handle(),mPort,mPipeline); + + mScreen = new QOpenWFDScreen(this); + mDevice->integration()->addScreen(mScreen); + mAttached = true; +} + +void QOpenWFDPort::detach() +{ + if (!mAttached) + return; + + mAttached = false; + mOn = false; + + delete mScreen; + + wfdDestroyPipeline(mDevice->handle(),mPipeline); + mPipelineId = WFD_INVALID_PIPELINE_ID; + mPipeline = WFD_INVALID_HANDLE; +} + +bool QOpenWFDPort::attached() const +{ + return mAttached; +} + +QSize QOpenWFDPort::setNativeResolutionMode() +{ + WFDint nativePixelSize[2]; + wfdGetPortAttribiv(device()->handle(),mPort,WFD_PORT_NATIVE_RESOLUTION,2,nativePixelSize); + QSize nativeSize(nativePixelSize[0],nativePixelSize[1]); + + for (int i = 0; i < mPortModes.size(); i++) { + const QOpenWFDPortMode &mode = mPortModes.at(i); + if (nativeSize == mode.size()) { + wfdSetPortMode(device()->handle(),mPort,mode.handle()); + return nativeSize; + } + } + return QSize(); +} + +QSize QOpenWFDPort::pixelSize() const +{ + return mPixelSize; +} + +QSizeF QOpenWFDPort::physicalSize() const +{ + return mPhysicalSize; +} + +QOpenWFDDevice * QOpenWFDPort::device() const +{ + return mDevice; +} + +WFDPort QOpenWFDPort::handle() const +{ + return mPort; +} + +WFDint QOpenWFDPort::portId() const +{ + return mPortId; +} + +WFDPipeline QOpenWFDPort::pipeline() const +{ + return mPipeline; +} + +QOpenWFDScreen * QOpenWFDPort::screen() const +{ + return mScreen; +} diff --git a/src/plugins/platforms/openwfd/qopenwfdport.h b/src/plugins/platforms/openwfd/qopenwfdport.h new file mode 100644 index 0000000000..497c43749e --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdport.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDPORT_H +#define QOPENWFDPORT_H + +#include "qopenwfddevice.h" +#include "qopenwfdportmode.h" + +#include + +class QOpenWFDPort +{ +public: + QOpenWFDPort(QOpenWFDDevice *device, WFDint portEnumeration); + ~QOpenWFDPort(); + void attach(); + void detach(); + bool attached() const; + + QSize setNativeResolutionMode(); + + QSize pixelSize() const; + QSizeF physicalSize() const; + + QOpenWFDDevice *device() const; + WFDPort handle() const; + WFDint portId() const; + WFDPipeline pipeline() const; + QOpenWFDScreen *screen() const; + +private: + QOpenWFDDevice *mDevice; + WFDPort mPort; + WFDint mPortId; + + QList mPortModes; + + bool mAttached; + bool mOn; + QSize mPixelSize; + QSizeF mPhysicalSize; + + QOpenWFDScreen *mScreen; + + WFDint mPipelineId; + WFDPipeline mPipeline; + +}; + +#endif // QOPENWFDPORT_H diff --git a/src/plugins/platforms/openwfd/qopenwfdportmode.cpp b/src/plugins/platforms/openwfd/qopenwfdportmode.cpp new file mode 100644 index 0000000000..4e507a42a1 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdportmode.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdportmode.h" + +#include "qopenwfdport.h" + +QOpenWFDPortMode::QOpenWFDPortMode(QOpenWFDPort *port, WFDPortMode portMode) + : mPortMode(portMode) +{ + int width = wfdGetPortModeAttribi(port->device()->handle(),port->handle(),portMode,WFD_PORT_MODE_WIDTH); + int height = wfdGetPortModeAttribi(port->device()->handle(),port->handle(),portMode,WFD_PORT_MODE_HEIGHT); + mSize = QSize(width,height); + + mRefresh = wfdGetPortModeAttribf(port->device()->handle(),port->handle(),portMode,WFD_PORT_MODE_REFRESH_RATE); + mFlipMirror = wfdGetPortModeAttribi(port->device()->handle(),port->handle(),portMode,WFD_PORT_MODE_FLIP_MIRROR_SUPPORT); + mInterlaced = wfdGetPortModeAttribi(port->device()->handle(), port->handle(),portMode,WFD_PORT_MODE_INTERLACED); +} + +QDebug operator<<(QDebug s, const QOpenWFDPortMode &portMode) +{ + s.nospace() << "QOpenWFPortMode( " << portMode.size() << " Refreash: " << portMode.refreshRate() + << " FlipMirror: " << portMode.flipMirror() << " Interlaced: " << portMode.interlaced(); + return s; +} diff --git a/src/plugins/platforms/openwfd/qopenwfdportmode.h b/src/plugins/platforms/openwfd/qopenwfdportmode.h new file mode 100644 index 0000000000..dd95339404 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdportmode.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDPORTMODE_H +#define QOPENWFDPORTMODE_H + +#include + +#include + +#include + +class QOpenWFDPort; + +class QOpenWFDPortMode +{ +public: + QOpenWFDPortMode(QOpenWFDPort *port, WFDPortMode portMode); + + QSize size() const {return mSize;} + qreal refreshRate() const { return mRefresh; } + bool flipMirror() const { return mFlipMirror; } + bool interlaced() const { return mInterlaced; } + + WFDPortMode handle() const { return mPortMode; } +private: + WFDPortMode mPortMode; + + QSize mSize; + qreal mRefresh; + bool mFlipMirror; + bool mInterlaced; +}; + +QDebug operator<<(QDebug, const QOpenWFDPortMode &); +#endif // QOPENWFPORTMODE_H diff --git a/src/plugins/platforms/openwfd/qopenwfdscreen.cpp b/src/plugins/platforms/openwfd/qopenwfdscreen.cpp new file mode 100644 index 0000000000..785bee9c55 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdscreen.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdscreen.h" + +#include "qopenwfdport.h" +#include "qopenwfdoutputbuffer.h" + +#include + +QOpenWFDScreen::QOpenWFDScreen(QOpenWFDPort *port) + : mPort(port) + , mFbo(0) + , mOutputBuffers(BUFFER_NUM) + , mCurrentRenderBufferIndex(0) + , mStagedBackBufferIndex(-1) + , mCommitedBackBufferIndex(-1) + , mBackBufferIndex(-1) +{ + printf ("\n"); + printf ("Information of screen %p:\n", this); + printf (" width..........: %d\n", port->pixelSize().width()); + printf (" height.........: %d\n", port->pixelSize().height()); + printf (" physical width.: %f\n", port->physicalSize().width()); + printf (" physical height: %f\n", port->physicalSize().height()); + printf ("\n"); + + EGLDisplay display = mPort->device()->eglDisplay(); + EGLContext context = mPort->device()->eglContext(); + + if (!eglMakeCurrent(display,EGL_NO_SURFACE,EGL_NO_SURFACE,context)) { + qDebug() << "screen: eglMakeCurrent FAILED"; + } + + glGenFramebuffers(1,&mFbo); + glBindFramebuffer(GL_FRAMEBUFFER,mFbo); + + for (int i = 0; i < mOutputBuffers.size(); i++) { + mOutputBuffers[i] = new QOpenWFDOutputBuffer(mPort->pixelSize(),mPort); + } + + mStagedBackBufferIndex = mOutputBuffers.size()-1; + mOutputBuffers[mStagedBackBufferIndex]->setAvailable(false);; + commitStagedOutputBuffer(); + + mOutputBuffers.at(mCurrentRenderBufferIndex)->bindToCurrentFbo(); + + if (mPort->device()->isDeviceInitializedAndCommited()) { + mPort->device()->commit(WFD_COMMIT_ENTIRE_PORT,mPort->handle()); + } + +} + +QOpenWFDScreen::~QOpenWFDScreen() +{ + for (int i = 0; i < mOutputBuffers.size(); i++) { + delete mOutputBuffers[i]; + } + glDeleteFramebuffers(1, &mFbo); +} + +QRect QOpenWFDScreen::geometry() const +{ + return QRect(QPoint(),mPort->pixelSize()); +} + +int QOpenWFDScreen::depth() const +{ + return 32; +} + +QImage::Format QOpenWFDScreen::format() const +{ + return QImage::Format_RGB32; +} + +QSize QOpenWFDScreen::physicalSize() const +{ + return mPort->physicalSize().toSize(); +} + +QOpenWFDPort * QOpenWFDScreen::port() const +{ + return mPort; +} + +void QOpenWFDScreen::swapBuffers() +{ + glFlush(); + + setStagedBackBuffer(mCurrentRenderBufferIndex); + mCurrentRenderBufferIndex = nextAvailableRenderBuffer(); + + bindFramebuffer(); + mOutputBuffers.at(mCurrentRenderBufferIndex)->bindToCurrentFbo(); +} + +void QOpenWFDScreen::bindFramebuffer() +{ + glBindFramebuffer(GL_FRAMEBUFFER,mFbo); +} + +void QOpenWFDScreen::setStagedBackBuffer(int bufferIndex) +{ + if (mStagedBackBufferIndex >= 0) { + mOutputBuffers[mStagedBackBufferIndex]->setAvailable(true); + } + + mOutputBuffers[bufferIndex]->setAvailable(false);; + mStagedBackBufferIndex = bufferIndex; + + if (mCommitedBackBufferIndex < 0) { + commitStagedOutputBuffer(); + } +} + +void QOpenWFDScreen::commitStagedOutputBuffer() +{ + Q_ASSERT(mStagedBackBufferIndex >= 0); + wfdBindSourceToPipeline(mPort->device()->handle(), + mPort->pipeline(), + mOutputBuffers.at(mStagedBackBufferIndex)->wfdSource(), + WFD_TRANSITION_AT_VSYNC, + 0); + mPort->device()->commit(WFD_COMMIT_PIPELINE,mPort->pipeline()); + mCommitedBackBufferIndex = mStagedBackBufferIndex; + mStagedBackBufferIndex = -1; +} + +int QOpenWFDScreen::nextAvailableRenderBuffer() const +{ + while (true) { + for (int i = 0; i < mOutputBuffers.size(); i++) { + if (mOutputBuffers.at(i)->isAvailable()) { + return i; + } + } + mPort->device()->waitForPipelineBindSourceCompleteEvent(); + } +} + +void QOpenWFDScreen::pipelineBindSourceComplete() +{ + if (mBackBufferIndex >= 0) { + mOutputBuffers[mBackBufferIndex]->setAvailable(true); + } + + mBackBufferIndex = mCommitedBackBufferIndex; + mCommitedBackBufferIndex = -1; + + if (mStagedBackBufferIndex >= 0) { + commitStagedOutputBuffer(); + } +} diff --git a/src/plugins/platforms/openwfd/qopenwfdscreen.h b/src/plugins/platforms/openwfd/qopenwfdscreen.h new file mode 100644 index 0000000000..bb23744ac4 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdscreen.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDSCREEN_H +#define QOPENWFDSCREEN_H + +#include + + +#include "qopenwfdoutputbuffer.h" + +#include + +#include +#include + +#define BUFFER_NUM 4 + +class QOpenWFDPort; +class QOpenWFDScreen : public QPlatformScreen +{ +public: + QOpenWFDScreen(QOpenWFDPort *port); + ~QOpenWFDScreen(); + + QRect geometry() const; + int depth() const; + QImage::Format format() const; + QSize physicalSize() const; + + QOpenWFDPort *port() const; + + void swapBuffers(); + void bindFramebuffer(); + void pipelineBindSourceComplete(); + +private: + void setStagedBackBuffer(int bufferIndex); + void commitStagedOutputBuffer(); + int nextAvailableRenderBuffer() const; + + QOpenWFDPort *mPort; + + GLuint mFbo; + + QVarLengthArray mOutputBuffers; + int mCurrentRenderBufferIndex; + int mStagedBackBufferIndex; + int mCommitedBackBufferIndex; + int mBackBufferIndex; +}; + +#endif diff --git a/src/plugins/platforms/openwfd/qopenwfdwindow.cpp b/src/plugins/platforms/openwfd/qopenwfdwindow.cpp new file mode 100644 index 0000000000..15dc4b11c4 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdwindow.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qopenwfdwindow.h" + +#include "qopenwfdscreen.h" +#include "QtGui/QWindowSystemInterface" + +QOpenWFDWindow::QOpenWFDWindow(QWindow *window) + : QPlatformWindow(window) +{ + + QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(window); + mPort = static_cast(platformScreen)->port(); + + QWindowSystemInterface::handleGeometryChange(window,QRect(QPoint(0,0),mPort->screen()->geometry().size())); +} + +QOpenWFDPort *QOpenWFDWindow::port() const +{ + return mPort; +} + diff --git a/src/plugins/platforms/openwfd/qopenwfdwindow.h b/src/plugins/platforms/openwfd/qopenwfdwindow.h new file mode 100644 index 0000000000..3c97b014b1 --- /dev/null +++ b/src/plugins/platforms/openwfd/qopenwfdwindow.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENWFDWINDOW_H +#define QOPENWFDWINDOW_H + +#include +#include + +#include "qopenwfdport.h" + +class QOpenWFDWindow : public QPlatformWindow +{ +public: + QOpenWFDWindow(QWindow *window); + + QOpenWFDPort *port() const; + +private: + QOpenWFDPort *mPort; +}; + +#endif // QOPENWFWINDOW_H -- cgit v1.2.3