From 984f2ef4b3037d7ff68d1de890ac8006c976efe3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Samuel=20R=C3=B8dal?= Date: Tue, 15 May 2012 15:05:47 +0200 Subject: [PATCH] BRCM EGL integration to handle eglCreateGlobalImageBRCM. For hardware accelerated multiprocess compositing on the raspberry pi. Change-Id: Ieb46aa7306587f89fea87098227a520f18f959a7 Reviewed-by: Laszlo Agocs Reviewed-by: Girish Ramakrishnan Reviewed-by: Paul Olav Tvete --- extensions/brcm.xml | 54 ++++ .../hardware_integration/brcm_egl/brcm_egl.pri | 11 + .../hardware_integration/brcm_egl/brcmbuffer.cpp | 79 ++++++ .../hardware_integration/brcm_egl/brcmbuffer.h | 74 ++++++ .../brcm_egl/brcmeglintegration.cpp | 198 ++++++++++++++ .../brcm_egl/brcmeglintegration.h | 75 ++++++ .../hardware_integration/hardware_integration.pri | 6 + .../wayland/gl_integration/brcm_egl/brcm_egl.pri | 11 + .../brcm_egl/qwaylandbrcmeglintegration.cpp | 129 +++++++++ .../brcm_egl/qwaylandbrcmeglintegration.h | 86 ++++++ .../brcm_egl/qwaylandbrcmeglwindow.cpp | 294 +++++++++++++++++++++ .../brcm_egl/qwaylandbrcmeglwindow.h | 97 +++++++ .../brcm_egl/qwaylandbrcmglcontext.cpp | 102 +++++++ .../brcm_egl/qwaylandbrcmglcontext.h | 80 ++++++ .../wayland/gl_integration/gl_integration.pri | 7 + 15 files changed, 1303 insertions(+) create mode 100644 extensions/brcm.xml create mode 100644 src/compositor/hardware_integration/brcm_egl/brcm_egl.pri create mode 100644 src/compositor/hardware_integration/brcm_egl/brcmbuffer.cpp create mode 100644 src/compositor/hardware_integration/brcm_egl/brcmbuffer.h create mode 100644 src/compositor/hardware_integration/brcm_egl/brcmeglintegration.cpp create mode 100644 src/compositor/hardware_integration/brcm_egl/brcmeglintegration.h create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/brcm_egl.pri create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.h create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.h create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.cpp create mode 100644 src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.h diff --git a/extensions/brcm.xml b/extensions/brcm.xml new file mode 100644 index 0000000..5bfb8db --- /dev/null +++ b/extensions/brcm.xml @@ -0,0 +1,54 @@ + + + + + Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). + Contact: http://www.qt-project.org/ + + This file is part of the plugins of the Qt Toolkit. + + $QT_BEGIN_LICENSE:BSD$ + You may use this file under the terms of the BSD license as follows: + + "Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor + the names of its contributors may be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + + $QT_END_LICENSE$ + + + + + + + + + + + + + + diff --git a/src/compositor/hardware_integration/brcm_egl/brcm_egl.pri b/src/compositor/hardware_integration/brcm_egl/brcm_egl.pri new file mode 100644 index 0000000..fdb65b3 --- /dev/null +++ b/src/compositor/hardware_integration/brcm_egl/brcm_egl.pri @@ -0,0 +1,11 @@ +LIBS += -lEGL + +SOURCES += \ + $$PWD/brcmeglintegration.cpp \ + $$PWD/brcmbuffer.cpp + +HEADERS += \ + $$PWD/brcmeglintegration.h \ + $$PWD/brcmbuffer.h + +WAYLANDSOURCES += $$PWD/../../../../extensions/brcm.xml diff --git a/src/compositor/hardware_integration/brcm_egl/brcmbuffer.cpp b/src/compositor/hardware_integration/brcm_egl/brcmbuffer.cpp new file mode 100644 index 0000000..9381346 --- /dev/null +++ b/src/compositor/hardware_integration/brcm_egl/brcmbuffer.cpp @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "brcmbuffer.h" + +#include + +#define EGL_EGLEXT_PROTOTYPES +#include + +BrcmBuffer::BrcmBuffer(Wayland::Compositor *compositor, const QSize &size, EGLint *data, size_t count) + : m_invertedY(false) + , m_handle(count) +{ + Q_UNUSED(compositor); + + base()->height = size.height(); + base()->width = size.width(); + + for (size_t i = 0; i < count; ++i) + m_handle[i] = data[i]; +} + +BrcmBuffer::~BrcmBuffer() +{ + eglDestroyGlobalImageBRCM(handle()); +} + +struct wl_buffer_interface BrcmBuffer::buffer_interface = { + BrcmBuffer::buffer_interface_destroy +}; + +void BrcmBuffer::buffer_interface_destroy(wl_client *client, wl_resource *buffer) +{ + Q_UNUSED(client); + Q_UNUSED(buffer); +} + +void BrcmBuffer::delete_resource(struct wl_resource *resource) +{ + delete reinterpret_cast(resource); +} diff --git a/src/compositor/hardware_integration/brcm_egl/brcmbuffer.h b/src/compositor/hardware_integration/brcm_egl/brcmbuffer.h new file mode 100644 index 0000000..6af3f31 --- /dev/null +++ b/src/compositor/hardware_integration/brcm_egl/brcmbuffer.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BRCMBUFFER_H +#define BRCMBUFFER_H + +#include "waylandobject.h" +#include "wayland_wrapper/wlcompositor.h" + +#include +#include + +#include + +class BrcmBuffer : public Wayland::Object +{ +public: + BrcmBuffer(Wayland::Compositor *compositor, const QSize &size, EGLint *data, size_t count); + ~BrcmBuffer(); + + static struct wl_buffer_interface buffer_interface; + static void delete_resource(struct wl_resource *resource); + + bool isYInverted() const { return m_invertedY; } + void setInvertedY(bool inverted) { m_invertedY = inverted; } + + EGLint *handle() { return m_handle.data(); } + + static void buffer_interface_destroy(struct wl_client *client, + struct wl_resource *buffer); + +private: + QVector m_handle; + bool m_invertedY; +}; + +#endif // BRCMBUFFER_H diff --git a/src/compositor/hardware_integration/brcm_egl/brcmeglintegration.cpp b/src/compositor/hardware_integration/brcm_egl/brcmeglintegration.cpp new file mode 100644 index 0000000..2bba5a7 --- /dev/null +++ b/src/compositor/hardware_integration/brcm_egl/brcmeglintegration.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "brcmeglintegration.h" +#include "brcmbuffer.h" +#include "wayland_wrapper/wlcompositor.h" +#include "wayland_wrapper/wlsurface.h" +#include "compositor_api/waylandsurface.h" +#include +#include +#include +#include +#include + +#include +#include + +#define EGL_EGLEXT_PROTOTYPES +#include + +#include +#include + +#include "wayland-brcm-server-protocol.h" + +GraphicsHardwareIntegration * GraphicsHardwareIntegration::createGraphicsHardwareIntegration(WaylandCompositor *compositor) +{ + return new BrcmEglIntegration(compositor); +} + +class BrcmEglIntegrationPrivate +{ +public: + BrcmEglIntegrationPrivate() + : egl_display(EGL_NO_DISPLAY) + , valid(false) + { } + EGLDisplay egl_display; + bool valid; + PFNEGLQUERYGLOBALIMAGEBRCMPROC eglQueryGlobalImageBRCM; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES; + PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; + PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; +}; + +BrcmEglIntegration::BrcmEglIntegration(WaylandCompositor *compositor) + : GraphicsHardwareIntegration(compositor) + , d_ptr(new BrcmEglIntegrationPrivate) +{ +} + +void BrcmEglIntegration::initializeHardware(Wayland::Display *waylandDisplay) +{ + Q_D(BrcmEglIntegration); + + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + if (nativeInterface) { + d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay"); + if (!d->egl_display) + qWarning("Failed to acquire EGL display from platform integration"); + + d->eglQueryGlobalImageBRCM = eglQueryGlobalImageBRCM; + + if (!d->eglQueryGlobalImageBRCM) { + qWarning("Failed to resolve eglQueryGlobalImageBRCM"); + return; + } + + d->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); + + if (!d->glEGLImageTargetTexture2DOES) { + qWarning("Failed to resolve glEGLImageTargetTexture2DOES"); + return; + } + + d->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); + + if (!d->eglCreateImageKHR) { + qWarning("Failed to resolve eglCreateImageKHR"); + return; + } + + d->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); + + if (!d->eglDestroyImageKHR) { + qWarning("Failed to resolve eglDestroyImageKHR"); + return; + } + d->valid = true; + } + + wl_display_add_global(waylandDisplay->handle(), &wl_brcm_interface, this, brcm_bind_func); +} + +GLuint BrcmEglIntegration::createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *context) +{ + Q_D(BrcmEglIntegration); + if (!d->valid) { + qWarning("createTextureFromBuffer() failed\n"); + return 0; + } + + BrcmBuffer *brcmBuffer = Wayland::wayland_cast(buffer); + + if (!d->eglQueryGlobalImageBRCM(brcmBuffer->handle(), brcmBuffer->handle() + 2)) { + qWarning("eglQueryGlobalImageBRCM failed!"); + return 0; + } + + EGLImageKHR image = d->eglCreateImageKHR(d->egl_display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)brcmBuffer->handle(), NULL); + if (image == EGL_NO_IMAGE_KHR) + qWarning("eglCreateImageKHR() failed: %x\n", eglGetError()); + + GLuint textureId; + glGenTextures(1, &textureId); + + glBindTexture(GL_TEXTURE_2D, textureId); + + d->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + d->eglDestroyImageKHR(d->egl_display, image); + + return textureId; +} + +void BrcmEglIntegration::create_buffer(struct wl_client *client, + struct wl_resource *brcm, + uint32_t id, + int32_t width, + int32_t height, + wl_array *data) +{ + BrcmEglIntegration *that = static_cast(brcm->data); + BrcmBuffer *buffer = new BrcmBuffer(that->m_compositor->handle(), QSize(width, height), static_cast(data->data), data->size / sizeof(EGLint)); + buffer->addClientResource(client, &buffer->base()->resource, + id, &wl_buffer_interface, + &BrcmBuffer::buffer_interface, + BrcmBuffer::delete_resource); +} + +static struct wl_brcm_interface brcm_interface = { + BrcmEglIntegration::create_buffer +}; + +void BrcmEglIntegration::brcm_bind_func(struct wl_client *client, void *data, uint32_t version, uint32_t id) +{ + Q_UNUSED(version); + BrcmEglIntegration *integration = static_cast(data); + wl_client_add_object(client, &wl_brcm_interface, &brcm_interface, id, integration); +} + +bool BrcmEglIntegration::isYInverted(struct wl_buffer *buffer) const +{ + Q_UNUSED(buffer); + return false; +} diff --git a/src/compositor/hardware_integration/brcm_egl/brcmeglintegration.h b/src/compositor/hardware_integration/brcm_egl/brcmeglintegration.h new file mode 100644 index 0000000..e17af9c --- /dev/null +++ b/src/compositor/hardware_integration/brcm_egl/brcmeglintegration.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef BRCMEGLINTEGRATION_H +#define BRCMEGLINTEGRATION_H + +#include "hardware_integration/graphicshardwareintegration.h" +#include + +class BrcmEglIntegrationPrivate; + +class BrcmEglIntegration : public GraphicsHardwareIntegration +{ + Q_DECLARE_PRIVATE(BrcmEglIntegration) +public: + BrcmEglIntegration(WaylandCompositor *compositor); + + void initializeHardware(Wayland::Display *waylandDisplay); + + GLuint createTextureFromBuffer(wl_buffer *buffer, QOpenGLContext *context); + bool isYInverted(struct wl_buffer *) const; + + static void create_buffer(struct wl_client *client, + struct wl_resource *brcm, + uint32_t id, + int32_t width, + int32_t height, + wl_array *data); + + static void brcm_bind_func(struct wl_client *client, void *data, uint32_t version, uint32_t id); + +private: + Q_DISABLE_COPY(BrcmEglIntegration) + QScopedPointer d_ptr; +}; + +#endif // BRCMEGLINTEGRATION_H + diff --git a/src/compositor/hardware_integration/hardware_integration.pri b/src/compositor/hardware_integration/hardware_integration.pri index d50402f..c6735aa 100644 --- a/src/compositor/hardware_integration/hardware_integration.pri +++ b/src/compositor/hardware_integration/hardware_integration.pri @@ -16,6 +16,9 @@ isEmpty(QT_WAYLAND_GL_CONFIG):QT_WAYLAND_GL_CONFIG = $$(QT_WAYLAND_GL_CONFIG) isEqual(QT_WAYLAND_GL_CONFIG, xcomposite_egl) { QT_WAYLAND_GL_INTEGRATION = xcomposite_egl CONFIG += xcomposite_egl + } else:isEqual(QT_WAYLAND_GL_CONFIG, brcm_egl) { + QT_WAYLAND_GL_INTEGRATION = brcm_egl + CONFIG += brcm_egl } else { QT_WAYLAND_GL_INTEGRATION = $$QT_WAYLAND_GL_CONFIG CONFIG += wayland_egl @@ -31,6 +34,9 @@ isEmpty(QT_WAYLAND_GL_CONFIG):QT_WAYLAND_GL_CONFIG = $$(QT_WAYLAND_GL_CONFIG) system(echo "Qt-Compositor configured as raster only compositor") } +brcm_egl { + include (brcm_egl/brcm_egl.pri) +} wayland_egl { include (wayland_egl/wayland_egl.pri) } diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/brcm_egl.pri b/src/plugins/platforms/wayland/gl_integration/brcm_egl/brcm_egl.pri new file mode 100644 index 0000000..12b10d2 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/brcm_egl.pri @@ -0,0 +1,11 @@ +LIBS += -lEGL -lGLESv2 +INCLUDEPATH += $$PWD +SOURCES += $$PWD/qwaylandbrcmeglintegration.cpp \ + $$PWD/qwaylandbrcmglcontext.cpp \ + $$PWD/qwaylandbrcmeglwindow.cpp + +HEADERS += $$PWD/qwaylandbrcmeglintegration.h \ + $$PWD/qwaylandbrcmglcontext.h \ + $$PWD/qwaylandbrcmeglwindow.h + +WAYLANDSOURCES += $$PWD/../../../../../../extensions/brcm.xml diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.cpp b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.cpp new file mode 100644 index 0000000..893ff16 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 "qwaylandbrcmeglintegration.h" + +#include "gl_integration/qwaylandglintegration.h" + +#include "qwaylandbrcmeglwindow.h" +#include "qwaylandbrcmglcontext.h" + +#include + +#include "wayland-brcm-client-protocol.h" + +QWaylandBrcmEglIntegration::QWaylandBrcmEglIntegration(struct wl_display *waylandDisplay) + : m_waylandDisplay(waylandDisplay) +{ + wl_display_add_global_listener(waylandDisplay, wlDisplayHandleGlobal, this); + qDebug() << "Using Brcm-EGL"; +} + +void QWaylandBrcmEglIntegration::wlDisplayHandleGlobal(wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data) +{ + Q_UNUSED(version); + if (strcmp(interface, "wl_brcm") == 0) { + QWaylandBrcmEglIntegration *integration = static_cast(data); + integration->m_waylandBrcm = static_cast(wl_display_bind(display, id, &wl_brcm_interface)); + } +} + +wl_brcm *QWaylandBrcmEglIntegration::waylandBrcm() const +{ + return m_waylandBrcm; +} + +QWaylandBrcmEglIntegration::~QWaylandBrcmEglIntegration() +{ + eglTerminate(m_eglDisplay); +} + +void QWaylandBrcmEglIntegration::initialize() +{ + EGLint major,minor; + m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); + if (m_eglDisplay == NULL) { + qWarning("EGL not available"); + } else { + if (!eglInitialize(m_eglDisplay, &major, &minor)) { + qWarning("failed to initialize EGL display"); + return; + } + + eglFlushBRCM = (PFNEGLFLUSHBRCMPROC)eglGetProcAddress("eglFlushBRCM"); + if (!eglFlushBRCM) { + qWarning("failed to resolve eglFlushBRCM, performance will suffer"); + } + + eglCreateGlobalImageBRCM = ::eglCreateGlobalImageBRCM; + if (!eglCreateGlobalImageBRCM) { + qWarning("failed to resolve eglCreateGlobalImageBRCM"); + return; + } + + eglDestroyGlobalImageBRCM = ::eglDestroyGlobalImageBRCM; + if (!eglDestroyGlobalImageBRCM) { + qWarning("failed to resolve eglDestroyGlobalImageBRCM"); + return; + } + } +} + +QWaylandWindow *QWaylandBrcmEglIntegration::createEglWindow(QWindow *window) +{ + return new QWaylandBrcmEglWindow(window); +} + +QPlatformOpenGLContext *QWaylandBrcmEglIntegration::createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const +{ + return new QWaylandBrcmGLContext(m_eglDisplay, glFormat, share); +} + +EGLDisplay QWaylandBrcmEglIntegration::eglDisplay() const +{ + return m_eglDisplay; +} + +QWaylandGLIntegration *QWaylandGLIntegration::createGLIntegration(QWaylandDisplay *waylandDisplay) +{ + return new QWaylandBrcmEglIntegration(waylandDisplay->wl_display()); +} + diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.h b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.h new file mode 100644 index 0000000..6a46de9 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglintegration.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 QWAYLANDBRCMEGLINTEGRATION_H +#define QWAYLANDBRCMEGLINTEGRATION_H + +#include "gl_integration/qwaylandglintegration.h" + +#include +#include + +#define EGL_EGLEXT_PROTOTYPES +#include + +class QWaylandWindow; +class QWindow; + +struct wl_brcm; + +class QWaylandBrcmEglIntegration : public QWaylandGLIntegration +{ +public: + QWaylandBrcmEglIntegration(struct wl_display *waylandDisplay); + ~QWaylandBrcmEglIntegration(); + + void initialize(); + + QWaylandWindow *createEglWindow(QWindow *window); + QPlatformOpenGLContext *createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const; + + EGLDisplay eglDisplay() const; + + struct wl_brcm *waylandBrcm() const; + + PFNEGLFLUSHBRCMPROC eglFlushBRCM; + PFNEGLCREATEGLOBALIMAGEBRCMPROC eglCreateGlobalImageBRCM; + PFNEGLDESTROYGLOBALIMAGEBRCMPROC eglDestroyGlobalImageBRCM; + +private: + static void wlDisplayHandleGlobal(wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data); + + struct wl_display *m_waylandDisplay; + struct wl_brcm *m_waylandBrcm; + + EGLDisplay m_eglDisplay; +}; + +#endif // QWAYLANDBRCMEGLINTEGRATION_H diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.cpp b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.cpp new file mode 100644 index 0000000..37b35fb --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.cpp @@ -0,0 +1,294 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 "qwaylandbrcmeglwindow.h" + +#include "qwaylandbuffer.h" +#include "qwaylandscreen.h" +#include "qwaylandbrcmglcontext.h" + +#include + +#include +#include + +#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT +#include "windowmanager_integration/qwaylandwindowmanagerintegration.h" +#endif + +#define EGL_EGLEXT_PROTOTYPES +#include + +#include "wayland-brcm-client-protocol.h" + +class QWaylandBrcmBuffer : public QWaylandBuffer +{ +public: + QWaylandBrcmBuffer(QWaylandDisplay *display, + struct wl_brcm *brcm, + const QSize &size, + EGLint *data, + int count) + : m_size(size) + , m_released(true) + , m_display(display) + { + wl_array_init(&m_array); + m_data = static_cast(wl_array_add(&m_array, count * sizeof(EGLint))); + + for (int i = 0; i < count; ++i) + m_data[i] = data[i]; + + mBuffer = wl_brcm_create_buffer(brcm, size.width(), size.height(), &m_array); + + static const struct wl_buffer_listener buffer_listener = { + QWaylandBrcmBuffer::buffer_release + }; + + wl_buffer_add_listener(mBuffer, &buffer_listener, this); + } + + ~QWaylandBrcmBuffer() + { + wl_array_release(&m_array); + } + + QSize size() const { return m_size; } + + void bind() + { + m_released = false; + } + + void waitForRelease() + { + if (m_released) + return; + m_mutex.lock(); + while (!m_released) + m_condition.wait(&m_mutex); + m_mutex.unlock(); + } + + static void buffer_release(void *data, wl_buffer *buffer) + { + Q_UNUSED(buffer); + m_mutex.lock(); + static_cast(data)->m_released = true; + m_condition.wakeAll(); + m_mutex.unlock(); + } + +private: + static QWaitCondition m_condition; + static QMutex m_mutex; + + QSize m_size; + bool m_released; + wl_array m_array; + EGLint *m_data; + QWaylandDisplay *m_display; +}; + +QWaitCondition QWaylandBrcmBuffer::m_condition; +QMutex QWaylandBrcmBuffer::m_mutex; + +QWaylandBrcmEglWindow::QWaylandBrcmEglWindow(QWindow *window) + : QWaylandWindow(window) + , m_eglIntegration(static_cast(mDisplay->eglIntegration())) + , m_eglConfig(0) + , m_format(window->format()) + , m_current(0) + , m_count(0) +{ +} + +QWaylandBrcmEglWindow::~QWaylandBrcmEglWindow() +{ + destroyEglSurfaces(); +} + +QWaylandWindow::WindowType QWaylandBrcmEglWindow::windowType() const +{ + return QWaylandWindow::Egl; +} + +void QWaylandBrcmEglWindow::setGeometry(const QRect &rect) +{ + destroyEglSurfaces(); + QWaylandWindow::setGeometry(rect); +} + +QSurfaceFormat QWaylandBrcmEglWindow::format() const +{ + return m_format; +} + +void QWaylandBrcmEglWindow::destroyEglSurfaces() +{ + for (int i = 0; i < m_count; ++i) { + if (m_eglSurfaces[i]) { + eglDestroySurface(m_eglIntegration->eglDisplay(), m_eglSurfaces[i]); + m_eglSurfaces[i] = 0; + // the server does this + //m_eglIntegration->eglDestroyGlobalImageBRCM(&m_globalImages[5*i]); + delete m_buffers[i]; + } + } + + m_count = 0; + m_current = 0; +} + +QSurfaceFormat brcmFixFormat(const QSurfaceFormat &f) +{ + QSurfaceFormat format = f; + format.setRedBufferSize(8); + format.setGreenBufferSize(8); + format.setBlueBufferSize(8); + format.setAlphaBufferSize(8); + return format; +} + +void QWaylandBrcmEglWindow::createEglSurfaces() +{ + QSize size(geometry().size()); + + m_count = window()->format().swapBehavior() == QSurfaceFormat::TripleBuffer ? 3 : 2; + + m_eglConfig = q_configFromGLFormat(m_eglIntegration->eglDisplay(), brcmFixFormat(window()->format()), true, EGL_PIXMAP_BIT); + + m_format = q_glFormatFromConfig(m_eglIntegration->eglDisplay(), m_eglConfig); + + EGLint pixel_format = EGL_PIXEL_FORMAT_ARGB_8888_BRCM; + + EGLint rt; + eglGetConfigAttrib(m_eglIntegration->eglDisplay(), m_eglConfig, EGL_RENDERABLE_TYPE, &rt); + + if (rt & EGL_OPENGL_ES_BIT) { + pixel_format |= EGL_PIXEL_FORMAT_RENDER_GLES_BRCM; + pixel_format |= EGL_PIXEL_FORMAT_GLES_TEXTURE_BRCM; + } + + if (rt & EGL_OPENGL_ES2_BIT) { + pixel_format |= EGL_PIXEL_FORMAT_RENDER_GLES2_BRCM; + pixel_format |= EGL_PIXEL_FORMAT_GLES2_TEXTURE_BRCM; + } + + if (rt & EGL_OPENVG_BIT) { + pixel_format |= EGL_PIXEL_FORMAT_RENDER_VG_BRCM; + pixel_format |= EGL_PIXEL_FORMAT_VG_IMAGE_BRCM; + } + + if (rt & EGL_OPENGL_BIT) { + pixel_format |= EGL_PIXEL_FORMAT_RENDER_GL_BRCM; + } + + memset(m_globalImages, 0, 5 * m_count * sizeof(EGLint)); + for (int i = 0; i < m_count; ++i) { + m_eglIntegration->eglCreateGlobalImageBRCM(size.width(), size.height(), pixel_format, + 0, size.width() * 4, &m_globalImages[5*i]); + + m_globalImages[5*i+2] = size.width(); + m_globalImages[5*i+3] = size.height(); + m_globalImages[5*i+4] = pixel_format; + + EGLint attrs[] = { + EGL_VG_COLORSPACE, EGL_VG_COLORSPACE_sRGB, + EGL_VG_ALPHA_FORMAT, pixel_format & EGL_PIXEL_FORMAT_ARGB_8888_PRE_BRCM ? EGL_VG_ALPHA_FORMAT_PRE : EGL_VG_ALPHA_FORMAT_NONPRE, + EGL_NONE + }; + + m_eglSurfaces[i] = eglCreatePixmapSurface(m_eglIntegration->eglDisplay(), m_eglConfig, (EGLNativePixmapType)&m_globalImages[5*i], attrs); + if (m_eglSurfaces[i] == EGL_NO_SURFACE) + qFatal("eglCreatePixmapSurface failed: %x, global image id: %d %d\n", eglGetError(), m_globalImages[5*i], m_globalImages[5*i+1]); + m_buffers[i] = new QWaylandBrcmBuffer(mDisplay, m_eglIntegration->waylandBrcm(), size, &m_globalImages[5*i], 5); + } +} + +void QWaylandBrcmEglWindow::swapBuffers() +{ + if (m_eglIntegration->eglFlushBRCM) { + m_eglIntegration->eglFlushBRCM(); + } else { + glFlush(); + glFinish(); + } + + m_buffers[m_current]->bind(); + + m_mutex.lock(); + m_pending << m_buffers[m_current]; + m_mutex.unlock(); + + // can't use a direct call since swapBuffers might be called from a separate thread + QMetaObject::invokeMethod(this, "flushBuffers"); + + m_current = (m_current + 1) % m_count; + + m_buffers[m_current]->waitForRelease(); +} + +void QWaylandBrcmEglWindow::flushBuffers() +{ + if (m_pending.isEmpty()) + return; + + QSize size = geometry().size(); + + m_mutex.lock(); + while (!m_pending.isEmpty()) { + QWaylandBrcmBuffer *buffer = m_pending.takeFirst(); + attach(buffer); + damage(QRect(QPoint(), size)); + } + m_mutex.unlock(); + + mDisplay->flushRequests(); +} + +bool QWaylandBrcmEglWindow::makeCurrent(EGLContext context) +{ + if (!m_count) + const_cast(this)->createEglSurfaces(); + return eglMakeCurrent(m_eglIntegration->eglDisplay(), m_eglSurfaces[m_current], m_eglSurfaces[m_current], context); +} + diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.h b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.h new file mode 100644 index 0000000..340f482 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmeglwindow.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 QWAYLANDBRCMEGLWINDOW_H +#define QWAYLANDBRCMEGLWINDOW_H + +#include "qwaylandwindow.h" +#include "qwaylandbrcmeglintegration.h" + +#include + +#include + +class QWaylandGLContext; +class QWaylandBrcmBuffer; + +class QWaylandBrcmEglWindow : public QObject, public QWaylandWindow +{ + Q_OBJECT +public: + QWaylandBrcmEglWindow(QWindow *window); + ~QWaylandBrcmEglWindow(); + WindowType windowType() const; + void setGeometry(const QRect &rect); + + QSurfaceFormat format() const; + + bool makeCurrent(EGLContext context); + void swapBuffers(); + +private slots: + void flushBuffers(); + +private: + void createEglSurfaces(); + void destroyEglSurfaces(); + + QWaylandBrcmEglIntegration *m_eglIntegration; + struct wl_egl_window *m_waylandEglWindow; + + const QWaylandWindow *m_parentWindow; + + EGLConfig m_eglConfig; + + EGLint m_globalImages[3*5]; + EGLSurface m_eglSurfaces[3]; + + QWaylandBrcmBuffer *m_buffers[3]; + QSurfaceFormat m_format; + + int m_current; + int m_count; + + QList m_pending; + + QMutex m_mutex; +}; + +#endif // QWAYLANDBRCMEGLWINDOW_H diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.cpp b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.cpp new file mode 100644 index 0000000..67e9b75 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 "qwaylandbrcmglcontext.h" + +#include "qwaylanddisplay.h" +#include "qwaylandwindow.h" +#include "qwaylandbrcmeglwindow.h" + +#include + +#include +#include + +extern QSurfaceFormat brcmFixFormat(const QSurfaceFormat &format); + +QWaylandBrcmGLContext::QWaylandBrcmGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformOpenGLContext *share) + : QPlatformOpenGLContext() + , m_eglDisplay(eglDisplay) + , m_config(q_configFromGLFormat(m_eglDisplay, brcmFixFormat(format), true)) + , m_format(q_glFormatFromConfig(m_eglDisplay, m_config)) +{ + EGLContext shareEGLContext = share ? static_cast(share)->eglContext() : EGL_NO_CONTEXT; + + eglBindAPI(EGL_OPENGL_ES_API); + + QVector eglContextAttrs; + eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); + eglContextAttrs.append(format.majorVersion() == 1 ? 1 : 2); + eglContextAttrs.append(EGL_NONE); + + m_context = eglCreateContext(m_eglDisplay, m_config, shareEGLContext, eglContextAttrs.constData()); +} + +QWaylandBrcmGLContext::~QWaylandBrcmGLContext() +{ + eglDestroyContext(m_eglDisplay, m_context); +} + +bool QWaylandBrcmGLContext::makeCurrent(QPlatformSurface *surface) +{ + return static_cast(surface)->makeCurrent(m_context); +} + +void QWaylandBrcmGLContext::doneCurrent() +{ + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + +void QWaylandBrcmGLContext::swapBuffers(QPlatformSurface *surface) +{ + static_cast(surface)->swapBuffers(); +} + +void (*QWaylandBrcmGLContext::getProcAddress(const QByteArray &procName)) () +{ + return eglGetProcAddress(procName.constData()); +} + +EGLConfig QWaylandBrcmGLContext::eglConfig() const +{ + return m_config; +} + diff --git a/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.h b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.h new file mode 100644 index 0000000..75dc786 --- /dev/null +++ b/src/plugins/platforms/wayland/gl_integration/brcm_egl/qwaylandbrcmglcontext.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** 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 QWAYLANDBRCMGLCONTEXT_H +#define QWAYLANDBRCMGLCONTEXT_H + +#include "qwaylanddisplay.h" + +#include + +#include + +class QWaylandWindow; +class QWaylandGLWindowSurface; + +class QWaylandBrcmGLContext : public QPlatformOpenGLContext { +public: + QWaylandBrcmGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformOpenGLContext *share); + ~QWaylandBrcmGLContext(); + + void swapBuffers(QPlatformSurface *surface); + + bool makeCurrent(QPlatformSurface *surface); + void doneCurrent(); + + void (*getProcAddress(const QByteArray &procName)) (); + + QSurfaceFormat format() const { return m_format; } + + EGLConfig eglConfig() const; + EGLContext eglContext() const { return m_context; } + +private: + EGLDisplay m_eglDisplay; + + EGLContext m_context; + EGLConfig m_config; + QSurfaceFormat m_format; +}; + + +#endif // QWAYLANDBRCMGLCONTEXT_H diff --git a/src/plugins/platforms/wayland/gl_integration/gl_integration.pri b/src/plugins/platforms/wayland/gl_integration/gl_integration.pri index d7e268a..f96a9ca 100644 --- a/src/plugins/platforms/wayland/gl_integration/gl_integration.pri +++ b/src/plugins/platforms/wayland/gl_integration/gl_integration.pri @@ -16,6 +16,9 @@ contains(QT_CONFIG, opengl):!equals(QT_WAYLAND_GL_CONFIG, nogl) { } else:isEqual(QT_WAYLAND_GL_CONFIG,readback) { QT_WAYLAND_GL_INTEGRATION = readback_egl CONFIG += readback_egl + } else:isEqual(QT_WAYLAND_GL_CONFIG, brcm_egl) { + QT_WAYLAND_GL_INTEGRATION = brcm_egl + CONFIG += brcm_egl } else { QT_WAYLAND_GL_INTEGRATION = $$QT_WAYLAND_GL_CONFIG CONFIG += wayland_egl @@ -45,6 +48,10 @@ readback_egl { include ($$PWD/readback_egl/readback_egl.pri) } +brcm_egl { + include ($$PWD/brcm_egl/brcm_egl.pri) +} + readback_glx { include ($$PWD/readback_glx/readback_glx.pri) } -- 2.7.4