diff options
author | Andy Nichols <andy.nichols@digia.com> | 2013-01-31 15:58:14 +0100 |
---|---|---|
committer | Andy Nichols <andy.nichols@digia.com> | 2013-02-06 14:19:35 +0100 |
commit | 4cbc411f60d17a6d4f4e9d4156146537d5dc2f16 (patch) | |
tree | d73b8d890f9e9e56c988f298f47a20370890bfed /src/plugins/platforms/qwayland-brcm-egl | |
parent | 634c4f6877d63cc30914049989b5cbfd18cd15c3 (diff) |
Overhaul how platform plugins are built
Instead of building only one platform plugin through the use of a
complicated if/else structure, build a plugin for each available
hardware integration type.
Change-Id: If133576515a881274019c1ac5956605f27a9fc40
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/plugins/platforms/qwayland-brcm-egl')
9 files changed, 885 insertions, 0 deletions
diff --git a/src/plugins/platforms/qwayland-brcm-egl/main.cpp b/src/plugins/platforms/qwayland-brcm-egl/main.cpp new file mode 100644 index 000000000..9862223f7 --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qpa/qplatformintegrationplugin.h> +#include "qwaylandintegration.h" + +QT_BEGIN_NAMESPACE + +class QWaylandIntegrationPlugin : public QPlatformIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.1" FILE "qwayland-brcm-egl.json") +public: + QStringList keys() const; + QPlatformIntegration *create(const QString&, const QStringList&); +}; + +QStringList QWaylandIntegrationPlugin::keys() const +{ + QStringList list; + list << "wayland-brcm"; + return list; +} + +QPlatformIntegration *QWaylandIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + Q_UNUSED(paramList); + if (system.toLower() == "wayland-brcm") + return new QWaylandIntegration(); + + return 0; +} + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwayland-brcm-egl.json b/src/plugins/platforms/qwayland-brcm-egl/qwayland-brcm-egl.json new file mode 100644 index 000000000..48611c6ab --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwayland-brcm-egl.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "wayland-brcm" ] +} diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwayland-brcm-egl.pro b/src/plugins/platforms/qwayland-brcm-egl/qwayland-brcm-egl.pro new file mode 100644 index 000000000..1f7a9c269 --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwayland-brcm-egl.pro @@ -0,0 +1,18 @@ +PLUGIN_TYPE = platforms +load(qt_plugin) + +include(../wayland_common/wayland_common.pri) + +OTHER_FILES += \ + qwayland-brcm-egl.json + +SOURCES += qwaylandbrcmeglintegration.cpp \ + qwaylandbrcmglcontext.cpp \ + qwaylandbrcmeglwindow.cpp \ + main.cpp + +HEADERS += qwaylandbrcmeglintegration.h \ + qwaylandbrcmglcontext.h \ + qwaylandbrcmeglwindow.h + +WAYLANDSOURCES += ../../../extensions/brcm.xml diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglintegration.cpp b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglintegration.cpp new file mode 100644 index 000000000..a1d6df082 --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglintegration.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandbrcmeglintegration.h" + +#include "qwaylandglintegration.h" + +#include "qwaylandbrcmeglwindow.h" +#include "qwaylandbrcmglcontext.h" + +#include <QtCore/QDebug> + +#include "wayland-brcm-client-protocol.h" + +QWaylandBrcmEglIntegration::QWaylandBrcmEglIntegration(QWaylandDisplay *waylandDisplay) + : m_waylandDisplay(waylandDisplay->wl_display()) +{ + qDebug() << "Using Brcm-EGL"; + waylandDisplay->addRegistryListener(wlDisplayHandleGlobal, this); +} + +void QWaylandBrcmEglIntegration::wlDisplayHandleGlobal(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) +{ + Q_UNUSED(version); + if (strcmp(interface, "wl_brcm") == 0) { + QWaylandBrcmEglIntegration *integration = static_cast<QWaylandBrcmEglIntegration *>(data); + integration->m_waylandBrcm = static_cast<struct wl_brcm *>(wl_registry_bind(registry, id, &wl_brcm_interface, 1)); + } +} + +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); +} + diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglintegration.h b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglintegration.h new file mode 100644 index 000000000..de7b38a52 --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglintegration.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDBRCMEGLINTEGRATION_H +#define QWAYLANDBRCMEGLINTEGRATION_H + +#include "qwaylandglintegration.h" + +#include <EGL/egl.h> +#include <EGL/eglext.h> + +#define EGL_EGLEXT_PROTOTYPES +#include <EGL/eglext_brcm.h> + +class QWaylandWindow; +class QWindow; + +struct wl_brcm; + +class QWaylandBrcmEglIntegration : public QWaylandGLIntegration +{ +public: + QWaylandBrcmEglIntegration(QWaylandDisplay *waylandDisplay); + ~QWaylandBrcmEglIntegration(); + + void initialize(); + + bool supportsThreadedOpenGL() const { return true; } + + 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(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version); + + struct wl_display *m_waylandDisplay; + struct wl_brcm *m_waylandBrcm; + + EGLDisplay m_eglDisplay; +}; + +#endif // QWAYLANDBRCMEGLINTEGRATION_H diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglwindow.cpp b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglwindow.cpp new file mode 100644 index 000000000..82f673922 --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglwindow.cpp @@ -0,0 +1,294 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandbrcmeglwindow.h" + +#include "qwaylandbuffer.h" +#include "qwaylandscreen.h" +#include "qwaylandbrcmglcontext.h" + +#include <QtPlatformSupport/private/qeglconvenience_p.h> + +#include <QtGui/QWindow> +#include <qpa/qwindowsysteminterface.h> + +#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT +#include "windowmanager_integration/qwaylandwindowmanagerintegration.h" +#endif + +#define EGL_EGLEXT_PROTOTYPES +#include <EGL/eglext_brcm.h> + +#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<EGLint *>(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<QWaylandBrcmBuffer *>(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<QWaylandBrcmEglIntegration *>(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, 0, 0); + damage(QRect(QPoint(), size)); + } + m_mutex.unlock(); + + mDisplay->flushRequests(); +} + +bool QWaylandBrcmEglWindow::makeCurrent(EGLContext context) +{ + if (!m_count) + const_cast<QWaylandBrcmEglWindow *>(this)->createEglSurfaces(); + return eglMakeCurrent(m_eglIntegration->eglDisplay(), m_eglSurfaces[m_current], m_eglSurfaces[m_current], context); +} + diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglwindow.h b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglwindow.h new file mode 100644 index 000000000..92c0aa57e --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmeglwindow.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDBRCMEGLWINDOW_H +#define QWAYLANDBRCMEGLWINDOW_H + +#include "qwaylandwindow.h" +#include "qwaylandbrcmeglintegration.h" + +#include <QMutex> + +#include <EGL/egl.h> + +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<QWaylandBrcmBuffer *> m_pending; + + QMutex m_mutex; +}; + +#endif // QWAYLANDBRCMEGLWINDOW_H diff --git a/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmglcontext.cpp b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmglcontext.cpp new file mode 100644 index 000000000..a3b737f55 --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmglcontext.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwaylandbrcmglcontext.h" + +#include "qwaylanddisplay.h" +#include "qwaylandwindow.h" +#include "qwaylandbrcmeglwindow.h" + +#include <QtPlatformSupport/private/qeglconvenience_p.h> + +#include <qpa/qplatformopenglcontext.h> +#include <QtGui/QSurfaceFormat> + +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<QWaylandBrcmGLContext *>(share)->eglContext() : EGL_NO_CONTEXT; + + eglBindAPI(EGL_OPENGL_ES_API); + + QVector<EGLint> 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<QWaylandBrcmEglWindow *>(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<QWaylandBrcmEglWindow *>(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/qwayland-brcm-egl/qwaylandbrcmglcontext.h b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmglcontext.h new file mode 100644 index 000000000..ae248a6ad --- /dev/null +++ b/src/plugins/platforms/qwayland-brcm-egl/qwaylandbrcmglcontext.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDBRCMGLCONTEXT_H +#define QWAYLANDBRCMGLCONTEXT_H + +#include "qwaylanddisplay.h" + +#include <qpa/qplatformopenglcontext.h> + +#include <EGL/egl.h> + +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 |