From 582af70640e411d8f423f1bc0528d5a5fce08e3a Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Tue, 11 Sep 2018 13:02:39 +0200 Subject: Add server buffer integration using Linux dma-buf Fixes: QTBUG-70494 Change-Id: Iaa4990fe9d39a1f9fb81f5e5f19039aa2e52dcac Reviewed-by: Johan Helsing --- .../dmabuf_server_buffer/dmabuf_server_buffer.pro | 1 + config.tests/dmabuf_server_buffer/main.cpp | 63 ++++++ examples/wayland/server-buffer/README | 4 +- src/client/configure.json | 11 ++ src/compositor/configure.json | 11 ++ src/extensions/qt-dmabuf-server-buffer.xml | 60 ++++++ .../client/dmabuf-server/dmabuf-server.pri | 12 ++ .../dmabufserverbufferintegration.cpp | 188 ++++++++++++++++++ .../dmabuf-server/dmabufserverbufferintegration.h | 146 ++++++++++++++ .../compositor/dmabuf-server/dmabuf-server.pri | 13 ++ .../dmabufserverbufferintegration.cpp | 218 +++++++++++++++++++++ .../dmabuf-server/dmabufserverbufferintegration.h | 195 ++++++++++++++++++ src/plugins/hardwareintegration/client/client.pro | 2 + .../client/dmabuf-server/dmabuf-server.json | 3 + .../client/dmabuf-server/dmabuf-server.pro | 15 ++ .../client/dmabuf-server/main.cpp | 64 ++++++ .../client/wayland-egl/main.cpp | 4 +- .../hardwareintegration/compositor/compositor.pro | 2 + .../compositor/dmabuf-server/dmabuf-server.json | 3 + .../compositor/dmabuf-server/dmabuf-server.pro | 12 ++ .../compositor/dmabuf-server/main.cpp | 62 ++++++ 21 files changed, 1084 insertions(+), 5 deletions(-) create mode 100644 config.tests/dmabuf_server_buffer/dmabuf_server_buffer.pro create mode 100644 config.tests/dmabuf_server_buffer/main.cpp create mode 100644 src/extensions/qt-dmabuf-server-buffer.xml create mode 100644 src/hardwareintegration/client/dmabuf-server/dmabuf-server.pri create mode 100644 src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.cpp create mode 100644 src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.h create mode 100644 src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri create mode 100644 src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp create mode 100644 src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h create mode 100644 src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.json create mode 100644 src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.pro create mode 100644 src/plugins/hardwareintegration/client/dmabuf-server/main.cpp create mode 100644 src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.json create mode 100644 src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pro create mode 100644 src/plugins/hardwareintegration/compositor/dmabuf-server/main.cpp diff --git a/config.tests/dmabuf_server_buffer/dmabuf_server_buffer.pro b/config.tests/dmabuf_server_buffer/dmabuf_server_buffer.pro new file mode 100644 index 00000000..28dcadcb --- /dev/null +++ b/config.tests/dmabuf_server_buffer/dmabuf_server_buffer.pro @@ -0,0 +1 @@ +SOURCES += main.cpp diff --git a/config.tests/dmabuf_server_buffer/main.cpp b/config.tests/dmabuf_server_buffer/main.cpp new file mode 100644 index 00000000..aa04d18f --- /dev/null +++ b/config.tests/dmabuf_server_buffer/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Compositor. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 The Qt Company Ltd 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 +#include +#include + +int main() +{ +#ifdef EGL_LINUX_DMA_BUF_EXT + return 0; +#else +#error Requires EGL_LINUX_DMA_BUF_EXT + return 1; +#endif +} diff --git a/examples/wayland/server-buffer/README b/examples/wayland/server-buffer/README index 4e5eebbb..5744a6ba 100644 --- a/examples/wayland/server-buffer/README +++ b/examples/wayland/server-buffer/README @@ -2,10 +2,10 @@ This is the example to demonstrate the server buffer interfaces Compile up both compositor and client. -If you have the drm-egl-server buffer integration (and you are running Mesa) +If you have the dmabuf-server buffer integration (and you are running Mesa) then start the compositor with: -$ QT_WAYLAND_SERVER_BUFFER_INTEGRATION=drm-egl-server ./compositor +$ QT_WAYLAND_SERVER_BUFFER_INTEGRATION=dmabuf-server ./compositor Note: if you are running a compositor on an X11 desktop, you also need to diff --git a/src/client/configure.json b/src/client/configure.json index ef5e87bb..1f86a493 100644 --- a/src/client/configure.json +++ b/src/client/configure.json @@ -68,6 +68,12 @@ "type": "compile", "test": "libhybris_egl_server", "use": "egl" + }, + "dmabuf-server-buffer": { + "label": "Linux dma-buf Buffer Sharing", + "type": "compile", + "test": "dmabuf_server_buffer", + "use": "egl" } }, @@ -111,6 +117,11 @@ "condition": "features.wayland-client && features.opengl && features.egl && tests.libhybris-egl-server", "output": [ "privateFeature" ] }, + "wayland-dmabuf-server-buffer": { + "label": "Linux dma-buf server buffer integration", + "condition": "features.wayland-client && features.opengl && features.egl && tests.dmabuf-server-buffer", + "output": [ "privateFeature" ] + }, "wayland-shm-emulation-server-buffer": { "label": "Shm emulation server buffer integration", "condition": "features.wayland-client && features.opengl", diff --git a/src/compositor/configure.json b/src/compositor/configure.json index 6864a94f..3b3d3320 100644 --- a/src/compositor/configure.json +++ b/src/compositor/configure.json @@ -73,6 +73,12 @@ "type": "compile", "test": "libhybris_egl_server", "use": "egl" + }, + "dmabuf-server-buffer": { + "label": "Linux dma-buf Buffer Sharing", + "type": "compile", + "test": "dmabuf_server_buffer", + "use": "egl" } }, @@ -116,6 +122,11 @@ "condition": "features.wayland-server && features.opengl && features.egl && tests.libhybris-egl-server", "output": [ "privateFeature" ] }, + "wayland-dmabuf-server-buffer": { + "label": "Linux dma-buf server buffer integration", + "condition": "features.wayland-server && features.opengl && features.egl && tests.dmabuf-server-buffer", + "output": [ "privateFeature" ] + }, "wayland-shm-emulation-server-buffer": { "label": "Shm emulation server buffer", "condition": "features.wayland-server && features.opengl", diff --git a/src/extensions/qt-dmabuf-server-buffer.xml b/src/extensions/qt-dmabuf-server-buffer.xml new file mode 100644 index 00000000..6b1d426f --- /dev/null +++ b/src/extensions/qt-dmabuf-server-buffer.xml @@ -0,0 +1,60 @@ + + + + Copyright (C) 2018 The Qt Company Ltd. + Contact: http://www.qt.io/licensing/ + + This file is part of the plugins of the Qt Toolkit. + + $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 The Qt Company Ltd 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$ + + + + This protocol is used internally by Qt for implementing the + qt_server_buffer extension on hardware that supports Linux dma-buf. + + This protocol is not part of the Qt API. It exists purely as an + implementation detail and may change from version to + version without notice, or even be removed. + + + + + + + + + + + + + diff --git a/src/hardwareintegration/client/dmabuf-server/dmabuf-server.pri b/src/hardwareintegration/client/dmabuf-server/dmabuf-server.pri new file mode 100644 index 00000000..9475581b --- /dev/null +++ b/src/hardwareintegration/client/dmabuf-server/dmabuf-server.pri @@ -0,0 +1,12 @@ +INCLUDEPATH += $$PWD + +QMAKE_USE += egl wayland-client + +SOURCES += \ + $$PWD/dmabufserverbufferintegration.cpp + +HEADERS += \ + $$PWD/dmabufserverbufferintegration.h + +CONFIG += wayland-scanner +WAYLANDCLIENTSOURCES += $$PWD/../../../extensions/qt-dmabuf-server-buffer.xml diff --git a/src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.cpp b/src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.cpp new file mode 100644 index 00000000..9f840414 --- /dev/null +++ b/src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dmabufserverbufferintegration.h" +#include +#include +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +DmaBufServerBuffer::DmaBufServerBuffer(DmaBufServerBufferIntegration *integration + , struct ::qt_server_buffer *id + , int32_t fd + , int32_t width + , int32_t height + , int32_t stride + , int32_t offset + , int32_t fourcc_format) + : m_integration(integration) + , m_server_buffer(id) +{ + m_size = QSize(width, height); + + + EGLint import_attribs[] = { + EGL_WIDTH, width, + EGL_HEIGHT, height, + EGL_LINUX_DRM_FOURCC_EXT, fourcc_format, + EGL_DMA_BUF_PLANE0_FD_EXT, fd, + EGL_DMA_BUF_PLANE0_OFFSET_EXT, offset, + EGL_DMA_BUF_PLANE0_PITCH_EXT, stride, + EGL_NONE + }; + + m_image = integration->eglCreateImageKHR( + EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + (EGLClientBuffer)nullptr, + import_attribs); + + int err = eglGetError(); + qCDebug(lcQpaWayland) << "imported egl image" << m_image; + if (m_image == EGL_NO_IMAGE_KHR || err != EGL_SUCCESS) + qCWarning(lcQpaWayland) << "DmaBufServerBuffer error importing image. EGL error code" << hex << err; + + qt_server_buffer_set_user_data(id, this); + +} + +DmaBufServerBuffer::~DmaBufServerBuffer() +{ + int err = m_integration->eglDestroyImageKHR(m_image); + if (err != EGL_SUCCESS) + qCWarning(lcQpaWayland) << "~DmaBufServerBuffer error destroying image" << m_image << "error code " << hex << err; + qt_server_buffer_release(m_server_buffer); + qt_server_buffer_destroy(m_server_buffer); +} + +QOpenGLTexture *DmaBufServerBuffer::toOpenGlTexture() +{ + if (!QOpenGLContext::currentContext()) + qCWarning(lcQpaWayland) <<"DmaBufServerBuffer: creating texture with no current context"; + + if (!m_texture) { + m_texture = new QOpenGLTexture(QOpenGLTexture::Target2D); + m_texture->create(); + } + + m_texture->bind(); + m_integration->glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + m_texture->release(); + m_texture->setSize(m_size.width(), m_size.height()); + return m_texture; +} + +void DmaBufServerBufferIntegration::initializeEgl() +{ + if (m_egl_initialized) + return; + m_egl_initialized = true; + + m_egl_display = eglGetDisplay((EGLNativeDisplayType) m_display->wl_display()); + if (m_egl_display == EGL_NO_DISPLAY) { + qCWarning(lcQpaWayland) << "Failed to initialize drm egl server buffer integration. Could not get egl display from wl_display."; + return; + } + + const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS); + + + if (!extensionString || !strstr(extensionString, "EGL_KHR_image")) { + qCWarning(lcQpaWayland) << "Failed to initialize dmabuf server buffer integration. There is no EGL_KHR_image extension.\n"; + return; + } + m_egl_create_image = reinterpret_cast(eglGetProcAddress("eglCreateImageKHR")); + m_egl_destroy_image = reinterpret_cast(eglGetProcAddress("eglDestroyImageKHR")); + if (!m_egl_create_image || !m_egl_destroy_image) { + qCWarning(lcQpaWayland) << "Failed to initialize dmabuf server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR"; + return; + } + + m_gl_egl_image_target_texture = reinterpret_cast(eglGetProcAddress("glEGLImageTargetTexture2DOES")); + if (!m_gl_egl_image_target_texture) { + qCWarning(lcQpaWayland) << "Failed to initialize dmabuf server buffer integration. Could not resolve glEGLImageTargetTexture2DOES"; + return; + } +} + +void DmaBufServerBufferIntegration::initialize(QWaylandDisplay *display) +{ + m_display = display; + display->addRegistryListener(&wlDisplayHandleGlobal, this); +} + +QWaylandServerBuffer *DmaBufServerBufferIntegration::serverBuffer(struct qt_server_buffer *buffer) +{ + return static_cast(qt_server_buffer_get_user_data(buffer)); +} + +void DmaBufServerBufferIntegration::wlDisplayHandleGlobal(void *data, ::wl_registry *registry, uint32_t id, const QString &interface, uint32_t version) +{ + Q_UNUSED(version); + if (interface == QStringLiteral("qt_dmabuf_server_buffer")) { + auto *integration = static_cast(data); + integration->QtWayland::qt_dmabuf_server_buffer::init(registry, id, 1); + } +} + +void DmaBufServerBufferIntegration::dmabuf_server_buffer_server_buffer_created(struct ::qt_server_buffer *id + , int32_t name + , int32_t width + , int32_t height + , int32_t stride + , int32_t offset + , int32_t format) +{ + (void) new DmaBufServerBuffer(this, id, name, width, height, stride, offset, format); +} + +} + +QT_END_NAMESPACE diff --git a/src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.h b/src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.h new file mode 100644 index 00000000..f38c2e15 --- /dev/null +++ b/src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.h @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DMABUFSERVERBUFFERINTEGRATION_H +#define DMABUFSERVERBUFFERINTEGRATION_H + +#include +#include "qwayland-qt-dmabuf-server-buffer.h" +#include + +#include "dmabufserverbufferintegration.h" +#include +#include + +#include +#include +#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 + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +class DmaBufServerBufferIntegration; + +class DmaBufServerBuffer : public QWaylandServerBuffer +{ +public: + DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, struct ::qt_server_buffer *id, int32_t fd, + int32_t width, int32_t height, int32_t stride, int32_t offset, int32_t fourcc_format); + ~DmaBufServerBuffer() override; + QOpenGLTexture* toOpenGlTexture() override; +private: + DmaBufServerBufferIntegration *m_integration = nullptr; + EGLImageKHR m_image = EGL_NO_IMAGE_KHR; + QOpenGLTexture *m_texture = nullptr; + struct ::qt_server_buffer *m_server_buffer = nullptr; +}; + +class DmaBufServerBufferIntegration + : public QWaylandServerBufferIntegration + , public QtWayland::qt_dmabuf_server_buffer +{ +public: + void initialize(QWaylandDisplay *display) override; + + QWaylandServerBuffer *serverBuffer(struct qt_server_buffer *buffer) override; + + 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); +protected: + void dmabuf_server_buffer_server_buffer_created(struct ::qt_server_buffer *id, int32_t fd, + int32_t width, int32_t height, int32_t stride, + int32_t offset, int32_t fourcc_format) override; + +private: + static void wlDisplayHandleGlobal(void *data, struct ::wl_registry *registry, uint32_t id, + const QString &interface, uint32_t version); + void initializeEgl(); + + PFNEGLCREATEIMAGEKHRPROC m_egl_create_image = nullptr; + PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image = nullptr; + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture = nullptr; + QWaylandDisplay *m_display = nullptr; + EGLDisplay m_egl_display = EGL_NO_DISPLAY; + bool m_egl_initialized = false; +}; + +EGLImageKHR DmaBufServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + if (!m_egl_initialized) + initializeEgl(); + if (!m_egl_create_image) { + qCWarning(lcQpaWayland) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglCreateImageKHR"; + return EGL_NO_IMAGE_KHR; + } + return m_egl_create_image(m_egl_display, ctx, target, buffer, attrib_list); +} + +EGLBoolean DmaBufServerBufferIntegration::eglDestroyImageKHR(EGLImageKHR image) +{ + if (!m_egl_destroy_image) { + qCWarning(lcQpaWayland) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR"; + return false; + } + return m_egl_destroy_image(m_egl_display, image); +} + +void DmaBufServerBufferIntegration::glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) +{ + if (!m_gl_egl_image_target_texture) { + qCWarning(lcQpaWayland) << "DmaBufServerBufferIntegration: Trying to use unresolved function glEGLImageTargetTexture2DOES"; + return; + } + m_gl_egl_image_target_texture(target, image); +} + +} + +QT_END_NAMESPACE + +#endif diff --git a/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri b/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri new file mode 100644 index 00000000..2df10109 --- /dev/null +++ b/src/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri @@ -0,0 +1,13 @@ +INCLUDEPATH += $$PWD + +QMAKE_USE_PRIVATE += egl wayland-server + +SOURCES += \ + $$PWD/dmabufserverbufferintegration.cpp + + +HEADERS += \ + $$PWD/dmabufserverbufferintegration.h + +CONFIG += wayland-scanner +WAYLANDSERVERSOURCES += $$PWD/../../../extensions/qt-dmabuf-server-buffer.xml diff --git a/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp new file mode 100644 index 00000000..32171f5e --- /dev/null +++ b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dmabufserverbufferintegration.h" + +#include +#include + +#include +#include + +QT_BEGIN_NAMESPACE + +DmaBufServerBuffer::DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format) + : QtWayland::ServerBuffer(qimage.size(),format) + , m_integration(integration) +{ + m_format = format; + + EGLContext eglContext = eglGetCurrentContext(); + + m_texture = new QOpenGLTexture(qimage); + + m_image = m_integration->eglCreateImageKHR(eglContext, EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)(unsigned long)m_texture->textureId(), nullptr); + + qCDebug(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer created egl image" << m_image; + + int err = eglGetError(); + if (err != EGL_SUCCESS || m_image == EGL_NO_IMAGE_KHR) + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer error creating EGL image" << hex << err; + + // TODO: formats with more than one plane + + int num_planes = 1; + + if (!m_integration->eglExportDMABUFImageQueryMESA(m_image, &m_fourcc_format, &num_planes, nullptr)) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer: Failed to query egl image"; + qCDebug(qLcWaylandCompositorHardwareIntegration) << "error" << hex << eglGetError(); + } else { + qCDebug(qLcWaylandCompositorHardwareIntegration) << "num_planes" << num_planes << "fourcc_format" << m_fourcc_format; + if (num_planes != 1) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer: multi-plane formats not supported"; + delete m_texture; + m_texture = nullptr; + m_integration->eglDestroyImageKHR(m_image); + m_image = EGL_NO_IMAGE_KHR; + return; + } + } + + if (!m_integration->eglExportDMABUFImageMESA(m_image, &m_fd, &m_stride, &m_offset)) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer: Failed to export egl image. Error code" << hex << eglGetError(); + } else { + qCDebug(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer exported egl image: fd" << m_fd << "stride" << m_stride << "offset" << m_offset; + m_texture->release(); + } +} + +DmaBufServerBuffer::~DmaBufServerBuffer() +{ + delete m_texture; + + int err; + m_integration->eglDestroyImageKHR(m_image); + if ((err = eglGetError()) != EGL_SUCCESS) + qCWarning(qLcWaylandCompositorHardwareIntegration) << "~DmaBufServerBuffer: eglDestroyImageKHR error" << hex << err; + + err = ::close(m_fd); + if (err) + perror("~DmaBufServerBuffer:: error closing fd"); + +} + +struct ::wl_resource *DmaBufServerBuffer::resourceForClient(struct ::wl_client *client) +{ + auto *bufferResource = resourceMap().value(client); + if (!bufferResource) { + auto integrationResource = m_integration->resourceMap().value(client); + if (!integrationResource) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer::resourceForClient: Trying to get resource for ServerBuffer. But client is not bound to the qt_dmabuf_server_buffer interface"; + return nullptr; + } + struct ::wl_resource *dmabuf_integration_resource = integrationResource->handle; + + Resource *resource = add(client, 1); + m_integration->send_server_buffer_created(dmabuf_integration_resource, resource->handle, m_fd, m_size.width(), m_size.height(), m_stride, m_offset, m_fourcc_format); + return resource->handle; + } + return bufferResource->handle; +} + + +QOpenGLTexture *DmaBufServerBuffer::toOpenGlTexture() +{ + if (!m_texture) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBuffer::toOpenGlTexture: no texture defined"; + } + return m_texture; +} + +bool DmaBufServerBuffer::bufferInUse() +{ + return resourceMap().count() > 0; +} + +DmaBufServerBufferIntegration::DmaBufServerBufferIntegration() +{ +} + +DmaBufServerBufferIntegration::~DmaBufServerBufferIntegration() +{ +} + +void DmaBufServerBufferIntegration::initializeHardware(QWaylandCompositor *compositor) +{ + Q_ASSERT(QGuiApplication::platformNativeInterface()); + + m_egl_display = static_cast(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("egldisplay")); + if (!m_egl_display) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Cannot initialize dmabuf server buffer integration. Missing egl display from platform plugin"; + return; + } + + const char *extensionString = eglQueryString(m_egl_display, EGL_EXTENSIONS); + if (!extensionString || !strstr(extensionString, "EGL_KHR_image")) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize dmabuf server buffer integration. There is no EGL_KHR_image extension."; + return; + } + + m_egl_create_image = reinterpret_cast(eglGetProcAddress("eglCreateImageKHR")); + m_egl_destroy_image = reinterpret_cast(eglGetProcAddress("eglDestroyImageKHR")); + if (!m_egl_create_image || !m_egl_destroy_image) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize dmabuf server buffer integration. Could not resolve eglCreateImageKHR or eglDestroyImageKHR"; + return; + } + + m_gl_egl_image_target_texture_2d = reinterpret_cast(eglGetProcAddress("glEGLImageTargetTexture2DOES")); + if (!m_gl_egl_image_target_texture_2d) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize dmabuf server buffer integration. Could not find glEGLImageTargetTexture2DOES."; + return; + } + + m_egl_export_dmabuf_image_query = reinterpret_cast(eglGetProcAddress("eglExportDMABUFImageQueryMESA")); + if (!m_egl_export_dmabuf_image_query) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize dmabuf server buffer integration. Could not find eglExportDMABUFImageQueryMESA."; + return; + } + + m_egl_export_dmabuf_image = reinterpret_cast(eglGetProcAddress("eglExportDMABUFImageMESA")); + if (!m_egl_export_dmabuf_image) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Failed to initialize dmabuf server buffer integration. Could not find eglExportDMABUFImageMESA."; + return; + } + + QtWaylandServer::qt_dmabuf_server_buffer::init(compositor->display(), 1); +} + +bool DmaBufServerBufferIntegration::supportsFormat(QtWayland::ServerBuffer::Format format) const +{ + // TODO: 8-bit format support + switch (format) { + case QtWayland::ServerBuffer::RGBA32: + return true; + case QtWayland::ServerBuffer::A8: + return false; + default: + return false; + } +} + +QtWayland::ServerBuffer *DmaBufServerBufferIntegration::createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) +{ + return new DmaBufServerBuffer(this, qimage, format); +} + +void DmaBufServerBuffer::server_buffer_release(Resource *resource) +{ + qCDebug(qLcWaylandCompositorHardwareIntegration) << "server_buffer RELEASE resource" << resource->handle << wl_resource_get_id(resource->handle) << "for client" << resource->client(); + wl_resource_destroy(resource->handle); +} + +QT_END_NAMESPACE diff --git a/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h new file mode 100644 index 00000000..70e73713 --- /dev/null +++ b/src/hardwareintegration/compositor/dmabuf-server/dmabufserverbufferintegration.h @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef DMABUFSERVERBUFFERINTEGRATION_H +#define DMABUFSERVERBUFFERINTEGRATION_H + +#include + +#include "qwayland-server-qt-dmabuf-server-buffer.h" + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#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_image_dma_buf_export +typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets); +#endif + +QT_BEGIN_NAMESPACE + +class DmaBufServerBufferIntegration; +class QImage; + +class DmaBufServerBuffer : public QtWayland::ServerBuffer, public QtWaylandServer::qt_server_buffer +{ +public: + DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format); + ~DmaBufServerBuffer() override; + + struct ::wl_resource *resourceForClient(struct ::wl_client *) override; + QOpenGLTexture *toOpenGlTexture() override; + bool bufferInUse() override; + +protected: + void server_buffer_release(Resource *resource) override; + +private: + DmaBufServerBufferIntegration *m_integration = nullptr; + + EGLImageKHR m_image; + + int32_t m_offset; + int32_t m_stride; + QOpenGLTexture *m_texture = nullptr; + int m_fourcc_format; + int m_fd; +}; + +class DmaBufServerBufferIntegration : + public QtWayland::ServerBufferIntegration, + public QtWaylandServer::qt_dmabuf_server_buffer +{ +public: + DmaBufServerBufferIntegration(); + ~DmaBufServerBufferIntegration() override; + + void initializeHardware(QWaylandCompositor *) override; + + bool supportsFormat(QtWayland::ServerBuffer::Format format) const override; + QtWayland::ServerBuffer *createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) 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 EGLBoolean eglExportDMABUFImageQueryMESA(EGLImageKHR image, + int *fourcc, + int *num_planes, + EGLuint64KHR *modifiers); + + inline EGLBoolean eglExportDMABUFImageMESA(EGLImageKHR image, + int *fds, + EGLint *strides, + EGLint *offsets); + + inline void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image); + +private: + EGLDisplay m_egl_display; + + PFNEGLEXPORTDMABUFIMAGEMESAPROC m_egl_export_dmabuf_image = nullptr; + PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC m_egl_export_dmabuf_image_query = nullptr; + + PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture_2d = nullptr; + PFNEGLCREATEIMAGEKHRPROC m_egl_create_image = nullptr; + PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image = nullptr; +}; + +EGLImageKHR DmaBufServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) +{ + if (!m_egl_create_image) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglCreateImageKHR"; + return EGL_NO_IMAGE_KHR; + } + return m_egl_create_image(m_egl_display, ctx, target, buffer, attrib_list); +} + +EGLBoolean DmaBufServerBufferIntegration::eglDestroyImageKHR(EGLImageKHR image) +{ + if (!m_egl_destroy_image) { + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR"; + return false; + } + return m_egl_destroy_image(m_egl_display, image); +} + +EGLBoolean DmaBufServerBufferIntegration::eglExportDMABUFImageQueryMESA(EGLImageKHR image, + int *fourcc, + int *num_planes, + EGLuint64KHR *modifiers) +{ + if (m_egl_export_dmabuf_image_query) + return m_egl_export_dmabuf_image_query(m_egl_display, image, fourcc, num_planes, modifiers); + else + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglExportDMABUFImageQueryMESA"; + return false; +} + +EGLBoolean DmaBufServerBufferIntegration::eglExportDMABUFImageMESA(EGLImageKHR image, + int *fds, + EGLint *strides, + EGLint *offsets) +{ + if (m_egl_export_dmabuf_image) + return m_egl_export_dmabuf_image(m_egl_display, image, fds, strides, offsets); + else + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglExportDMABUFImageMESA"; + return false; +} + +void DmaBufServerBufferIntegration::glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) +{ + if (m_gl_egl_image_target_texture_2d) + return m_gl_egl_image_target_texture_2d(target, image); + else + qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function glEGLImageTargetTexture2DOES"; +} +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/hardwareintegration/client/client.pro b/src/plugins/hardwareintegration/client/client.pro index eab62f8d..82e431ee 100644 --- a/src/plugins/hardwareintegration/client/client.pro +++ b/src/plugins/hardwareintegration/client/client.pro @@ -16,3 +16,5 @@ qtConfig(wayland-libhybris-egl-server-buffer): \ SUBDIRS += libhybris-egl-server qtConfig(wayland-shm-emulation-server-buffer): \ SUBDIRS += shm-emulation-server +qtConfig(wayland-dmabuf-server-buffer): \ + SUBDIRS += dmabuf-server diff --git a/src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.json b/src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.json new file mode 100644 index 00000000..22272a4a --- /dev/null +++ b/src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "dmabuf-server" ] +} diff --git a/src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.pro b/src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.pro new file mode 100644 index 00000000..5925c8b0 --- /dev/null +++ b/src/plugins/hardwareintegration/client/dmabuf-server/dmabuf-server.pro @@ -0,0 +1,15 @@ +# We have a bunch of C code with casts, so we can't have this option +QMAKE_CXXFLAGS_WARN_ON -= -Wcast-qual + +QT += waylandclient-private + +include(../../../../hardwareintegration/client/dmabuf-server/dmabuf-server.pri) + +OTHER_FILES += \ + dmabuf-server.json + +SOURCES += main.cpp + +PLUGIN_TYPE = wayland-graphics-integration-client +PLUGIN_CLASS_NAME = DmaBufServerBufferPlugin +load(qt_plugin) diff --git a/src/plugins/hardwareintegration/client/dmabuf-server/main.cpp b/src/plugins/hardwareintegration/client/dmabuf-server/main.cpp new file mode 100644 index 00000000..d4955d45 --- /dev/null +++ b/src/plugins/hardwareintegration/client/dmabuf-server/main.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "dmabufserverbufferintegration.h" + +QT_BEGIN_NAMESPACE + +namespace QtWaylandClient { + +class DmaBufServerBufferPlugin : public QWaylandServerBufferIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QWaylandServerBufferIntegrationFactoryInterface_iid FILE "dmabuf-server.json") +public: + QWaylandServerBufferIntegration *create(const QString&, const QStringList&) override; +}; + +QWaylandServerBufferIntegration *DmaBufServerBufferPlugin::create(const QString&, const QStringList&) +{ + return new DmaBufServerBufferIntegration(); +} + +} + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/src/plugins/hardwareintegration/client/wayland-egl/main.cpp b/src/plugins/hardwareintegration/client/wayland-egl/main.cpp index 05053ff9..08906355 100644 --- a/src/plugins/hardwareintegration/client/wayland-egl/main.cpp +++ b/src/plugins/hardwareintegration/client/wayland-egl/main.cpp @@ -52,10 +52,8 @@ public: QWaylandClientBufferIntegration *create(const QString&, const QStringList&) override; }; -QWaylandClientBufferIntegration *QWaylandEglClientBufferPlugin::create(const QString& system, const QStringList& paramList) +QWaylandClientBufferIntegration *QWaylandEglClientBufferPlugin::create(const QString&, const QStringList&) { - Q_UNUSED(paramList); - Q_UNUSED(system); return new QWaylandEglClientBufferIntegration(); } diff --git a/src/plugins/hardwareintegration/compositor/compositor.pro b/src/plugins/hardwareintegration/compositor/compositor.pro index 55bf1a7d..cd47b267 100644 --- a/src/plugins/hardwareintegration/compositor/compositor.pro +++ b/src/plugins/hardwareintegration/compositor/compositor.pro @@ -16,5 +16,7 @@ qtConfig(wayland-libhybris-egl-server-buffer): \ SUBDIRS += libhybris-egl-server qtConfig(wayland-shm-emulation-server-buffer): \ SUBDIRS += shm-emulation-server +qtConfig(wayland-dmabuf-server-buffer): \ + SUBDIRS += dmabuf-server SUBDIRS += hardwarelayer diff --git a/src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.json b/src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.json new file mode 100644 index 00000000..22272a4a --- /dev/null +++ b/src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.json @@ -0,0 +1,3 @@ +{ + "Keys": [ "dmabuf-server" ] +} diff --git a/src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pro b/src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pro new file mode 100644 index 00000000..1601a384 --- /dev/null +++ b/src/plugins/hardwareintegration/compositor/dmabuf-server/dmabuf-server.pro @@ -0,0 +1,12 @@ +QT = waylandcompositor waylandcompositor-private core-private gui-private + +OTHER_FILES += dmabuf-server.json + +SOURCES += \ + main.cpp + +include($PWD/../../../../../hardwareintegration/compositor/dmabuf-server/dmabuf-server.pri) + +PLUGIN_TYPE = wayland-graphics-integration-server +PLUGIN_CLASS_NAME = DmaBufServerBufferIntegrationPlugin +load(qt_plugin) diff --git a/src/plugins/hardwareintegration/compositor/dmabuf-server/main.cpp b/src/plugins/hardwareintegration/compositor/dmabuf-server/main.cpp new file mode 100644 index 00000000..0d82e0bb --- /dev/null +++ b/src/plugins/hardwareintegration/compositor/dmabuf-server/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include "dmabufserverbufferintegration.h" + +QT_BEGIN_NAMESPACE + +class DmaBufServerBufferIntegrationPlugin : public QtWayland::ServerBufferIntegrationPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QtWaylandServerBufferIntegrationFactoryInterface_iid FILE "dmabuf-server.json") +public: + QtWayland::ServerBufferIntegration *create(const QString&, const QStringList&) override; +}; + +QtWayland::ServerBufferIntegration *DmaBufServerBufferIntegrationPlugin::create(const QString& system, const QStringList& paramList) +{ + Q_UNUSED(paramList); + Q_UNUSED(system); + return new DmaBufServerBufferIntegration(); +} + +QT_END_NAMESPACE + +#include "main.moc" -- cgit v1.2.1