Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
dmabufserverbufferintegration.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:critical reason:network-protocol
4
5#ifndef DMABUFSERVERBUFFERINTEGRATION_H
6#define DMABUFSERVERBUFFERINTEGRATION_H
7
8#include <QtCore/QVariant>
9#include <QtWaylandCompositor/private/qwlserverbufferintegration_p.h>
10
11#include "qwayland-server-qt-dmabuf-server-buffer.h"
12
13#include <QtGui/QWindow>
14#include <QtGui/qpa/qplatformnativeinterface.h>
15#include <QtGui/QGuiApplication>
16
17#include <QtWaylandCompositor/qwaylandcompositor.h>
18#include <QtWaylandCompositor/private/qwayland-server-server-buffer-extension.h>
19
20#include <QtCore/QDebug>
21#include <EGL/egl.h>
22#include <EGL/eglext.h>
23
24#ifndef EGL_KHR_image
25typedef void *EGLImageKHR;
26typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
27typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image);
28#endif
29
30#ifndef GL_OES_EGL_image
31typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
32#endif
33
34#ifndef EGL_MESA_image_dma_buf_export
35typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers);
36typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDMABUFIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets);
37#endif
38
39QT_BEGIN_NAMESPACE
40
41class DmaBufServerBufferIntegration;
42class QImage;
43
45{
46public:
47 DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format);
49
50 struct ::wl_resource *resourceForClient(struct ::wl_client *) override;
52 bool bufferInUse() override;
53
54protected:
55 void server_buffer_release(Resource *resource) override;
56
57private:
58 DmaBufServerBufferIntegration *m_integration = nullptr;
59
60 EGLImageKHR m_image;
61
62 int32_t m_offset;
63 int32_t m_stride;
64 QOpenGLTexture *m_texture = nullptr;
65 int m_fourcc_format;
66 int m_fd;
67};
68
72{
73public:
76
77 bool initializeHardware(QWaylandCompositor *) override;
78
79 bool supportsFormat(QtWayland::ServerBuffer::Format format) const override;
80 QtWayland::ServerBuffer *createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override;
81
82 EGLDisplay display() const { return m_egl_display; }
83
84 inline EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
85 inline EGLBoolean eglDestroyImageKHR(EGLImageKHR image);
86
87 inline EGLBoolean eglExportDMABUFImageQueryMESA(EGLImageKHR image,
88 int *fourcc,
89 int *num_planes,
90 EGLuint64KHR *modifiers);
91
92 inline EGLBoolean eglExportDMABUFImageMESA(EGLImageKHR image,
93 int *fds,
94 EGLint *strides,
95 EGLint *offsets);
96
97 inline void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
98
99private:
100 EGLDisplay m_egl_display;
101
102 PFNEGLEXPORTDMABUFIMAGEMESAPROC m_egl_export_dmabuf_image = nullptr;
103 PFNEGLEXPORTDMABUFIMAGEQUERYMESAPROC m_egl_export_dmabuf_image_query = nullptr;
104
105 PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture_2d = nullptr;
106 PFNEGLCREATEIMAGEKHRPROC m_egl_create_image = nullptr;
107 PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image = nullptr;
108};
109
110EGLImageKHR DmaBufServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
111{
112 if (!m_egl_create_image) {
113 qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglCreateImageKHR";
114 return EGL_NO_IMAGE_KHR;
115 }
116 return m_egl_create_image(m_egl_display, ctx, target, buffer, attrib_list);
117}
118
120{
121 if (!m_egl_destroy_image) {
122 qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR";
123 return false;
124 }
125 return m_egl_destroy_image(m_egl_display, image);
126}
127
129 int *fourcc,
130 int *num_planes,
131 EGLuint64KHR *modifiers)
132{
133 if (m_egl_export_dmabuf_image_query)
134 return m_egl_export_dmabuf_image_query(m_egl_display, image, fourcc, num_planes, modifiers);
135 else
136 qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglExportDMABUFImageQueryMESA";
137 return false;
138}
139
141 int *fds,
142 EGLint *strides,
143 EGLint *offsets)
144{
145 if (m_egl_export_dmabuf_image)
146 return m_egl_export_dmabuf_image(m_egl_display, image, fds, strides, offsets);
147 else
148 qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function eglExportDMABUFImageMESA";
149 return false;
150}
151
152void DmaBufServerBufferIntegration::glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
153{
154 if (m_gl_egl_image_target_texture_2d)
155 return m_gl_egl_image_target_texture_2d(target, image);
156 else
157 qCWarning(qLcWaylandCompositorHardwareIntegration) << "DmaBufServerBufferIntegration: Trying to use unresolved function glEGLImageTargetTexture2DOES";
158}
159QT_END_NAMESPACE
160
161#endif
EGLBoolean eglExportDMABUFImageQueryMESA(EGLImageKHR image, int *fourcc, int *num_planes, EGLuint64KHR *modifiers)
bool initializeHardware(QWaylandCompositor *) override
bool supportsFormat(QtWayland::ServerBuffer::Format format) const override
void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list)
EGLBoolean eglExportDMABUFImageMESA(EGLImageKHR image, int *fds, EGLint *strides, EGLint *offsets)
EGLBoolean eglDestroyImageKHR(EGLImageKHR image)
QtWayland::ServerBuffer * createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override
QOpenGLTexture * toOpenGlTexture() override
DmaBufServerBuffer(DmaBufServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format)
void server_buffer_release(Resource *resource) override
typedef void(GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)(GLenum target