summaryrefslogtreecommitdiffstats
path: root/src/hardwareintegration/compositor
diff options
context:
space:
mode:
Diffstat (limited to 'src/hardwareintegration/compositor')
-rw-r--r--src/hardwareintegration/compositor/libhybris-egl-server/libhybris-egl-server.pri18
-rw-r--r--src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp197
-rw-r--r--src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h189
3 files changed, 404 insertions, 0 deletions
diff --git a/src/hardwareintegration/compositor/libhybris-egl-server/libhybris-egl-server.pri b/src/hardwareintegration/compositor/libhybris-egl-server/libhybris-egl-server.pri
new file mode 100644
index 000000000..84d901351
--- /dev/null
+++ b/src/hardwareintegration/compositor/libhybris-egl-server/libhybris-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/libhybriseglserverbufferintegration.cpp
+
+
+HEADERS += \
+ $$PWD/libhybriseglserverbufferintegration.h
+
+CONFIG += wayland-scanner
+WAYLANDSERVERSOURCES += $$PWD/../../../extensions/libhybris-egl-server-buffer.xml
diff --git a/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp
new file mode 100644
index 000000000..c15f3d154
--- /dev/null
+++ b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Jolla Ltd, author: <giulio.camuffo@jollamobile.com>
+** 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 "libhybriseglserverbufferintegration.h"
+
+#include <QtGui/QOpenGLContext>
+#include <hybris/eglplatformcommon/hybris_nativebufferext.h>
+#include <wayland-server.h>
+
+QT_BEGIN_NAMESPACE
+LibHybrisEglServerBuffer::LibHybrisEglServerBuffer(LibHybrisEglServerBufferIntegration *integration, const QSize &size, QtWayland::ServerBuffer::Format format)
+ : QtWayland::ServerBuffer(size,format)
+ , m_integration(integration)
+{
+ m_format = format;
+
+ EGLint egl_format;
+ switch (m_format) {
+ case RGBA32:
+ m_hybris_format = QtWaylandServer::qt_libhybris_egl_server_buffer::format_RGBA32;
+ egl_format = HYBRIS_PIXEL_FORMAT_RGBA_8888;
+ break;
+ default:
+ qWarning("LibHybrisEglServerBuffer: unsupported format");
+ m_hybris_format = QtWaylandServer::qt_libhybris_egl_server_buffer::format_RGBA32;
+ egl_format = HYBRIS_PIXEL_FORMAT_RGBA_8888;
+ break;
+ }
+
+ if (!m_integration->eglHybrisCreateNativeBuffer(size.width(), size.height(), HYBRIS_USAGE_HW_TEXTURE, egl_format, &m_stride, &m_buffer)) {
+ qWarning("LibHybrisEglServerBuffer: Failed to create egl buffer");
+ return;
+ }
+
+ int numInts;
+ int numFds;
+ m_integration->eglHybrisGetNativeBufferInfo(m_buffer, &numInts, &numFds);
+ m_ints.resize(numInts);
+ m_fds.resize(numFds);
+ m_integration->eglHybrisSerializeNativeBuffer(m_buffer, m_ints.data(), m_fds.data());
+
+ m_image = m_integration->eglCreateImageKHR(EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, m_buffer, 0);
+}
+
+struct ::wl_resource *LibHybrisEglServerBuffer::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_libhybris_egl_server_buffer::Resource *>::iterator egl_it = m_integration->resourceMap().find(client);
+ if (egl_it == m_integration->resourceMap().end()) {
+ qWarning("LibHybrisEglServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the libhybris_egl interface");
+ return 0;
+ }
+ struct ::wl_resource *egl_resource = (*egl_it)->handle;
+ Resource *resource = add(client);
+ wl_resource *bufRes = wl_client_new_object(client, &qt_libhybris_buffer_interface, 0, 0);
+
+ m_integration->send_server_buffer_created(egl_resource, resource->handle, bufRes, m_fds.size(), QByteArray((char *)m_ints.data(), m_ints.size() * sizeof(int32_t)),
+ m_name, m_size.width(), m_size.height(), m_stride, m_format);
+
+ m_qtbuffers.insert(resource, bufRes);
+
+ for (int i = 0; i < m_fds.size(); ++i) {
+ send_add_fd(resource->handle, m_fds.at(i));
+ }
+
+ return bufRes;
+ }
+ return m_qtbuffers.value(*it);
+}
+
+void LibHybrisEglServerBuffer::bindTextureToBuffer()
+{
+ if (!QOpenGLContext::currentContext()) {
+ qWarning("LibHybrisEglServerBuffer: 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);
+}
+
+LibHybrisEglServerBufferIntegration::LibHybrisEglServerBufferIntegration()
+{
+}
+
+LibHybrisEglServerBufferIntegration::~LibHybrisEglServerBufferIntegration()
+{
+}
+
+void LibHybrisEglServerBufferIntegration::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 libhybris egl server buffer integration. Missing egl display from platformplugin");
+ return;
+ }
+
+ m_egl_create_buffer = reinterpret_cast<PFNEGLHYBRISCREATENATIVEBUFFERPROC>(eglGetProcAddress("eglHybrisCreateNativeBuffer"));
+ if (!m_egl_create_buffer) {
+ qWarning("Failed to initialize libhybris egl server buffer integration. Could not find eglHybrisCreateNativeBuffer.\n");
+ return;
+ }
+ m_egl_get_buffer_info = reinterpret_cast<PFNEGLHYBRISGETNATIVEBUFFERINFOPROC>(eglGetProcAddress("eglHybrisGetNativeBufferInfo"));
+ if (!m_egl_get_buffer_info) {
+ qWarning("Failed to initialize libhybris egl server buffer integration. Could not find eglHybrisGetNativeBufferInfo.\n");
+ return;
+ }
+ m_egl_serialize_buffer = reinterpret_cast<PFNEGLHYBRISSERIALIZENATIVEBUFFERPROC>(eglGetProcAddress("eglHybrisSerializeNativeBuffer"));
+ if (!m_egl_serialize_buffer) {
+ qWarning("Failed to initialize libhybris egl server buffer integration. Could not find eglHybrisSerializeNativeBuffer.\n");
+ return;
+ }
+
+ const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS);
+ if (!extensionString || !strstr(extensionString, "EGL_KHR_image")) {
+ qWarning("Failed to initialize libhybris 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 libhybris egl server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR");
+ 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 libhybris egl server buffer integration. Could not find glEGLImageTargetTexture2DOES.\n");
+ return;
+ }
+
+ QtWaylandServer::qt_libhybris_egl_server_buffer::init(compositor->waylandDisplay());
+}
+
+bool LibHybrisEglServerBufferIntegration::supportsFormat(QtWayland::ServerBuffer::Format format) const
+{
+ switch (format) {
+ case QtWayland::ServerBuffer::RGBA32:
+ return true;
+ case QtWayland::ServerBuffer::A8:
+ return false;
+ default:
+ return false;
+ }
+}
+
+QtWayland::ServerBuffer *LibHybrisEglServerBufferIntegration::createServerBuffer(const QSize &size, QtWayland::ServerBuffer::Format format)
+{
+ return new LibHybrisEglServerBuffer(this, size, format);
+}
+
+QT_END_NAMESPACE
diff --git a/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h
new file mode 100644
index 000000000..35a3e8007
--- /dev/null
+++ b/src/hardwareintegration/compositor/libhybris-egl-server/libhybriseglserverbufferintegration.h
@@ -0,0 +1,189 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Jolla Ltd, author: <giulio.camuffo@jollamobile.com>
+** 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 LIBHYBRISEGLSERVERBUFFERINTEGRATION_H
+#define LIBHYBRISEGLSERVERBUFFERINTEGRATION_H
+
+#include <QtCompositor/private/qwlserverbufferintegration_p.h>
+
+#include "qwayland-server-libhybris-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 EGL_HYBRIS_native_buffer
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLHYBRISCREATENATIVEBUFFERPROC)(EGLint width, EGLint height, EGLint usage, EGLint format, EGLint *stride, EGLClientBuffer *buffer);
+typedef void (EGLAPIENTRYP PFNEGLHYBRISGETNATIVEBUFFERINFOPROC)(EGLClientBuffer buffer, int *num_ints, int *num_fds);
+typedef void (EGLAPIENTRYP PFNEGLHYBRISSERIALIZENATIVEBUFFERPROC)(EGLClientBuffer buffer, int *ints, int *fds);
+#endif
+
+#ifndef GL_OES_EGL_image
+typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class LibHybrisEglServerBufferIntegration;
+
+class LibHybrisEglServerBuffer : public QtWayland::ServerBuffer, public QtWaylandServer::qt_libhybris_buffer
+{
+public:
+ LibHybrisEglServerBuffer(LibHybrisEglServerBufferIntegration *integration, const QSize &size, QtWayland::ServerBuffer::Format format);
+
+ struct ::wl_resource *resourceForClient(struct ::wl_client *) Q_DECL_OVERRIDE;
+ void bindTextureToBuffer() Q_DECL_OVERRIDE;
+
+private:
+ LibHybrisEglServerBufferIntegration *m_integration;
+
+ EGLImageKHR m_image;
+ EGLClientBuffer m_buffer;
+
+ int32_t m_name;
+ int32_t m_stride;
+ QtWaylandServer::qt_libhybris_egl_server_buffer::format m_hybris_format;
+ QVector<int32_t> m_ints;
+ QVector<int32_t> m_fds;
+ QHash<Resource *, wl_resource *> m_qtbuffers;
+};
+
+class LibHybrisEglServerBufferIntegration :
+ public QtWayland::ServerBufferIntegration,
+ public QtWaylandServer::qt_libhybris_egl_server_buffer
+{
+public:
+ LibHybrisEglServerBufferIntegration();
+ ~LibHybrisEglServerBufferIntegration();
+
+ void initializeHardware(QWaylandCompositor *);
+
+ bool supportsFormat(QtWayland::ServerBuffer::Format format) const Q_DECL_OVERRIDE;
+ QtWayland::ServerBuffer *createServerBuffer(const QSize &size, QtWayland::ServerBuffer::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 void glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image);
+
+ inline EGLBoolean eglHybrisCreateNativeBuffer(EGLint width, EGLint height, EGLint usage, EGLint format, EGLint *stride, EGLClientBuffer *buffer);
+ inline void eglHybrisGetNativeBufferInfo(EGLClientBuffer buffer, int *num_ints, int *num_fds);
+ inline void eglHybrisSerializeNativeBuffer(EGLClientBuffer buffer, int *ints, int *fds);
+
+private:
+ EGLDisplay m_egl_display;
+ PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture_2d;
+
+ PFNEGLHYBRISCREATENATIVEBUFFERPROC m_egl_create_buffer;
+ PFNEGLHYBRISGETNATIVEBUFFERINFOPROC m_egl_get_buffer_info;
+ PFNEGLHYBRISSERIALIZENATIVEBUFFERPROC m_egl_serialize_buffer;
+
+ PFNEGLCREATEIMAGEKHRPROC m_egl_create_image;
+ PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image;
+};
+
+EGLImageKHR LibHybrisEglServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
+{
+ if (!m_egl_create_image) {
+ qWarning("LibHybrisEglServerBufferIntegration: 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 LibHybrisEglServerBufferIntegration::eglDestroyImageKHR (EGLImageKHR image)
+{
+ if (!m_egl_destroy_image) {
+ qWarning("LibHybrisEglServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR");
+ return false;
+ }
+ return m_egl_destroy_image(m_egl_display, image);
+}
+
+void LibHybrisEglServerBufferIntegration::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("LibHybrisEglServerBufferIntegration: Trying to use unresolved function glEGLImageTargetTexture2DOES");
+}
+
+EGLBoolean LibHybrisEglServerBufferIntegration::eglHybrisCreateNativeBuffer(EGLint width, EGLint height, EGLint usage, EGLint format, EGLint *stride, EGLClientBuffer *buffer)
+{
+ if (m_egl_create_buffer)
+ return m_egl_create_buffer(width, height, usage, format, stride, buffer);
+ else
+ qWarning("LibHybrisEglServerBufferIntegration: Trying to use unresolved function eglHybrisCreateNativeBuffer");
+ return EGL_FALSE;
+}
+
+void LibHybrisEglServerBufferIntegration::eglHybrisGetNativeBufferInfo(EGLClientBuffer buffer, int *num_ints, int *num_fds)
+{
+ if (m_egl_get_buffer_info)
+ m_egl_get_buffer_info(buffer, num_ints, num_fds);
+ else
+ qWarning("LibHybrisEglServerBufferIntegration: Trying to use unresolved function eglHybrisGetNativeBufferInfo");
+}
+
+void LibHybrisEglServerBufferIntegration::eglHybrisSerializeNativeBuffer(EGLClientBuffer buffer, int *ints, int *fds)
+{
+ if (m_egl_serialize_buffer)
+ m_egl_serialize_buffer(buffer, ints, fds);
+ else
+ qWarning("LibHybrisEglServerBufferIntegration: Trying to use unresolved function eglHybrisSerializeNativeBuffer");
+}
+
+QT_END_NAMESPACE
+
+#endif