summaryrefslogtreecommitdiffstats
path: root/src/hardwareintegration/client/wayland-egl
diff options
context:
space:
mode:
Diffstat (limited to 'src/hardwareintegration/client/wayland-egl')
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp124
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h77
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h60
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h54
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp171
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.h88
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp261
-rw-r--r--src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h96
-rw-r--r--src/hardwareintegration/client/wayland-egl/wayland-egl.pri16
9 files changed, 947 insertions, 0 deletions
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp
new file mode 100644
index 000000000..68d38c498
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** 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 "qwaylandeglclientbufferintegration.h"
+
+#include "qwaylandeglwindow.h"
+#include "qwaylandglcontext.h"
+
+#include <wayland-client.h>
+
+#include <QtCore/QDebug>
+
+QT_BEGIN_NAMESPACE
+
+static const char *qwaylandegl_threadedgl_blacklist_vendor[] = {
+ "Mesa Project",
+ 0
+};
+
+QWaylandEglClientBufferIntegration::QWaylandEglClientBufferIntegration()
+ : m_waylandDisplay(0)
+ , m_supportsThreading(false)
+{
+ qDebug() << "Using Wayland-EGL";
+}
+
+
+QWaylandEglClientBufferIntegration::~QWaylandEglClientBufferIntegration()
+{
+ eglTerminate(m_eglDisplay);
+}
+
+void QWaylandEglClientBufferIntegration::initialize(QWaylandDisplay *display)
+{
+ QByteArray eglPlatform = qgetenv("EGL_PLATFORM");
+ if (eglPlatform.isEmpty()) {
+ setenv("EGL_PLATFORM","wayland",true);
+ }
+
+ m_waylandDisplay = display->wl_display();
+
+ 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;
+ }
+ }
+
+ m_supportsThreading = true;
+ if (qEnvironmentVariableIsSet("QT_OPENGL_NO_SANITY_CHECK"))
+ return;
+
+ const char *vendor = eglQueryString(m_eglDisplay, EGL_VENDOR);
+ for (int i = 0; qwaylandegl_threadedgl_blacklist_vendor[i]; ++i) {
+ if (strstr(vendor, qwaylandegl_threadedgl_blacklist_vendor[i]) != 0) {
+ m_supportsThreading = false;
+ break;
+ }
+ }
+}
+
+bool QWaylandEglClientBufferIntegration::supportsThreadedOpenGL() const
+{
+ return m_supportsThreading;
+}
+
+QWaylandWindow *QWaylandEglClientBufferIntegration::createEglWindow(QWindow *window)
+{
+ return new QWaylandEglWindow(window);
+}
+
+QPlatformOpenGLContext *QWaylandEglClientBufferIntegration::createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const
+{
+ return new QWaylandGLContext(m_eglDisplay, glFormat, share);
+}
+
+EGLDisplay QWaylandEglClientBufferIntegration::eglDisplay() const
+{
+ return m_eglDisplay;
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h
new file mode 100644
index 000000000..0c7d76cb9
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglclientbufferintegration.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** 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 <QtWaylandClient/private/qwaylandclientbufferintegration_p.h>
+
+#include "qwaylandeglinclude.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWaylandWindow;
+class QWindow;
+
+class QWaylandEglClientBufferIntegration : public QWaylandClientBufferIntegration
+{
+public:
+ QWaylandEglClientBufferIntegration();
+ ~QWaylandEglClientBufferIntegration();
+
+ void initialize(QWaylandDisplay *display) Q_DECL_OVERRIDE;
+ bool supportsThreadedOpenGL() const Q_DECL_OVERRIDE;
+
+ QWaylandWindow *createEglWindow(QWindow *window) Q_DECL_OVERRIDE;
+ QPlatformOpenGLContext *createPlatformOpenGLContext(const QSurfaceFormat &glFormat, QPlatformOpenGLContext *share) const Q_DECL_OVERRIDE;
+
+ EGLDisplay eglDisplay() const;
+
+private:
+ struct wl_display *m_waylandDisplay;
+
+ EGLDisplay m_eglDisplay;
+ bool m_supportsThreading;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWAYLANDEGLINTEGRATION_H
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h b/src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h
new file mode 100644
index 000000000..4eadacca2
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandegldisplay.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** 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 <QtWaylandClient/qwaylanddisplay.h>
+
+#include "qwaylandeglintegration.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWaylandEglDisplay : public QWaylandDisplay
+{
+public:
+
+ QWaylandEglDisplay()
+ : QWaylandDisplay()
+ { }
+};
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h
new file mode 100644
index 000000000..9b151a5e8
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglinclude.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** 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 EGL_EGLEXT_PROTOTYPES
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#endif // QWAYLANDEGLINCLUDE_H
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp
new file mode 100644
index 000000000..1e86bd313
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp
@@ -0,0 +1,171 @@
+/****************************************************************************
+**
+** 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 <QtWaylandClient/private/qwaylandscreen_p.h>
+#include "qwaylandglcontext.h"
+
+#include <QtPlatformSupport/private/qeglconvenience_p.h>
+
+#include <QDebug>
+#include <QtGui/QWindow>
+#include <qpa/qwindowsysteminterface.h>
+#include <QOpenGLFramebufferObject>
+#include <QOpenGLContext>
+
+QT_BEGIN_NAMESPACE
+
+QWaylandEglWindow::QWaylandEglWindow(QWindow *window)
+ : QWaylandWindow(window)
+ , m_clientBufferIntegration(static_cast<QWaylandEglClientBufferIntegration *>(mDisplay->clientBufferIntegration()))
+ , m_waylandEglWindow(0)
+ , m_eglSurface(0)
+ , m_eglConfig(0)
+ , m_contentFBO(0)
+ , m_resize(false)
+ , m_format(window->requestedFormat())
+{
+ setGeometry(window->geometry());
+}
+
+QWaylandEglWindow::~QWaylandEglWindow()
+{
+ if (m_eglSurface) {
+ eglDestroySurface(m_clientBufferIntegration->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::setGeometry(const QRect &rect)
+{
+ QWaylandWindow::setGeometry(rect);
+
+ 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,&current_width,&current_height);
+ if (current_width != sizeWithMargins.width() || current_height != sizeWithMargins.height()) {
+ 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(object(), 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) {
+ QWaylandEglWindow *self = const_cast<QWaylandEglWindow *>(this);
+ self->createDecoration();
+ QMargins margins = frameMargins();
+ QSize sizeWithMargins = geometry().size() + QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
+ m_waylandEglWindow = wl_egl_window_create(self->object(), sizeWithMargins.width(), sizeWithMargins.height());
+ }
+
+ if (!m_eglSurface) {
+ m_eglConfig = q_configFromGLFormat(m_clientBufferIntegration->eglDisplay(), window()->format(), true);
+ const_cast<QWaylandEglWindow *>(this)->m_format = q_glFormatFromConfig(m_clientBufferIntegration->eglDisplay(),m_eglConfig);
+
+ EGLNativeWindowType window = (EGLNativeWindowType) m_waylandEglWindow;
+ m_eglSurface = eglCreateWindowSurface(m_clientBufferIntegration->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();
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.h b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.h
new file mode 100644
index 000000000..9f08559d1
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-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 <QtWaylandClient/private/qwaylandwindow_p.h>
+#include "qwaylandeglinclude.h"
+#include "qwaylandeglclientbufferintegration.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWaylandGLContext;
+class QOpenGLFramebufferObject;
+
+class QWaylandEglWindow : public QWaylandWindow
+{
+public:
+ QWaylandEglWindow(QWindow *window);
+ ~QWaylandEglWindow();
+ WindowType windowType() const;
+
+ virtual void setGeometry(const QRect &rect);
+ QRect contentsRect() const;
+
+ EGLSurface eglSurface() const;
+ GLuint contentFBO() const;
+ GLuint contentTexture() const;
+
+ QSurfaceFormat format() const;
+
+ void bindContentFBO();
+
+private:
+ QWaylandEglClientBufferIntegration *m_clientBufferIntegration;
+ 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;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWAYLANDEGLWINDOW_H
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
new file mode 100644
index 000000000..3bc1ff2b1
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** 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 <QtWaylandClient/private/qwaylanddisplay_p.h>
+#include <QtWaylandClient/private/qwaylandwindow_p.h>
+#include <QtWaylandClient/private/qwaylanddecoration_p.h>
+#include "qwaylandeglwindow.h"
+
+#include <QDebug>
+#include <QtPlatformSupport/private/qeglconvenience_p.h>
+#include <QtGui/private/qopenglcontext_p.h>
+#include <QtGui/private/qopengltexturecache_p.h>
+
+#include <qpa/qplatformopenglcontext.h>
+#include <QtGui/QSurfaceFormat>
+#include <QtGui/QOpenGLShaderProgram>
+
+QT_BEGIN_NAMESPACE
+
+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_textureCache(0)
+ , mUseNativeDefaultFbo(false)
+{
+ m_shareEGLContext = share ? static_cast<QWaylandGLContext *>(share)->eglContext() : EGL_NO_CONTEXT;
+
+ switch (m_format.renderableType()) {
+ case QSurfaceFormat::OpenVG:
+ eglBindAPI(EGL_OPENVG_API);
+ break;
+#ifdef EGL_VERSION_1_4
+# if !defined(QT_OPENGL_ES_2)
+ case QSurfaceFormat::DefaultRenderableType:
+# endif
+ case QSurfaceFormat::OpenGL:
+ eglBindAPI(EGL_OPENGL_API);
+ break;
+#endif
+ case QSurfaceFormat::OpenGLES:
+ default:
+ eglBindAPI(EGL_OPENGL_ES_API);
+ break;
+ }
+
+ 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;
+ delete m_textureCache;
+ eglDestroyContext(m_eglDisplay, m_context);
+}
+
+bool QWaylandGLContext::makeCurrent(QPlatformSurface *surface)
+{
+ QWaylandEglWindow *window = static_cast<QWaylandEglWindow *>(surface);
+
+ window->setCanResize(false);
+
+ EGLSurface eglSurface = window->eglSurface();
+ if (!eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_context)) {
+ qWarning("QEGLPlatformContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this);
+ return false;
+ }
+
+ 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) {
+ initializeOpenGLFunctions();
+ 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 highp 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();
+ }
+ }
+
+ if (!m_textureCache) {
+ m_textureCache = new QOpenGLTextureCache(this->context());
+ }
+
+ QRect windowRect = window->window()->frameGeometry();
+ glViewport(0, 0, windowRect.width(), windowRect.height());
+
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_BLEND);
+ mUseNativeDefaultFbo = true;
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ mUseNativeDefaultFbo = false;
+
+ static const GLfloat squareVertices[] = {
+ -1.f, -1.f,
+ 1.0f, -1.f,
+ -1.f, 1.0f,
+ 1.0f, 1.0f
+ };
+
+ static const GLfloat inverseSquareVertices[] = {
+ -1.f, 1.f,
+ 1.f, 1.f,
+ -1.f, -1.f,
+ 1.f, -1.f
+ };
+
+ 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("texCoords", textureVertices, 2);
+
+ glActiveTexture(GL_TEXTURE0);
+
+ //Draw Decoration
+ m_blitProgram->setAttributeArray("position", inverseSquareVertices, 2);
+ QImage decorationImage = window->decoration()->contentImage();
+ m_textureCache->bindTexture(context(), decorationImage);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ //Draw Content
+ m_blitProgram->setAttributeArray("position", squareVertices, 2);
+ glBindTexture(GL_TEXTURE_2D, window->contentTexture());
+ QRect r = window->contentsRect();
+ glViewport(r.x(), r.y(), r.width(), r.height());
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ //Cleanup
+ m_blitProgram->disableAttributeArray("position");
+ m_blitProgram->disableAttributeArray("texCoords");
+ m_blitProgram->release();
+ }
+
+ eglSwapBuffers(m_eglDisplay, eglSurface);
+
+ window->setCanResize(true);
+}
+
+GLuint QWaylandGLContext::defaultFramebufferObject(QPlatformSurface *surface) const
+{
+ if (mUseNativeDefaultFbo)
+ return 0;
+
+ 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;
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h
new file mode 100644
index 000000000..38548ac81
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/qwaylandglcontext.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** 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 <QtWaylandClient/private/qwaylanddisplay_p.h>
+
+#include <qpa/qplatformopenglcontext.h>
+#include <QtGui/QOpenGLFunctions>
+
+#include "qwaylandeglinclude.h"
+
+QT_BEGIN_NAMESPACE
+
+class QWaylandWindow;
+class QWaylandGLWindowSurface;
+class QOpenGLShaderProgram;
+class QOpenGLTextureCache;
+
+class QWaylandGLContext : public QPlatformOpenGLContext, protected QOpenGLFunctions
+{
+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;
+ QOpenGLTextureCache *m_textureCache;
+ bool mUseNativeDefaultFbo;
+};
+
+QT_END_NAMESPACE
+
+#endif // QWAYLANDGLCONTEXT_H
diff --git a/src/hardwareintegration/client/wayland-egl/wayland-egl.pri b/src/hardwareintegration/client/wayland-egl/wayland-egl.pri
new file mode 100644
index 000000000..bf03a8c72
--- /dev/null
+++ b/src/hardwareintegration/client/wayland-egl/wayland-egl.pri
@@ -0,0 +1,16 @@
+INCLUDEPATH += $$PWD
+!contains(QT_CONFIG, no-pkg-config) {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += wayland-egl egl
+} else {
+ LIBS += -lwayland-egl -lEGL
+}
+
+SOURCES += $$PWD/qwaylandeglclientbufferintegration.cpp \
+ $$PWD/qwaylandglcontext.cpp \
+ $$PWD/qwaylandeglwindow.cpp
+
+HEADERS += $$PWD/qwaylandeglclientbufferintegration.h \
+ $$PWD/qwaylandglcontext.h \
+ $$PWD/qwaylandeglwindow.h \
+ $$PWD/qwaylandeglinclude.h