summaryrefslogtreecommitdiffstats
path: root/src/hardwareintegration/compositor
diff options
context:
space:
mode:
Diffstat (limited to 'src/hardwareintegration/compositor')
-rw-r--r--src/hardwareintegration/compositor/brcm-egl/brcm-egl.pri19
-rw-r--r--src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp75
-rw-r--r--src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h81
-rw-r--r--src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp177
-rw-r--r--src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h78
-rw-r--r--src/hardwareintegration/compositor/drm-egl-server/drm-egl-server.pri18
-rw-r--r--src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp193
-rw-r--r--src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h172
-rw-r--r--src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri14
-rw-r--r--src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp258
-rw-r--r--src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.h77
-rw-r--r--src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri16
-rw-r--r--src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp144
-rw-r--r--src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h72
-rw-r--r--src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri16
-rw-r--r--src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp156
-rw-r--r--src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.h80
-rw-r--r--src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri15
-rw-r--r--src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp69
-rw-r--r--src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h85
-rw-r--r--src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp78
-rw-r--r--src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h71
-rw-r--r--src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h78
23 files changed, 2042 insertions, 0 deletions
diff --git a/src/hardwareintegration/compositor/brcm-egl/brcm-egl.pri b/src/hardwareintegration/compositor/brcm-egl/brcm-egl.pri
new file mode 100644
index 000000000..c04b4abc9
--- /dev/null
+++ b/src/hardwareintegration/compositor/brcm-egl/brcm-egl.pri
@@ -0,0 +1,19 @@
+PLUGIN_TYPE = waylandcompositors
+load(qt_plugin)
+
+QT = compositor compositor-private core-private gui-private
+
+INCLUDEPATH = $$PWD
+LIBS += -lwayland-server -lEGL
+
+SOURCES += \
+ brcmeglintegration.cpp \
+ brcmbuffer.cpp
+
+
+HEADERS += \
+ brcmeglintegration.h \
+ brcmbuffer.h
+
+CONFIG += wayland-scanner
+WAYLANDSERVERSOURCES += $$PWD/../../../extensions/brcm.xml
diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp
new file mode 100644
index 000000000..e4fbfb553
--- /dev/null
+++ b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "brcmbuffer.h"
+
+#include <EGL/eglext.h>
+
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/eglext_brcm.h>
+
+QT_BEGIN_NAMESPACE
+
+BrcmBuffer::BrcmBuffer(struct ::wl_client *client, uint32_t id, const QSize &size, EGLint *data, size_t count)
+ : QtWaylandServer::wl_buffer(client, id)
+ , m_handle(count)
+ , m_invertedY(false)
+ , m_size(size)
+{
+ for (size_t i = 0; i < count; ++i)
+ m_handle[i] = data[i];
+}
+
+BrcmBuffer::~BrcmBuffer()
+{
+ eglDestroyGlobalImageBRCM(handle());
+}
+
+void BrcmBuffer::buffer_destroy_resource(Resource *)
+{
+ delete this;
+}
+
+void BrcmBuffer::buffer_destroy(Resource *resource)
+{
+ wl_resource_destroy(resource->handle);
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h
new file mode 100644
index 000000000..6ec5868f9
--- /dev/null
+++ b/src/hardwareintegration/compositor/brcm-egl/brcmbuffer.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BRCMBUFFER_H
+#define BRCMBUFFER_H
+
+#include <QtCompositor/private/qwlcompositor_p.h>
+#include <qwayland-server-wayland.h>
+
+#include <QtCore/QSize>
+#include <QtCore/QVector>
+
+#include <EGL/egl.h>
+
+QT_BEGIN_NAMESPACE
+
+class BrcmBuffer : public QtWaylandServer::wl_buffer
+{
+public:
+ BrcmBuffer(struct ::wl_client *client, uint32_t id, const QSize &size, EGLint *data, size_t count);
+ ~BrcmBuffer();
+
+ bool isYInverted() const { return m_invertedY; }
+ void setInvertedY(bool inverted) { m_invertedY = inverted; }
+
+ EGLint *handle() { return m_handle.data(); }
+
+ QSize size() { return m_size; }
+
+ static BrcmBuffer *fromResource(struct ::wl_resource *resource) { return static_cast<BrcmBuffer*>(Resource::fromResource(resource)->buffer); }
+
+protected:
+ void buffer_destroy_resource(Resource *resource) Q_DECL_OVERRIDE;
+ void buffer_destroy(Resource *resource) Q_DECL_OVERRIDE;
+
+private:
+ QVector<EGLint> m_handle;
+ bool m_invertedY;
+ QSize m_size;
+};
+
+QT_END_NAMESPACE
+
+#endif // BRCMBUFFER_H
diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp
new file mode 100644
index 000000000..a0be625dd
--- /dev/null
+++ b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.cpp
@@ -0,0 +1,177 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "brcmeglintegration.h"
+#include "brcmbuffer.h"
+#include <QtCompositor/private/qwlsurface_p.h>
+#include <QtCompositor/private/qwlcompositor_p.h>
+#include <QtCompositor/qwaylandsurface.h>
+#include <qpa/qplatformnativeinterface.h>
+#include <QtGui/QGuiApplication>
+#include <QtGui/QOpenGLContext>
+#include <qpa/qplatformscreen.h>
+#include <QtGui/QWindow>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#define EGL_EGLEXT_PROTOTYPES
+#include <EGL/eglext_brcm.h>
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+QT_BEGIN_NAMESPACE
+
+class BrcmEglIntegrationPrivate
+{
+public:
+ BrcmEglIntegrationPrivate()
+ : egl_display(EGL_NO_DISPLAY)
+ , valid(false)
+ { }
+ EGLDisplay egl_display;
+ bool valid;
+ PFNEGLQUERYGLOBALIMAGEBRCMPROC eglQueryGlobalImageBRCM;
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
+ PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
+ PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
+};
+
+BrcmEglIntegration::BrcmEglIntegration()
+ : QWaylandClientBufferIntegration()
+ , QtWaylandServer::qt_brcm()
+ , d_ptr(new BrcmEglIntegrationPrivate)
+{
+}
+
+void BrcmEglIntegration::initializeHardware(QtWayland::Display *waylandDisplay)
+{
+ Q_D(BrcmEglIntegration);
+
+ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+ if (nativeInterface) {
+ d->egl_display = nativeInterface->nativeResourceForIntegration("EglDisplay");
+ if (!d->egl_display)
+ qWarning("Failed to acquire EGL display from platform integration");
+
+ d->eglQueryGlobalImageBRCM = eglQueryGlobalImageBRCM;
+
+ if (!d->eglQueryGlobalImageBRCM) {
+ qWarning("Failed to resolve eglQueryGlobalImageBRCM");
+ return;
+ }
+
+ d->glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
+
+ if (!d->glEGLImageTargetTexture2DOES) {
+ qWarning("Failed to resolve glEGLImageTargetTexture2DOES");
+ return;
+ }
+
+ d->eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
+
+ if (!d->eglCreateImageKHR) {
+ qWarning("Failed to resolve eglCreateImageKHR");
+ return;
+ }
+
+ d->eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR");
+
+ if (!d->eglDestroyImageKHR) {
+ qWarning("Failed to resolve eglDestroyImageKHR");
+ return;
+ }
+ d->valid = true;
+ init(waylandDisplay->handle());
+ }
+}
+
+void BrcmEglIntegration::bindTextureToBuffer(struct ::wl_resource *buffer)
+{
+ Q_D(BrcmEglIntegration);
+ if (!d->valid) {
+ qWarning("bindTextureToBuffer failed!");
+ return;
+ }
+
+ BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(buffer);
+
+ if (!d->eglQueryGlobalImageBRCM(brcmBuffer->handle(), brcmBuffer->handle() + 2)) {
+ qWarning("eglQueryGlobalImageBRCM failed!");
+ return;
+ }
+
+ EGLImageKHR image = d->eglCreateImageKHR(d->egl_display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLClientBuffer)brcmBuffer->handle(), NULL);
+ if (image == EGL_NO_IMAGE_KHR)
+ qWarning("eglCreateImageKHR() failed: %x\n", eglGetError());
+
+ d->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ d->eglDestroyImageKHR(d->egl_display, image);
+}
+
+bool BrcmEglIntegration::isYInverted(struct ::wl_resource *) const
+{
+ return false;
+}
+
+void BrcmEglIntegration::brcm_bind_resource(Resource *)
+{
+}
+
+void BrcmEglIntegration::brcm_create_buffer(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data)
+{
+ new BrcmBuffer(resource->client(), id, QSize(width, height), static_cast<EGLint *>(data->data), data->size / sizeof(EGLint));
+}
+
+QSize BrcmEglIntegration::bufferSize(struct ::wl_resource *buffer) const
+{
+ BrcmBuffer *brcmBuffer = BrcmBuffer::fromResource(buffer);
+
+ return brcmBuffer->size();
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h
new file mode 100644
index 000000000..f6486ed4b
--- /dev/null
+++ b/src/hardwareintegration/compositor/brcm-egl/brcmeglintegration.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BRCMEGLINTEGRATION_H
+#define BRCMEGLINTEGRATION_H
+
+#include <QtCompositor/qwaylandclientbufferintegration.h>
+#include "qwayland-server-brcm.h"
+
+#include <QtCore/QScopedPointer>
+
+QT_BEGIN_NAMESPACE
+
+class BrcmEglIntegrationPrivate;
+
+class BrcmEglIntegration : public QWaylandClientBufferIntegration, public QtWaylandServer::qt_brcm
+{
+ Q_DECLARE_PRIVATE(BrcmEglIntegration)
+public:
+ BrcmEglIntegration();
+
+ void initializeHardware(QtWayland::Display *waylandDisplay) Q_DECL_OVERRIDE;
+
+ void udpateTextureFromBuffer(struct ::wl_resource *buffer) Q_DECL_OVERRIDE;
+ bool isYInverted(struct ::wl_resource *) const Q_DECL_OVERRIDE;
+
+ QSize bufferSize(struct ::wl_resource *buffer) const Q_DECL_OVERRIDE;
+
+protected:
+ void brcm_bind_resource(Resource *resource) Q_DECL_OVERRIDE;
+ void brcm_create_buffer(Resource *resource, uint32_t id, int32_t width, int32_t height, wl_array *data) Q_DECL_OVERRIDE;
+
+private:
+ Q_DISABLE_COPY(BrcmEglIntegration)
+ QScopedPointer<BrcmEglIntegrationPrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // BRCMEGLINTEGRATION_H
+
diff --git a/src/hardwareintegration/compositor/drm-egl-server/drm-egl-server.pri b/src/hardwareintegration/compositor/drm-egl-server/drm-egl-server.pri
new file mode 100644
index 000000000..cd2e24719
--- /dev/null
+++ b/src/hardwareintegration/compositor/drm-egl-server/drm-egl-server.pri
@@ -0,0 +1,18 @@
+INCLUDEPATH += $$PWD
+
+contains(QT_CONFIG, no-pkg-config) {
+ LIBS += -lwayland-server -lEGL
+} else {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += wayland-server egl
+}
+
+SOURCES += \
+ $$PWD/drmeglserverbufferintegration.cpp
+
+
+HEADERS += \
+ $$PWD/drmeglserverbufferintegration.h
+
+CONFIG += wayland-scanner
+WAYLANDSERVERSOURCES += $$PWD/../../../extensions/drm-egl-server-buffer.xml
diff --git a/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp
new file mode 100644
index 000000000..9c7440dc6
--- /dev/null
+++ b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "drmeglserverbufferintegration.h"
+
+#include <QtGui/QOpenGLContext>
+
+QT_BEGIN_NAMESPACE
+
+DrmEglServerBuffer::DrmEglServerBuffer(DrmEglServerBufferIntegration *integration, const QSize &size, QWaylandServerBuffer::Format format)
+ : QWaylandServerBuffer(size,format)
+ , m_integration(integration)
+{
+ m_format = format;
+
+ EGLint egl_format;
+ switch (m_format) {
+ case RGBA32:
+ m_drm_format = QtWaylandServer::qt_drm_egl_server_buffer::format_RGBA32;
+ egl_format = EGL_DRM_BUFFER_FORMAT_ARGB32_MESA;
+ break;
+#ifdef EGL_DRM_BUFFER_FORMAT_A8_MESA
+ case A8:
+ m_drm_format = QtWaylandServer::qt_drm_egl_server_buffer::format_A8;
+ egl_format = EGL_DRM_BUFFER_FORMAT_A8_MESA;
+ break;
+#endif
+ default:
+ qWarning("DrmEglServerBuffer: unsupported format");
+ m_drm_format = QtWaylandServer::qt_drm_egl_server_buffer::format_RGBA32;
+ egl_format = EGL_DRM_BUFFER_FORMAT_ARGB32_MESA;
+ break;
+ }
+ EGLint imageAttribs[] = {
+ EGL_WIDTH, m_size.width(),
+ EGL_HEIGHT, m_size.height(),
+ EGL_DRM_BUFFER_FORMAT_MESA, egl_format,
+ EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SHARE_MESA,
+ EGL_NONE
+ };
+
+ m_image = m_integration->eglCreateDRMImageMESA(imageAttribs);
+
+ EGLint handle;
+ if (!m_integration->eglExportDRMImageMESA(m_image, &m_name, &handle, &m_stride)) {
+ qWarning("DrmEglServerBuffer: Failed to export egl image");
+ }
+
+}
+
+struct ::wl_resource *DrmEglServerBuffer::resourceForClient(struct ::wl_client *client)
+{
+ QMultiMap<struct ::wl_client *, Resource *>::iterator it = resourceMap().find(client);
+ if (it == resourceMap().end()) {
+ QMultiMap<struct ::wl_client *, QtWaylandServer::qt_drm_egl_server_buffer::Resource *>::iterator drm_egl_it = m_integration->resourceMap().find(client);
+ if (drm_egl_it == m_integration->resourceMap().end()) {
+ qWarning("DrmEglServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the drm_egl interface");
+ return 0;
+ }
+ struct ::wl_resource *drm_egl_resource = (*drm_egl_it)->handle;
+ Resource *resource = add(client);
+ m_integration->send_server_buffer_created(drm_egl_resource, resource->handle, m_name, m_size.width(), m_size.height(), m_stride, m_drm_format);
+ return resource->handle;
+ }
+ return (*it)->handle;
+}
+
+void DrmEglServerBuffer::bindTextureToBuffer()
+{
+ if (!QOpenGLContext::currentContext()) {
+ qWarning("DrmEglServerBuffer: No current context when creating buffer. Texture loading will fail");
+ return;
+ }
+
+ m_integration->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_image);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+}
+
+DrmEglServerBufferIntegration::DrmEglServerBufferIntegration()
+{
+}
+
+DrmEglServerBufferIntegration::~DrmEglServerBufferIntegration()
+{
+}
+
+void DrmEglServerBufferIntegration::initializeHardware(QWaylandCompositor *compositor)
+{
+ QWindow *window = compositor->window();
+ Q_ASSERT(QGuiApplication::platformNativeInterface());
+
+ m_egl_display = static_cast<EGLDisplay>(QGuiApplication::platformNativeInterface()->nativeResourceForWindow("egldisplay", window));
+ if (!m_egl_display) {
+ qWarning("Cant initialize drm egl server buffer integration. Missing egl display from platformplugin");
+ return;
+ }
+
+ const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS);
+ if (!extensionString || !strstr(extensionString, "EGL_KHR_image")) {
+ qWarning("Failed to initialize drm egl server buffer integration. There is no EGL_KHR_image extension.\n");
+ return;
+ }
+ m_egl_create_image = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
+ m_egl_destroy_image = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
+ if (!m_egl_create_image || !m_egl_destroy_image) {
+ qWarning("Failed to initialize drm egl server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR");
+ return;
+ }
+
+ if (!extensionString || !strstr(extensionString, "EGL_MESA_drm_image")) {
+ qWarning("Failed to initialize drm egl server buffer integration. There is no EGL_MESA_drm_image extension.\n");
+ return;
+ }
+
+ m_egl_create_drm_image = reinterpret_cast<PFNEGLCREATEDRMIMAGEMESAPROC>(eglGetProcAddress("eglCreateDRMImageMESA"));
+ m_egl_export_drm_image = reinterpret_cast<PFNEGLEXPORTDRMIMAGEMESAPROC>(eglGetProcAddress("eglExportDRMImageMESA"));
+ if (!m_egl_create_drm_image || !m_egl_export_drm_image) {
+ qWarning("Failed to initialize drm egl server buffer integration. Could not find eglCreateDRMImageMESA or eglExportDRMImageMESA.\n");
+ return;
+ }
+
+ m_gl_egl_image_target_texture_2d = reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(eglGetProcAddress("glEGLImageTargetTexture2DOES"));
+ if (!m_gl_egl_image_target_texture_2d) {
+ qWarning("Failed to initialize drm egl server buffer integration. Could not find glEGLImageTargetTexture2DOES.\n");
+ return;
+ }
+
+ QtWaylandServer::qt_drm_egl_server_buffer::init(compositor->waylandDisplay());
+}
+
+bool DrmEglServerBufferIntegration::supportsFormat(QWaylandServerBuffer::Format format) const
+{
+ switch (format) {
+ case QWaylandServerBuffer::RGBA32:
+ return true;
+ case QWaylandServerBuffer::A8:
+#ifdef EGL_DRM_BUFFER_FORMAT_A8_MESA
+ return true;
+#else
+ return false;
+#endif
+ default:
+ return false;
+ }
+}
+
+QWaylandServerBuffer *DrmEglServerBufferIntegration::createServerBuffer(const QSize &size, QWaylandServerBuffer::Format format)
+{
+ return new DrmEglServerBuffer(this, size, format);
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h
new file mode 100644
index 000000000..659b261e0
--- /dev/null
+++ b/src/hardwareintegration/compositor/drm-egl-server/drmeglserverbufferintegration.h
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DRMEGLSERVERBUFFERINTEGRATION_H
+#define DRMEGLSERVERBUFFERINTEGRATION_H
+
+#include <QtCompositor/qwaylandserverbufferintegration.h>
+
+#include "qwayland-server-drm-egl-server-buffer.h"
+
+#include <QtGui/QWindow>
+#include <QtGui/qpa/qplatformnativeinterface.h>
+#include <QtGui/QGuiApplication>
+
+#include <QtCompositor/qwaylandcompositor.h>
+#include <QtCompositor/private/qwayland-server-server-buffer-extension.h>
+
+#include <QtCore/QDebug>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#ifndef EGL_KHR_image
+typedef void *EGLImageKHR;
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#endif
+
+#ifndef GL_OES_EGL_image
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+#ifndef EGL_MESA_drm_image
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class DrmEglServerBufferIntegration;
+
+class DrmEglServerBuffer : public QWaylandServerBuffer, public QtWaylandServer::qt_server_buffer
+{
+public:
+ DrmEglServerBuffer(DrmEglServerBufferIntegration *integration, const QSize &size, QWaylandServerBuffer::Format format);
+
+ struct ::wl_resource *resourceForClient(struct ::wl_client *) Q_DECL_OVERRIDE;
+ void bindTextureToBuffer() Q_DECL_OVERRIDE;
+
+private:
+ DrmEglServerBufferIntegration *m_integration;
+
+ EGLImageKHR m_image;
+
+ int32_t m_name;
+ int32_t m_stride;
+ QtWaylandServer::qt_drm_egl_server_buffer::format m_drm_format;
+};
+
+class DrmEglServerBufferIntegration :
+ public QWaylandServerBufferIntegration,
+ public QtWaylandServer::qt_drm_egl_server_buffer
+{
+public:
+ DrmEglServerBufferIntegration();
+ ~DrmEglServerBufferIntegration();
+
+ void initializeHardware(QWaylandCompositor *);
+
+ bool supportsFormat(QWaylandServerBuffer::Format format) const Q_DECL_OVERRIDE;
+ QWaylandServerBuffer *createServerBuffer(const QSize &size, QWaylandServerBuffer::Format format) Q_DECL_OVERRIDE;
+
+ EGLDisplay display() const { return m_egl_display; }
+
+ inline EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+ inline EGLBoolean eglDestroyImageKHR (EGLImageKHR image);
+ inline EGLImageKHR eglCreateDRMImageMESA (const EGLint *attrib_list);
+ inline EGLBoolean eglExportDRMImageMESA (EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
+ inline void glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+
+private:
+ EGLDisplay m_egl_display;
+ PFNEGLCREATEDRMIMAGEMESAPROC m_egl_create_drm_image;
+ PFNEGLEXPORTDRMIMAGEMESAPROC m_egl_export_drm_image;
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture_2d;
+
+ PFNEGLCREATEIMAGEKHRPROC m_egl_create_image;
+ PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image;
+};
+
+EGLImageKHR DrmEglServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
+{
+ if (!m_egl_create_image) {
+ qWarning("DrmEglServerBufferIntegration: Trying to used unresolved function eglCreateImageKHR");
+ return EGL_NO_IMAGE_KHR;
+ }
+ return m_egl_create_image(m_egl_display, ctx, target, buffer,attrib_list);
+}
+
+EGLBoolean DrmEglServerBufferIntegration::eglDestroyImageKHR (EGLImageKHR image)
+{
+ if (!m_egl_destroy_image) {
+ qWarning("DrmEglServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR");
+ return false;
+ }
+ return m_egl_destroy_image(m_egl_display, image);
+}
+
+EGLImageKHR DrmEglServerBufferIntegration::eglCreateDRMImageMESA (const EGLint *attrib_list)
+{
+ if (m_egl_create_drm_image)
+ return m_egl_create_drm_image(m_egl_display, attrib_list);
+ else
+ qWarning("DrmEglServerBufferIntegration: Trying to use unresolved function eglCreateDRMImageMESA");
+ return EGL_NO_IMAGE_KHR;
+
+}
+
+EGLBoolean DrmEglServerBufferIntegration::eglExportDRMImageMESA (EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride)
+{
+ if (m_egl_export_drm_image)
+ return m_egl_export_drm_image(m_egl_display, image, name, handle, stride);
+ else
+ qWarning("DrmEglServerBufferIntegration: Trying to use unresolved function eglExportDRMImageMESA");
+ return 0;
+}
+
+void DrmEglServerBufferIntegration::glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
+{
+ if (m_gl_egl_image_target_texture_2d)
+ return m_gl_egl_image_target_texture_2d(target, image);
+ else
+ qWarning("DrmEglServerBufferIntegration: Trying to use unresolved function glEGLImageTargetTexture2DOES");
+}
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri b/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri
new file mode 100644
index 000000000..2d4771a2a
--- /dev/null
+++ b/src/hardwareintegration/compositor/wayland-egl/wayland-egl.pri
@@ -0,0 +1,14 @@
+INCLUDEPATH += $$PWD
+
+!contains(QT_CONFIG, no-pkg-config) {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += wayland-server wayland-egl egl
+} else {
+ LIBS += -lwayland-egl -lwayland-server -lEGL
+}
+
+SOURCES += \
+ $$PWD/waylandeglclientbufferintegration.cpp
+
+HEADERS += \
+ $$PWD/waylandeglclientbufferintegration.h
diff --git a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp
new file mode 100644
index 000000000..a127b7bd2
--- /dev/null
+++ b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.cpp
@@ -0,0 +1,258 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "waylandeglclientbufferintegration.h"
+
+#include <QtCompositor/private/qwlcompositor_p.h>
+#include <QtCompositor/private/qwlsurface_p.h>
+#include <qpa/qplatformnativeinterface.h>
+#include <QtGui/QGuiApplication>
+#include <QtGui/QOpenGLContext>
+#include <qpa/qplatformscreen.h>
+#include <QtGui/QWindow>
+#include <QtCore/QPointer>
+
+#include <QDebug>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#ifndef EGL_WL_bind_wayland_display
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLUNBINDWAYLANDDISPLAYWL) (EGLDisplay dpy, struct wl_display *display);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYWAYLANDBUFFERWL) (EGLDisplay dpy, struct wl_buffer *buffer, EGLint attribute, EGLint *value);
+#endif
+
+#ifndef EGL_KHR_image
+typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
+#endif
+
+#ifndef GL_OES_EGL_image
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class WaylandEglClientBufferIntegrationPrivate
+{
+public:
+ WaylandEglClientBufferIntegrationPrivate()
+ : egl_display(EGL_NO_DISPLAY)
+ , valid(false)
+ , display_bound(false)
+ , flipperConnected(false)
+ , egl_bind_wayland_display(0)
+ , egl_unbind_wayland_display(0)
+ , egl_query_wayland_buffer(0)
+ , egl_create_image(0)
+ , egl_destroy_image(0)
+ , gl_egl_image_target_texture_2d(0)
+ { }
+ EGLDisplay egl_display;
+ bool valid;
+ bool display_bound;
+ bool flipperConnected;
+ PFNEGLBINDWAYLANDDISPLAYWL egl_bind_wayland_display;
+ PFNEGLUNBINDWAYLANDDISPLAYWL egl_unbind_wayland_display;
+ PFNEGLQUERYWAYLANDBUFFERWL egl_query_wayland_buffer;
+
+ PFNEGLCREATEIMAGEKHRPROC egl_create_image;
+ PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image;
+
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC gl_egl_image_target_texture_2d;
+};
+
+WaylandEglClientBufferIntegration::WaylandEglClientBufferIntegration()
+ : QWaylandClientBufferIntegration()
+ , d_ptr(new WaylandEglClientBufferIntegrationPrivate)
+{
+}
+
+void WaylandEglClientBufferIntegration::initializeHardware(QtWayland::Display *waylandDisplay)
+{
+ Q_D(WaylandEglClientBufferIntegration);
+
+ const bool ignoreBindDisplay = !qgetenv("QT_WAYLAND_IGNORE_BIND_DISPLAY").isEmpty();
+
+ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+ if (!nativeInterface) {
+ qWarning("Failed to initialize egl display. No native platform interface available.\n");
+ return;
+ }
+
+ d->egl_display = nativeInterface->nativeResourceForWindow("EglDisplay", m_compositor->window());
+ if (!d->egl_display) {
+ qWarning("Failed to initialize egl display. Could not get EglDisplay for window.\n");
+ return;
+ }
+
+ const char *extensionString = eglQueryString(d->egl_display, EGL_EXTENSIONS);
+ if ((!extensionString || !strstr(extensionString, "EGL_WL_bind_wayland_display")) && !ignoreBindDisplay) {
+ qWarning("Failed to initialize egl display. There is no EGL_WL_bind_wayland_display extension.\n");
+ return;
+ }
+
+ d->egl_bind_wayland_display = reinterpret_cast<PFNEGLBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglBindWaylandDisplayWL"));
+ d->egl_unbind_wayland_display = reinterpret_cast<PFNEGLUNBINDWAYLANDDISPLAYWL>(eglGetProcAddress("eglUnbindWaylandDisplayWL"));
+ if ((!d->egl_bind_wayland_display || !d->egl_unbind_wayland_display) && !ignoreBindDisplay) {
+ qWarning("Failed to initialize egl display. Could not find eglBindWaylandDisplayWL and eglUnbindWaylandDisplayWL.\n");
+ return;
+ }
+
+ d->egl_query_wayland_buffer = reinterpret_cast<PFNEGLQUERYWAYLANDBUFFERWL>(eglGetProcAddress("eglQueryWaylandBufferWL"));
+ if (!d->egl_query_wayland_buffer) {
+ qWarning("Failed to initialize egl display. Could not find eglQueryWaylandBufferWL.\n");
+ return;
+ }
+
+ d->egl_create_image = reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC>(eglGetProcAddress("eglCreateImageKHR"));
+ d->egl_destroy_image = reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC>(eglGetProcAddress("eglDestroyImageKHR"));
+ if (!d->egl_create_image || !d->egl_destroy_image) {
+ qWarning("Failed to initialize egl display. Could not find eglCreateImageKHR and eglDestroyImageKHR.\n");
+ return;
+ }
+
+ d->gl_egl_image_target_texture_2d = reinterpret_cast<PFNGLEGLIMAGETARGETTEXTURE2DOESPROC>(eglGetProcAddress("glEGLImageTargetTexture2DOES"));
+ if (!d->gl_egl_image_target_texture_2d) {
+ qWarning("Failed to initialize egl display. Could not find glEGLImageTargetTexture2DOES.\n");
+ return;
+ }
+
+ if (d->egl_bind_wayland_display && d->egl_unbind_wayland_display) {
+ d->display_bound = d->egl_bind_wayland_display(d->egl_display, waylandDisplay->handle());
+ if (!d->display_bound && !ignoreBindDisplay) {
+ qWarning("Failed to initialize egl display. Could not bind Wayland display.\n");
+ return;
+ }
+ }
+
+ d->valid = true;
+
+ qWarning("EGL Wayland extension successfully initialized.%s\n", !d->display_bound ? " eglBindWaylandDisplayWL ignored" : "");
+}
+
+void WaylandEglClientBufferIntegration::bindTextureToBuffer(struct ::wl_resource *buffer)
+{
+ Q_D(WaylandEglClientBufferIntegration);
+ if (!d->valid) {
+ qWarning("bindTextureToBuffer() failed");
+ return;
+ }
+
+ EGLImageKHR image = d->egl_create_image(d->egl_display, EGL_NO_CONTEXT,
+ EGL_WAYLAND_BUFFER_WL,
+ buffer, NULL);
+
+ d->gl_egl_image_target_texture_2d(GL_TEXTURE_2D, image);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ d->egl_destroy_image(d->egl_display, image);
+}
+
+bool WaylandEglClientBufferIntegration::isYInverted(struct ::wl_resource *buffer) const
+{
+#if defined(EGL_WAYLAND_Y_INVERTED_WL)
+ Q_D(const WaylandEglClientBufferIntegration);
+
+ EGLint isYInverted;
+ EGLBoolean ret;
+ ret = d->egl_query_wayland_buffer(d->egl_display, buffer, EGL_WAYLAND_Y_INVERTED_WL, &isYInverted);
+
+ // Yes, this looks strange, but the specification says that EGL_FALSE return
+ // value (not supported) should be treated the same as EGL_TRUE return value
+ // and EGL_TRUE in value.
+ if (ret == EGL_FALSE || isYInverted == EGL_TRUE)
+ return true;
+#endif
+
+ return QWaylandClientBufferIntegration::isYInverted(buffer);
+}
+
+
+bool WaylandEglClientBufferIntegration::setDirectRenderSurface(QWaylandSurface *surface)
+{
+ Q_D(WaylandEglClientBufferIntegration);
+
+ QPlatformScreen *screen = QPlatformScreen::platformScreenForWindow(m_compositor->window());
+ QPlatformScreenPageFlipper *flipper = screen ? screen->pageFlipper() : 0;
+ if (flipper && !d->flipperConnected) {
+ QObject::connect(flipper, SIGNAL(bufferReleased(QPlatformScreenBuffer*)), m_compositor->handle(), SLOT(releaseBuffer(QPlatformScreenBuffer*)));
+ d->flipperConnected = true;
+ }
+ Q_UNUSED(surface);
+ return flipper;
+}
+
+void *WaylandEglClientBufferIntegration::lockNativeBuffer(struct ::wl_resource *buffer, QOpenGLContext *) const
+{
+ Q_D(const WaylandEglClientBufferIntegration);
+
+ EGLImageKHR image = d->egl_create_image(d->egl_display, EGL_NO_CONTEXT,
+ EGL_WAYLAND_BUFFER_WL,
+ buffer, NULL);
+ return image;
+}
+
+void WaylandEglClientBufferIntegration::unlockNativeBuffer(void *native_buffer, QOpenGLContext *) const
+{
+ Q_D(const WaylandEglClientBufferIntegration);
+ EGLImageKHR image = static_cast<EGLImageKHR>(native_buffer);
+
+ d->egl_destroy_image(d->egl_display, image);
+}
+
+QSize WaylandEglClientBufferIntegration::bufferSize(struct ::wl_resource *buffer) const
+{
+ Q_D(const WaylandEglClientBufferIntegration);
+
+ int width, height;
+ d->egl_query_wayland_buffer(d->egl_display, buffer, EGL_WIDTH, &width);
+ d->egl_query_wayland_buffer(d->egl_display, buffer, EGL_HEIGHT, &height);
+
+ return QSize(width, height);
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.h b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.h
new file mode 100644
index 000000000..a289baa0d
--- /dev/null
+++ b/src/hardwareintegration/compositor/wayland-egl/waylandeglclientbufferintegration.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 Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WAYLANDEGLINTEGRATION_H
+#define WAYLANDEGLINTEGRATION_H
+
+#include <QtCompositor/qwaylandclientbufferintegration.h>
+#include <QtCore/QScopedPointer>
+
+QT_BEGIN_NAMESPACE
+
+class WaylandEglClientBufferIntegrationPrivate;
+
+class WaylandEglClientBufferIntegration : public QWaylandClientBufferIntegration
+{
+ Q_DECLARE_PRIVATE(WaylandEglClientBufferIntegration)
+public:
+ WaylandEglClientBufferIntegration();
+
+ void initializeHardware(QtWayland::Display *waylandDisplay) Q_DECL_OVERRIDE;
+
+ void bindTextureToBuffer(struct ::wl_resource *buffer) Q_DECL_OVERRIDE;
+ bool isYInverted(struct ::wl_resource *) const Q_DECL_OVERRIDE;
+
+ bool setDirectRenderSurface(QWaylandSurface *) Q_DECL_OVERRIDE;
+
+ void *lockNativeBuffer(struct ::wl_resource *buffer, QOpenGLContext *context) const Q_DECL_OVERRIDE;
+ void unlockNativeBuffer(void *native_buffer, QOpenGLContext *context) const Q_DECL_OVERRIDE;
+
+ QSize bufferSize(struct ::wl_resource *buffer) const Q_DECL_OVERRIDE;
+
+private:
+ Q_DISABLE_COPY(WaylandEglClientBufferIntegration)
+ QScopedPointer<WaylandEglClientBufferIntegrationPrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // WAYLANDEGLINTEGRATION_H
+
diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri b/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri
new file mode 100644
index 000000000..cde790bdc
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite-egl/xcomposite-egl.pri
@@ -0,0 +1,16 @@
+include($$PWD/../xcomposite_share/xcomposite_share.pri)
+
+!contains(QT_CONFIG, no-pkg-config) {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += xcomposite egl x11 wayland-server
+} else {
+ LIBS += -lXcomposite -lEGL -lX11
+}
+
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/xcompositeeglintegration.h
+
+SOURCES += \
+ $$PWD/xcompositeeglintegration.cpp
diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp
new file mode 100644
index 000000000..c645b997f
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xcompositeeglintegration.h"
+
+#include "wayland-xcomposite-server-protocol.h"
+
+#include <QtCompositor/private/qwlcompositor_p.h>
+#include <QtGui/QGuiApplication>
+#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformopenglcontext.h>
+
+#include "xcompositebuffer.h"
+#include "xcompositehandler.h"
+#include <X11/extensions/Xcomposite.h>
+
+#include <QtCore/QDebug>
+
+QT_BEGIN_NAMESPACE
+
+QVector<EGLint> eglbuildSpec()
+{
+ QVector<EGLint> spec;
+
+ spec.append(EGL_SURFACE_TYPE); spec.append(EGL_WINDOW_BIT | EGL_PIXMAP_BIT);
+ spec.append(EGL_RENDERABLE_TYPE); spec.append(EGL_OPENGL_ES2_BIT);
+ spec.append(EGL_BIND_TO_TEXTURE_RGBA); spec.append(EGL_TRUE);
+ spec.append(EGL_ALPHA_SIZE); spec.append(8);
+ spec.append(EGL_NONE);
+ return spec;
+}
+
+XCompositeEglClientBufferIntegration::XCompositeEglClientBufferIntegration()
+ : QWaylandClientBufferIntegration()
+ , mDisplay(0)
+{
+
+}
+
+void XCompositeEglClientBufferIntegration::initializeHardware(QtWayland::Display *)
+{
+ QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface();
+ if (nativeInterface) {
+ mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWindow("Display",m_compositor->window()));
+ if (!mDisplay)
+ qFatal("could not retireve Display from platform integration");
+ mEglDisplay = static_cast<EGLDisplay>(nativeInterface->nativeResourceForWindow("EGLDisplay",m_compositor->window()));
+ if (!mEglDisplay)
+ qFatal("could not retrieve EGLDisplay from platform integration");
+ } else {
+ qFatal("Platform integration doesn't have native interface");
+ }
+ mScreen = XDefaultScreen(mDisplay);
+ new XCompositeHandler(m_compositor->handle(), mDisplay);
+}
+
+void XCompositeEglClientBufferIntegration::bindTextureToBuffer(struct ::wl_resource *buffer)
+{
+ XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
+ Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());
+
+ QVector<EGLint> eglConfigSpec = eglbuildSpec();
+
+ EGLint matching = 0;
+ EGLConfig config;
+ bool matched = eglChooseConfig(mEglDisplay,eglConfigSpec.constData(),&config,1,&matching);
+ if (!matched || !matching) {
+ qWarning("Could not retrieve a suitable EGL config");
+ return;
+ }
+
+ QVector<EGLint> attribList;
+
+ attribList.append(EGL_TEXTURE_FORMAT);
+ attribList.append(EGL_TEXTURE_RGBA);
+ attribList.append(EGL_TEXTURE_TARGET);
+ attribList.append(EGL_TEXTURE_2D);
+ attribList.append(EGL_NONE);
+
+ EGLSurface surface = eglCreatePixmapSurface(mEglDisplay,config,pixmap,attribList.constData());
+ if (surface == EGL_NO_SURFACE) {
+ qDebug() << "Failed to create eglsurface" << pixmap << compositorBuffer->window();
+ }
+
+ compositorBuffer->setInvertedY(true);
+
+ if (!eglBindTexImage(mEglDisplay,surface,EGL_BACK_BUFFER)) {
+ qDebug() << "Failed to bind";
+ }
+
+ // eglDestroySurface(mEglDisplay,surface);
+}
+
+bool XCompositeEglClientBufferIntegration::isYInverted(struct ::wl_resource *buffer) const
+{
+ XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
+ return compositorBuffer->isYInverted();
+}
+
+QSize XCompositeEglClientBufferIntegration::bufferSize(struct ::wl_resource *buffer) const
+{
+ XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
+
+ return compositorBuffer->size();
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.h
new file mode 100644
index 000000000..5497daed4
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite-egl/xcompositeeglintegration.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 Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XCOMPOSITEEGLINTEGRATION_H
+#define XCOMPOSITEEGLINTEGRATION_H
+
+#include <QtCompositor/qwaylandclientbufferintegration.h>
+
+#include "xlibinclude.h"
+
+#include <EGL/egl.h>
+
+QT_BEGIN_NAMESPACE
+
+class XCompositeEglClientBufferIntegration : public QWaylandClientBufferIntegration
+{
+public:
+ XCompositeEglClientBufferIntegration();
+
+ void initializeHardware(QtWayland::Display *waylandDisplay) Q_DECL_OVERRIDE;
+
+ void bindTextureToBuffer(struct ::wl_resource *buffer) Q_DECL_OVERRIDE;
+ bool isYInverted(struct ::wl_resource *) const Q_DECL_OVERRIDE;
+
+ QSize bufferSize(struct ::wl_resource *buffer) const Q_DECL_OVERRIDE;
+
+private:
+ Display *mDisplay;
+ EGLDisplay mEglDisplay;
+ int mScreen;
+};
+
+QT_END_NAMESPACE
+
+#endif // XCOMPOSITEEGLINTEGRATION_H
diff --git a/src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri b/src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri
new file mode 100644
index 000000000..ccbbe46a6
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite-glx/xcomposite-glx.pri
@@ -0,0 +1,16 @@
+include($$PWD/../xcomposite_share/xcomposite_share.pri)
+
+!contains(QT_CONFIG, no-pkg-config) {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += xcomposite gl x11 wayland-server
+} else {
+ LIBS += -lXcomposite -lGL -lX11
+}
+
+INCLUDEPATH += $$PWD
+
+HEADERS += \
+ $$PWD/xcompositeglxintegration.h
+
+SOURCES += \
+ $$PWD/xcompositeglxintegration.cpp
diff --git a/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp b/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp
new file mode 100644
index 000000000..a58827cee
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xcompositeglxintegration.h"
+
+#include <QtCompositor/private/qwlcompositor_p.h>
+#include "wayland-xcomposite-server-protocol.h"
+
+#include <qpa/qplatformnativeinterface.h>
+#include <qpa/qplatformintegration.h>
+#include <QtGui/QOpenGLContext>
+
+#include "xcompositebuffer.h"
+#include "xcompositehandler.h"
+#include <X11/extensions/Xcomposite.h>
+
+#include <QtCore/QDebug>
+
+QT_BEGIN_NAMESPACE
+
+QVector<int> qglx_buildSpec()
+{
+ QVector<int> spec(48);
+ int i = 0;
+
+ spec[i++] = GLX_LEVEL;
+ spec[i++] = 0;
+ spec[i++] = GLX_DRAWABLE_TYPE; spec[i++] = GLX_PIXMAP_BIT | GLX_WINDOW_BIT;
+ spec[i++] = GLX_BIND_TO_TEXTURE_TARGETS_EXT; spec[i++] = GLX_TEXTURE_2D_BIT_EXT;
+ spec[i++] = GLX_BIND_TO_TEXTURE_RGB_EXT; spec[i++] = true;
+
+ spec[i++] = 0;
+ return spec;
+}
+
+
+XCompositeGLXClientBufferIntegration::XCompositeGLXClientBufferIntegration()
+ : QWaylandClientBufferIntegration()
+ , mDisplay(0)
+ , mHandler(0)
+{
+}
+
+XCompositeGLXClientBufferIntegration::~XCompositeGLXClientBufferIntegration()
+{
+ delete mHandler;
+}
+
+void XCompositeGLXClientBufferIntegration::initializeHardware(QtWayland::Display *)
+{
+ QPlatformNativeInterface *nativeInterface = QGuiApplicationPrivate::platformIntegration()->nativeInterface();
+ if (nativeInterface) {
+ mDisplay = static_cast<Display *>(nativeInterface->nativeResourceForWindow("Display",m_compositor->window()));
+ if (!mDisplay)
+ qFatal("could not retireve Display from platform integration");
+ } else {
+ qFatal("Platform integration doesn't have native interface");
+ }
+ mScreen = XDefaultScreen(mDisplay);
+
+ mHandler = new XCompositeHandler(m_compositor->handle(), mDisplay);
+
+ QOpenGLContext *glContext = new QOpenGLContext();
+ glContext->create();
+
+ m_glxBindTexImageEXT = reinterpret_cast<PFNGLXBINDTEXIMAGEEXTPROC>(glContext->getProcAddress("glXBindTexImageEXT"));
+ if (!m_glxBindTexImageEXT) {
+ qDebug() << "Did not find glxBindTexImageExt, everything will FAIL!";
+ }
+ m_glxReleaseTexImageEXT = reinterpret_cast<PFNGLXRELEASETEXIMAGEEXTPROC>(glContext->getProcAddress("glXReleaseTexImageEXT"));
+ if (!m_glxReleaseTexImageEXT) {
+ qDebug() << "Did not find glxReleaseTexImageExt";
+ }
+
+ delete glContext;
+}
+
+void XCompositeGLXClientBufferIntegration::updateTextureFromBuffer(struct ::wl_resource *buffer)
+{
+ XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
+ Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());
+
+ QVector<int> glxConfigSpec = qglx_buildSpec();
+ int numberOfConfigs;
+ GLXFBConfig *configs = glXChooseFBConfig(mDisplay,mScreen,glxConfigSpec.constData(),&numberOfConfigs);
+
+ QVector<int> attribList;
+ attribList.append(GLX_TEXTURE_FORMAT_EXT);
+ attribList.append(GLX_TEXTURE_FORMAT_RGB_EXT);
+ attribList.append(GLX_TEXTURE_TARGET_EXT);
+ attribList.append(GLX_TEXTURE_2D_EXT);
+ attribList.append(0);
+ GLXPixmap glxPixmap = glXCreatePixmap(mDisplay,*configs,pixmap,attribList.constData());
+
+ uint inverted = 0;
+ glXQueryDrawable(mDisplay, glxPixmap, GLX_Y_INVERTED_EXT,&inverted);
+ compositorBuffer->setInvertedY(!inverted);
+
+ XFree(configs);
+
+ m_glxBindTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT, 0);
+ //Do we need to change the api so that we do bind and release in the painevent?
+ //The specification states that when deleting the texture the color buffer is deleted
+// m_glxReleaseTexImageEXT(mDisplay,glxPixmap,GLX_FRONT_EXT);
+}
+
+bool XCompositeGLXClientBufferIntegration::isYInverted(struct ::wl_resource *buffer) const
+{
+ return XCompositeBuffer::fromResource(buffer)->isYInverted();
+}
+
+QSize XCompositeGLXClientBufferIntegration::bufferSize(struct ::wl_resource *buffer) const
+{
+ XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
+
+ return compositorBuffer->size();
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.h b/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.h
new file mode 100644
index 000000000..5a724eedf
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite-glx/xcompositeglxintegration.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 Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XCOMPOSITEGLXINTEGRATION_H
+#define XCOMPOSITEGLXINTEGRATION_H
+
+#include <QtCompositor/qwaylandclientbufferintegration.h>
+
+#include "xlibinclude.h"
+
+#define GLX_GLXEXT_PROTOTYPES
+#include <GL/glx.h>
+#include <GL/glxext.h>
+
+QT_BEGIN_NAMESPACE
+
+class XCompositeHandler;
+
+class XCompositeGLXClientBufferIntegration : public QWaylandClientBufferIntegration
+{
+public:
+ XCompositeGLXClientBufferIntegration();
+ ~XCompositeGLXClientBufferIntegration();
+
+ void initializeHardware(QtWayland::Display *waylandDisplay) Q_DECL_OVERRIDE;
+
+ void bindTextureToBuffer(struct ::wl_resource *buffer) Q_DECL_OVERRIDE;
+ bool isYInverted(struct ::wl_resource *) const Q_DECL_OVERRIDE;
+
+ QSize bufferSize(struct ::wl_resource *buffer) const Q_DECL_OVERRIDE;
+
+private:
+ PFNGLXBINDTEXIMAGEEXTPROC m_glxBindTexImageEXT;
+ PFNGLXRELEASETEXIMAGEEXTPROC m_glxReleaseTexImageEXT;
+
+ Display *mDisplay;
+ int mScreen;
+ XCompositeHandler *mHandler;
+};
+
+QT_END_NAMESPACE
+
+#endif // XCOMPOSITEGLXINTEGRATION_H
diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri b/src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri
new file mode 100644
index 000000000..06937c412
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite_share/xcomposite_share.pri
@@ -0,0 +1,15 @@
+INCLUDEPATH += $$PWD
+
+CONFIG += wayland-scanner
+WAYLANDSERVERSOURCES += $$PWD/../../../extensions/xcomposite.xml $$PWD/../../../3rdparty/protocol/wayland.xml
+
+HEADERS += \
+ $$PWD/xcompositebuffer.h \
+ $$PWD/xcompositehandler.h \
+ $$PWD/xlibinclude.h
+
+SOURCES += \
+ $$PWD/xcompositebuffer.cpp \
+ $$PWD/xcompositehandler.cpp
+
+QT += gui-private
diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp b/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp
new file mode 100644
index 000000000..0457214b4
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.cpp
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xcompositebuffer.h"
+
+QT_BEGIN_NAMESPACE
+
+XCompositeBuffer::XCompositeBuffer(Window window, const QSize &size,
+ struct ::wl_client *client, uint32_t id)
+ : QtWaylandServer::wl_buffer(client, id)
+ , mWindow(window)
+ , mInvertedY(false)
+ , mSize(size)
+{
+}
+
+void XCompositeBuffer::buffer_destroy_resource(Resource *)
+{
+ delete this;
+}
+
+void XCompositeBuffer::buffer_destroy(Resource *resource)
+{
+ wl_resource_destroy(resource->handle);
+}
+
+Window XCompositeBuffer::window()
+{
+ return mWindow;
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h b/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h
new file mode 100644
index 000000000..20cf399b6
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite_share/xcompositebuffer.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XCOMPOSITEBUFFER_H
+#define XCOMPOSITEBUFFER_H
+
+#include <private/qwlcompositor_p.h>
+#include <qwayland-server-wayland.h>
+
+#include <QtCore/QSize>
+
+#include <QtCore/QTextStream>
+#include <QtCore/QDataStream>
+#include <QtCore/QMetaType>
+#include <QtCore/QVariant>
+
+#include <X11/X.h>
+
+QT_BEGIN_NAMESPACE
+
+class XCompositeBuffer : public QtWaylandServer::wl_buffer
+{
+public:
+ XCompositeBuffer(Window window, const QSize &size,
+ struct ::wl_client *client, uint32_t id);
+
+ Window window();
+
+ bool isYInverted() const { return mInvertedY; }
+ void setInvertedY(bool inverted) { mInvertedY = inverted; }
+
+ QSize size() const { return mSize; }
+
+ static XCompositeBuffer *fromResource(struct ::wl_resource *resource) { return static_cast<XCompositeBuffer*>(Resource::fromResource(resource)->buffer); }
+
+protected:
+ void buffer_destroy_resource(Resource *) Q_DECL_OVERRIDE;
+ void buffer_destroy(Resource *) Q_DECL_OVERRIDE;
+
+private:
+ Window mWindow;
+ bool mInvertedY;
+ QSize mSize;
+};
+
+QT_END_NAMESPACE
+
+#endif // XCOMPOSITORBUFFER_H
diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp b/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp
new file mode 100644
index 000000000..0f10d38de
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xcompositehandler.h"
+
+#include "wayland-xcomposite-server-protocol.h"
+
+#include "xcompositebuffer.h"
+#include <X11/extensions/Xcomposite.h>
+
+QT_BEGIN_NAMESPACE
+
+XCompositeHandler::XCompositeHandler(QtWayland::Compositor *compositor, Display *display)
+ : QtWaylandServer::qt_xcomposite(compositor->wl_display())
+{
+ compositor->window()->create();
+
+ mFakeRootWindow = new QWindow(compositor->window());
+ mFakeRootWindow->setGeometry(QRect(-1,-1,1,1));
+ mFakeRootWindow->create();
+ mFakeRootWindow->show();
+
+ int composite_event_base, composite_error_base;
+ if (!XCompositeQueryExtension(display, &composite_event_base, &composite_error_base))
+ qFatal("XComposite required");
+
+ mDisplayString = QString::fromLocal8Bit(XDisplayString(display));
+}
+
+void XCompositeHandler::xcomposite_bind_resource(Resource *resource)
+{
+ send_root(resource->handle, mDisplayString, mFakeRootWindow->winId());
+}
+
+void XCompositeHandler::xcomposite_create_buffer(Resource *resource, uint32_t id, uint32_t window,
+ int32_t width, int32_t height)
+{
+ new XCompositeBuffer(Window(window), QSize(width, height), resource->client(), id);
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h b/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h
new file mode 100644
index 000000000..678ad4460
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite_share/xcompositehandler.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XCOMPOSITEHANDLER_H
+#define XCOMPOSITEHANDLER_H
+
+#include <QtCompositor/private/qwlcompositor_p.h>
+
+#include "xlibinclude.h"
+
+#include "qwayland-server-xcomposite.h"
+#include <wayland-server.h>
+
+QT_BEGIN_NAMESPACE
+
+class XCompositeHandler : public QtWaylandServer::qt_xcomposite
+{
+public:
+ XCompositeHandler(QtWayland::Compositor *compositor, Display *display);
+
+private:
+ QWindow *mFakeRootWindow;
+
+ QString mDisplayString;
+
+ void xcomposite_bind_resource(Resource *resource) Q_DECL_OVERRIDE;
+ void xcomposite_create_buffer(Resource *resource, uint32_t id, uint32_t x_window,
+ int32_t width, int32_t height) Q_DECL_OVERRIDE;
+
+};
+
+QT_END_NAMESPACE
+
+#endif // XCOMPOSITEHANDLER_H
diff --git a/src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h b/src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h
new file mode 100644
index 000000000..733fd6fd0
--- /dev/null
+++ b/src/hardwareintegration/compositor/xcomposite_share/xlibinclude.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Compositor.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XLIBINCLUDE_H
+#define XLIBINCLUDE_H
+
+#include <QtCore/QEvent>
+#include <QtCore/QTextStream>
+#include <QtCore/QDataStream>
+#include <QtCore/QMetaType>
+#include <QtCore/QVariant>
+#include <QtGui/QCursor>
+#include <QtGui/private/qguiapplication_p.h>
+
+#include <X11/Xlib.h>
+#include "X11/extensions/Xcomposite.h"
+
+enum {
+ XFocusOut = FocusOut,
+ XFocusIn = FocusIn,
+ XKeyPress = KeyPress,
+ XKeyRelease = KeyRelease,
+ XNone = None,
+ XRevertToParent = RevertToParent,
+ XGrayScale = GrayScale,
+ XCursorShape = CursorShape
+};
+#undef FocusOut
+#undef FocusIn
+#undef KeyPress
+#undef KeyRelease
+#undef None
+#undef RevertToParent
+#undef GrayScale
+#undef CursorShape
+
+#ifdef FontChange
+#undef FontChange
+#endif
+
+#endif //XLIBINCLUDE_H