diff options
Diffstat (limited to 'src/plugins/platforms/qwayland-egl')
12 files changed, 1022 insertions, 0 deletions
diff --git a/src/plugins/platforms/qwayland-egl/main.cpp b/src/plugins/platforms/qwayland-egl/main.cpp new file mode 100644 index 000000000..222cc1e85 --- /dev/null +++ b/src/plugins/platforms/qwayland-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-egl.json") +public: + QStringList keys() const; + QPlatformIntegration *create(const QString&, const QStringList&); +}; + +QStringList QWaylandIntegrationPlugin::keys() const +{ + QStringList list; + list << "wayland" << "wayland-egl"; + return list; +} + +QPlatformIntegration *QWaylandIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + Q_UNUSED(paramList); + if (system.toLower() == "wayland" || system.toLower() == "wayland-egl") + return new QWaylandIntegration(); + + return 0; +} + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/platforms/qwayland-egl/qwayland-egl.json b/src/plugins/platforms/qwayland-egl/qwayland-egl.json new file mode 100644 index 000000000..3ab70d3c3 --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwayland-egl.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "wayland", "wayland-egl" ] +} diff --git a/src/plugins/platforms/qwayland-egl/qwayland-egl.pro b/src/plugins/platforms/qwayland-egl/qwayland-egl.pro new file mode 100644 index 000000000..cdebf9bbc --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwayland-egl.pro @@ -0,0 +1,26 @@ +PLUGIN_TYPE = platforms +load(qt_plugin) + +include(../wayland_common/wayland_common.pri) + +OTHER_FILES += \ + qwayland-egl.json + +!contains(QT_CONFIG, no-pkg-config) { + CONFIG += link_pkgconfig + PKGCONFIG += wayland-egl egl +} else { + LIBS += -lwayland-egl -lEGL +} + +SOURCES += qwaylandeglintegration.cpp \ + qwaylandglcontext.cpp \ + qwaylandeglwindow.cpp \ + qwaylandegldecoration.cpp \ + main.cpp + +HEADERS += qwaylandeglintegration.h \ + qwaylandglcontext.h \ + qwaylandeglwindow.h \ + qwaylandegldecoration.h \ + qwaylandeglinclude.h diff --git a/src/plugins/platforms/qwayland-egl/qwaylandegldecoration.cpp b/src/plugins/platforms/qwayland-egl/qwaylandegldecoration.cpp new file mode 100644 index 000000000..5cf5239a8 --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandegldecoration.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 "qwaylandegldecoration.h" + +#include "qwaylandeglwindow.h" + +#include <QtGui/QPainter> +#include <QtGui/QOpenGLPaintDevice> + +QWaylandEglDecoration::QWaylandEglDecoration(QWaylandEglWindow *window) + : QWaylandDecoration(window) +{ +} + +QWaylandEglDecoration::~QWaylandEglDecoration() +{ +} + +void QWaylandEglDecoration::paintDecoration() +{ + glClearColor(backgroundColor().redF(), backgroundColor().greenF(), backgroundColor().blueF(), backgroundColor().alphaF()); + glClear(GL_COLOR_BUFFER_BIT); + + QOpenGLPaintDevice device(window()->frameGeometry().size()); + paint(&device); +} diff --git a/src/plugins/platforms/qwayland-egl/qwaylandegldecoration.h b/src/plugins/platforms/qwayland-egl/qwaylandegldecoration.h new file mode 100644 index 000000000..c1ef6d54a --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandegldecoration.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** 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 QWAYLANDEGLDECORATION_H +#define QWAYLANDEGLDECORATION_H + +#include "qwaylanddecoration.h" + +class QWaylandEglWindow; + +class QWaylandEglDecoration : public QWaylandDecoration +{ +public: + QWaylandEglDecoration(QWaylandEglWindow *window); + ~QWaylandEglDecoration(); + + void paintDecoration(); + +}; + +#endif // QWAYLANDEGLDECORATION_H diff --git a/src/plugins/platforms/qwayland-egl/qwaylandeglinclude.h b/src/plugins/platforms/qwayland-egl/qwaylandeglinclude.h new file mode 100644 index 000000000..fb42d43c1 --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandeglinclude.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 QWAYLANDEGLINCLUDE_H +#define QWAYLANDEGLINCLUDE_H + +#include <string.h> +#include <wayland-client.h> + +#include <wayland-egl.h> + +#define GL_GLEXT_PROTOTYPES +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#define EGL_EGLEXT_PROTOTYPES +#include <EGL/egl.h> +#include <EGL/eglext.h> + +#endif // QWAYLANDEGLINCLUDE_H diff --git a/src/plugins/platforms/qwayland-egl/qwaylandeglintegration.cpp b/src/plugins/platforms/qwayland-egl/qwaylandeglintegration.cpp new file mode 100644 index 000000000..b64798f66 --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandeglintegration.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** 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 "qwaylandeglintegration.h" + +#include "qwaylandglintegration.h" + +#include "qwaylandeglwindow.h" +#include "qwaylandglcontext.h" + +#include <wayland-client.h> + +#include <QtCore/QDebug> + +QWaylandEglIntegration::QWaylandEglIntegration(struct wl_display *waylandDisplay) + : m_waylandDisplay(waylandDisplay) +{ + qDebug() << "Using Wayland-EGL"; +} + + +QWaylandEglIntegration::~QWaylandEglIntegration() +{ + eglTerminate(m_eglDisplay); +} + +void QWaylandEglIntegration::initialize() +{ + QByteArray eglPlatform = qgetenv("EGL_PLATFORM"); + if (eglPlatform.isEmpty()) { + setenv("EGL_PLATFORM","wayland",true); + } + + EGLint major,minor; + m_eglDisplay = eglGetDisplay((EGLNativeDisplayType) m_waylandDisplay); + if (m_eglDisplay == NULL) { + qWarning("EGL not available"); + } else { + if (!eglInitialize(m_eglDisplay, &major, &minor)) { + qWarning("failed to initialize EGL display"); + return; + } + } +} + +bool QWaylandEglIntegration::supportsThreadedOpenGL() const +{ + return false; +} + +QWaylandWindow *QWaylandEglIntegration::createEglWindow(QWindow *window) +{ + return new QWaylandEglWindow(window); +} + +QPlatformOpenGLContext *QWaylandEglIntegration::createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const +{ + return new QWaylandGLContext(m_eglDisplay, glFormat, share); +} + +EGLDisplay QWaylandEglIntegration::eglDisplay() const +{ + return m_eglDisplay; +} + +QWaylandGLIntegration *QWaylandGLIntegration::createGLIntegration(QWaylandDisplay *waylandDisplay) +{ + return new QWaylandEglIntegration(waylandDisplay->wl_display()); +} diff --git a/src/plugins/platforms/qwayland-egl/qwaylandeglintegration.h b/src/plugins/platforms/qwayland-egl/qwaylandeglintegration.h new file mode 100644 index 000000000..77a365dfa --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandeglintegration.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 QWAYLANDEGLINTEGRATION_H +#define QWAYLANDEGLINTEGRATION_H + +#include "qwaylandglintegration.h" + +#include "qwaylandeglinclude.h" + +class QWaylandWindow; +class QWindow; + +class QWaylandEglIntegration : public QWaylandGLIntegration +{ +public: + QWaylandEglIntegration(struct wl_display *waylandDisplay); + ~QWaylandEglIntegration(); + + void initialize(); + bool supportsThreadedOpenGL() const; + + QWaylandWindow *createEglWindow(QWindow *window); + QPlatformOpenGLContext *createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const; + + EGLDisplay eglDisplay() const; + +private: + struct wl_display *m_waylandDisplay; + + EGLDisplay m_eglDisplay; +}; + +#endif // QWAYLANDEGLINTEGRATION_H diff --git a/src/plugins/platforms/qwayland-egl/qwaylandeglwindow.cpp b/src/plugins/platforms/qwayland-egl/qwaylandeglwindow.cpp new file mode 100644 index 000000000..caed3dfe0 --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandeglwindow.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** 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 "qwaylandeglwindow.h" + +#include "qwaylandscreen.h" +#include "qwaylandglcontext.h" +#include "qwaylandegldecoration.h" + +#include <QtPlatformSupport/private/qeglconvenience_p.h> + +#include <QDebug> +#include <QtGui/QWindow> +#include <qpa/qwindowsysteminterface.h> +#include <QOpenGLFramebufferObject> +#include <QOpenGLContext> + +#ifdef QT_WAYLAND_WINDOWMANAGER_SUPPORT +#include "windowmanager_integration/qwaylandwindowmanagerintegration.h" +#endif + +QWaylandEglWindow::QWaylandEglWindow(QWindow *window) + : QWaylandWindow(window) + , m_eglIntegration(static_cast<QWaylandEglIntegration *>(mDisplay->eglIntegration())) + , m_waylandEglWindow(0) + , m_eglSurface(0) + , m_eglConfig(0) + , m_contentFBO(0) + , m_resize(false) + , m_format(window->format()) +{ + setGeometry(window->geometry()); +} + +QWaylandEglWindow::~QWaylandEglWindow() +{ + if (m_eglSurface) { + eglDestroySurface(m_eglIntegration->eglDisplay(), m_eglSurface); + m_eglSurface = 0; + } + + wl_egl_window_destroy(m_waylandEglWindow); + + delete m_contentFBO; +} + +QWaylandWindow::WindowType QWaylandEglWindow::windowType() const +{ + return QWaylandWindow::Egl; +} + +void QWaylandEglWindow::redraw() +{ + createDecoration(); + QMargins margins = frameMargins(); + QSize sizeWithMargins = geometry().size() + QSize(margins.left() + margins.right(), margins.top() + margins.bottom()); + + if (m_waylandEglWindow) { + int current_width, current_height; + wl_egl_window_get_attached_size(m_waylandEglWindow,¤t_width,¤t_height); + if (current_width != sizeWithMargins.width() || current_height != sizeWithMargins.height()) { + waitForFrameSync(); + wl_egl_window_resize(m_waylandEglWindow, sizeWithMargins.width(), sizeWithMargins.height(), mOffset.x(), mOffset.y()); + mOffset = QPoint(); + + m_resize = true; + } + } else { + m_waylandEglWindow = wl_egl_window_create(mSurface, sizeWithMargins.width(), sizeWithMargins.height()); + } +} + +QRect QWaylandEglWindow::contentsRect() const +{ + QRect r = geometry(); + QMargins m = frameMargins(); + return QRect(m.left(), m.bottom(), r.width(), r.height()); +} + +QSurfaceFormat QWaylandEglWindow::format() const +{ + return m_format; +} + +EGLSurface QWaylandEglWindow::eglSurface() const +{ + if (!m_waylandEglWindow) { + const_cast<QWaylandEglWindow *>(this)->createDecoration(); + QMargins margins = frameMargins(); + QSize sizeWithMargins = geometry().size() + QSize(margins.left() + margins.right(), margins.top() + margins.bottom()); + m_waylandEglWindow = wl_egl_window_create(mSurface, sizeWithMargins.width(), sizeWithMargins.height()); + } + + if (!m_eglSurface) { + m_eglConfig = q_configFromGLFormat(m_eglIntegration->eglDisplay(), window()->format(), true); + const_cast<QWaylandEglWindow *>(this)->m_format = q_glFormatFromConfig(m_eglIntegration->eglDisplay(),m_eglConfig); + + EGLNativeWindowType window = (EGLNativeWindowType) m_waylandEglWindow; + m_eglSurface = eglCreateWindowSurface(m_eglIntegration->eglDisplay(), m_eglConfig, window, 0); + } + + return m_eglSurface; +} + +GLuint QWaylandEglWindow::contentFBO() const +{ + if (!decoration()) + return 0; + + if (m_resize || !m_contentFBO) { + QOpenGLFramebufferObject *old = m_contentFBO; + m_contentFBO = new QOpenGLFramebufferObject(geometry().width(), geometry().height(), QOpenGLFramebufferObject::CombinedDepthStencil); + + delete old; + m_resize = false; + } + + return m_contentFBO->handle(); +} + +GLuint QWaylandEglWindow::contentTexture() const +{ + return m_contentFBO->texture(); +} + +void QWaylandEglWindow::bindContentFBO() +{ + if (decoration()) { + contentFBO(); + m_contentFBO->bind(); + } +} + +void QWaylandEglWindow::createDecorationInstance() +{ + new QWaylandEglDecoration(this); +} diff --git a/src/plugins/platforms/qwayland-egl/qwaylandeglwindow.h b/src/plugins/platforms/qwayland-egl/qwaylandeglwindow.h new file mode 100644 index 000000000..4a7b3054a --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandeglwindow.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 QWAYLANDEGLWINDOW_H +#define QWAYLANDEGLWINDOW_H + +#include "qwaylandwindow.h" +#include "qwaylandeglinclude.h" +#include "qwaylandeglintegration.h" + +class QWaylandGLContext; +class QOpenGLFramebufferObject; + +class QWaylandEglWindow : public QWaylandWindow +{ +public: + QWaylandEglWindow(QWindow *window); + ~QWaylandEglWindow(); + WindowType windowType() const; + + QRect contentsRect() const; + + EGLSurface eglSurface() const; + GLuint contentFBO() const; + GLuint contentTexture() const; + + QSurfaceFormat format() const; + + void bindContentFBO(); + + void redraw(); + +protected: + void createDecorationInstance(); + +private: + QWaylandEglIntegration *m_eglIntegration; + mutable struct wl_egl_window *m_waylandEglWindow; + + const QWaylandWindow *m_parentWindow; + + mutable EGLSurface m_eglSurface; + mutable EGLConfig m_eglConfig; + mutable QOpenGLFramebufferObject *m_contentFBO; + mutable bool m_resize; + + QSurfaceFormat m_format; +}; + +#endif // QWAYLANDEGLWINDOW_H diff --git a/src/plugins/platforms/qwayland-egl/qwaylandglcontext.cpp b/src/plugins/platforms/qwayland-egl/qwaylandglcontext.cpp new file mode 100644 index 000000000..f9ad280f7 --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandglcontext.cpp @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** 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 "qwaylandglcontext.h" + +#include "qwaylanddisplay.h" +#include "qwaylandwindow.h" +#include "qwaylandeglwindow.h" +#include "qwaylanddecoration.h" + +#include <QDebug> +#include <QtPlatformSupport/private/qeglconvenience_p.h> +#include <QtGui/private/qopenglcontext_p.h> + +#include <qpa/qplatformopenglcontext.h> +#include <QtGui/QSurfaceFormat> +#include <QtGui/QOpenGLShaderProgram> + +QWaylandGLContext::QWaylandGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformOpenGLContext *share) + : QPlatformOpenGLContext() + , m_eglDisplay(eglDisplay) + , m_config(q_configFromGLFormat(m_eglDisplay, format, true)) + , m_format(q_glFormatFromConfig(m_eglDisplay, m_config)) + , m_blitProgram(0) +{ + m_shareEGLContext = share ? static_cast<QWaylandGLContext *>(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, m_shareEGLContext, eglContextAttrs.constData()); + + if (m_context == EGL_NO_CONTEXT) { + m_context = eglCreateContext(m_eglDisplay, m_config, EGL_NO_CONTEXT, eglContextAttrs.constData()); + m_shareEGLContext = EGL_NO_CONTEXT; + } +} + +QWaylandGLContext::~QWaylandGLContext() +{ + delete m_blitProgram; + eglDestroyContext(m_eglDisplay, m_context); +} + +bool QWaylandGLContext::makeCurrent(QPlatformSurface *surface) +{ + QWaylandEglWindow *window = static_cast<QWaylandEglWindow *>(surface); + EGLSurface eglSurface = window->eglSurface(); + if (!eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_context)) + return false; + + // FIXME: remove this as soon as https://codereview.qt-project.org/#change,38879 is merged + QOpenGLContextPrivate::setCurrentContext(context()); + + window->bindContentFBO(); + + return true; +} + +void QWaylandGLContext::doneCurrent() +{ + eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); +} + +void QWaylandGLContext::swapBuffers(QPlatformSurface *surface) +{ + QWaylandEglWindow *window = static_cast<QWaylandEglWindow *>(surface); + EGLSurface eglSurface = window->eglSurface(); + + if (window->decoration()) { + makeCurrent(surface); + + if (!m_blitProgram) { + m_blitProgram = new QOpenGLShaderProgram(); + m_blitProgram->addShaderFromSourceCode(QOpenGLShader::Vertex, "attribute vec4 position;\n\ + attribute vec4 texCoords;\n\ + varying vec2 outTexCoords;\n\ + void main()\n\ + {\n\ + gl_Position = position;\n\ + outTexCoords = texCoords.xy;\n\ + }"); + m_blitProgram->addShaderFromSourceCode(QOpenGLShader::Fragment, "varying vec2 outTexCoords;\n\ + uniform sampler2D texture;\n\ + void main()\n\ + {\n\ + gl_FragColor = texture2D(texture, outTexCoords);\n\ + }"); + + if (!m_blitProgram->link()) { + qDebug() << "Shader Program link failed."; + qDebug() << m_blitProgram->log(); + } + } + + glDisable(GL_DEPTH_TEST); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + if (window->decoration()) + window->decoration()->paintDecoration(); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, window->contentTexture()); + QRect r = window->contentsRect(); + glViewport(r.x(), r.y(), r.width(), r.height()); + + static const GLfloat squareVertices[] = { + -1.f, -1.f, + 1.0f, -1.f, + -1.f, 1.0f, + 1.0f, 1.0f, + }; + static const GLfloat textureVertices[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + }; + + m_blitProgram->bind(); + + m_blitProgram->setUniformValue("texture", 0); + + m_blitProgram->enableAttributeArray("position"); + m_blitProgram->enableAttributeArray("texCoords"); + m_blitProgram->setAttributeArray("position", squareVertices, 2); + m_blitProgram->setAttributeArray("texCoords", textureVertices, 2); + + m_blitProgram->bind(); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + m_blitProgram->disableAttributeArray("position"); + m_blitProgram->disableAttributeArray("texCoords"); + m_blitProgram->release(); + } + + eglSwapBuffers(m_eglDisplay, eglSurface); +} + +GLuint QWaylandGLContext::defaultFramebufferObject(QPlatformSurface *surface) const +{ + return static_cast<QWaylandEglWindow *>(surface)->contentFBO(); +} + +bool QWaylandGLContext::isSharing() const +{ + return m_shareEGLContext != EGL_NO_CONTEXT; +} + +bool QWaylandGLContext::isValid() const +{ + return m_context != EGL_NO_CONTEXT; +} + +void (*QWaylandGLContext::getProcAddress(const QByteArray &procName)) () +{ + return eglGetProcAddress(procName.constData()); +} + +EGLConfig QWaylandGLContext::eglConfig() const +{ + return m_config; +} + diff --git a/src/plugins/platforms/qwayland-egl/qwaylandglcontext.h b/src/plugins/platforms/qwayland-egl/qwaylandglcontext.h new file mode 100644 index 000000000..767f188fb --- /dev/null +++ b/src/plugins/platforms/qwayland-egl/qwaylandglcontext.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 QWAYLANDGLCONTEXT_H +#define QWAYLANDGLCONTEXT_H + +#include "qwaylanddisplay.h" + +#include <qpa/qplatformopenglcontext.h> + +#include "qwaylandeglinclude.h" + +class QWaylandWindow; +class QWaylandGLWindowSurface; +class QOpenGLShaderProgram; + +class QWaylandGLContext : public QPlatformOpenGLContext { +public: + QWaylandGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformOpenGLContext *share); + ~QWaylandGLContext(); + + void swapBuffers(QPlatformSurface *surface); + + bool makeCurrent(QPlatformSurface *surface); + void doneCurrent(); + + GLuint defaultFramebufferObject(QPlatformSurface *surface) const; + + bool isSharing() const; + bool isValid() const; + + 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; + EGLContext m_shareEGLContext; + EGLConfig m_config; + QSurfaceFormat m_format; + QOpenGLShaderProgram *m_blitProgram; +}; + + +#endif // QWAYLANDGLCONTEXT_H |