Debian Codegraph @

src/hardwareintegration/client/dmabuf-server/dmabufserverbufferintegration.h

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef DMABUFSERVERBUFFERINTEGRATION_H
41 #define DMABUFSERVERBUFFERINTEGRATION_H
42
43 #include <QtWaylandClient/private/qwayland-wayland.h>
44 #include "qwayland-qt-dmabuf-server-buffer.h"
45 #include <QtWaylandClient/private/qwaylandserverbufferintegration_p.h>
46
47 #include "dmabufserverbufferintegration.h"
48 #include <QtWaylandClient/private/qwaylanddisplay_p.h>
49 #include <QtCore/QTextStream>
50
51 #include <EGL/egl.h>
52 #include <EGL/eglext.h>
53 #ifndef EGL_KHR_image
54 typedef void *EGLImageKHR;
55 typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
56 typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
57 #endif
58
59 #ifndef GL_OES_EGL_image
60 typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
61 #endif
62
63 QT_BEGIN_NAMESPACE
64
65 namespace QtWaylandClient {
66
67 class DmaBufServerBufferIntegration;
68
69 class DmaBufServerBuffer : public QWaylandServerBuffer
70 {
71 public:
72 DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, struct ::qt_server_buffer *id, int32_t fd,
73 int32_t width, int32_t height, int32_t stride, int32_t offset, int32_t fourcc_format);
74 ~DmaBufServerBuffer() override;
75 QOpenGLTexture* toOpenGlTexture() override;
76 private:
77 DmaBufServerBufferIntegration *m_integration = nullptr;
78 EGLImageKHR m_image = EGL_NO_IMAGE_KHR;
79 QOpenGLTexture *m_texture = nullptr;
80 struct ::qt_server_buffer *m_server_buffer = nullptr;
81 };
82
83 class DmaBufServerBufferIntegration
84 : public QWaylandServerBufferIntegration
85 , public QtWayland::qt_dmabuf_server_buffer
86 {
87 public:
88 void initialize(QWaylandDisplay *display) override;
89
90 QWaylandServerBuffer *serverBuffer(struct qt_server_buffer *buffer) override;
91
92 inline EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
93 inline EGLBoolean eglDestroyImageKHR(EGLImageKHR image);
94 inline void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
95 protected:
96 void dmabuf_server_buffer_server_buffer_created(struct ::qt_server_buffer *id, int32_t fd,
97 int32_t width, int32_t height, int32_t stride,
98 int32_t offset, int32_t fourcc_format) override;
99
100 private:
101 static void wlDisplayHandleGlobal(void *data, struct ::wl_registry *registry, uint32_t id,
102 const QString &interface, uint32_t version);
103 void initializeEgl();
104
105 PFNEGLCREATEIMAGEKHRPROC m_egl_create_image = nullptr;
106 PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image = nullptr;
107 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture = nullptr;
108 QWaylandDisplay *m_display = nullptr;
109 EGLDisplay m_egl_display = EGL_NO_DISPLAY;
110 bool m_egl_initialized = false;
111 };
112
113 EGLImageKHR DmaBufServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
114 {
115 if (!m_egl_initialized)
116 initializeEgl();
117 if (!m_egl_create_image) {
118 qCWarning(lcQpaWayland) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglCreateImageKHR";
119 return EGL_NO_IMAGE_KHR;
120 }
121 return m_egl_create_image(m_egl_display, ctx, target, buffer, attrib_list);
122 }
123
124 EGLBoolean DmaBufServerBufferIntegration::eglDestroyImageKHR(EGLImageKHR image)
125 {
126 if (!m_egl_destroy_image) {
127 qCWarning(lcQpaWayland) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR";
128 return false;
129 }
130 return m_egl_destroy_image(m_egl_display, image);
131 }
132
133 void DmaBufServerBufferIntegration::glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
134 {
135 if (!m_gl_egl_image_target_texture) {
136 qCWarning(lcQpaWayland) << "DmaBufServerBufferIntegration: Trying to use unresolved function glEGLImageTargetTexture2DOES";
137 return;
138 }
139 m_gl_egl_image_target_texture(target, image);
140 }
141
142 }
143
144 QT_END_NAMESPACE
145
146 #endif