1 | // Copyright (C) 2018 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef LINUXDMABUFCLIENTBUFFERINTEGRATION_H |
5 | #define LINUXDMABUFCLIENTBUFFERINTEGRATION_H |
6 | |
7 | #include "linuxdmabuf.h" |
8 | |
9 | #include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> |
10 | #include <QtWaylandCompositor/private/qwlclientbuffer_p.h> |
11 | #include <QtWaylandCompositor/private/qwayland-server-wayland.h> |
12 | #include <QtCore/QMutex> |
13 | |
14 | #include <drm_fourcc.h> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYWAYLANDBUFFERWL_compat) (EGLDisplay dpy, struct wl_resource *buffer, EGLint attribute, EGLint *value); |
19 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFFORMATSEXTPROC) (EGLDisplay dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats); |
20 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFMODIFIERSEXTPROC) (EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, EGLBoolean *external_only, EGLint *num_modifiers); |
21 | |
22 | class LinuxDmabufClientBufferIntegrationPrivate; |
23 | class LinuxDmabufParams; |
24 | class LinuxDmabufClientBuffer; |
25 | |
26 | // buffer conversion definitions to import YUV buffers |
27 | struct YuvPlaneConversion { |
28 | EGLint format = DRM_FORMAT_YUYV; |
29 | EGLint widthDivisor = 1; |
30 | EGLint heightDivisor = 1; |
31 | EGLint planeIndex = 0; |
32 | }; |
33 | struct YuvFormatConversion { |
34 | uint32_t inputPlanes = 1; |
35 | uint32_t outputPlanes = 1; |
36 | struct YuvPlaneConversion plane[LinuxDmabufWlBuffer::MaxDmabufPlanes]; |
37 | }; |
38 | |
39 | class LinuxDmabufClientBufferIntegration : public QtWayland::ClientBufferIntegration |
40 | { |
41 | public: |
42 | LinuxDmabufClientBufferIntegration(); |
43 | ~LinuxDmabufClientBufferIntegration() override; |
44 | |
45 | void initializeHardware(struct ::wl_display *display) override; |
46 | QtWayland::ClientBuffer *createBufferFor(wl_resource *resource) override; |
47 | bool importBuffer(wl_resource *resource, LinuxDmabufWlBuffer *linuxDmabufBuffer); |
48 | void removeBuffer(wl_resource *resource); |
49 | void deleteImage(EGLImageKHR image); |
50 | PFNGLEGLIMAGETARGETTEXTURE2DOESPROC gl_egl_image_target_texture_2d = nullptr; |
51 | |
52 | private: |
53 | Q_DISABLE_COPY(LinuxDmabufClientBufferIntegration) |
54 | |
55 | PFNEGLBINDWAYLANDDISPLAYWL egl_bind_wayland_display = nullptr; |
56 | PFNEGLUNBINDWAYLANDDISPLAYWL egl_unbind_wayland_display = nullptr; |
57 | PFNEGLCREATEIMAGEKHRPROC egl_create_image = nullptr; |
58 | PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image = nullptr; |
59 | PFNEGLQUERYDMABUFMODIFIERSEXTPROC egl_query_dmabuf_modifiers_ext = nullptr; |
60 | PFNEGLQUERYDMABUFFORMATSEXTPROC egl_query_dmabuf_formats_ext = nullptr; |
61 | |
62 | bool initSimpleTexture(LinuxDmabufWlBuffer *dmabufBuffer); |
63 | bool initYuvTexture(LinuxDmabufWlBuffer *dmabufBuffer); |
64 | QList<uint32_t> supportedDrmFormats(); |
65 | QList<uint64_t> supportedDrmModifiers(uint32_t format); |
66 | |
67 | EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; |
68 | ::wl_display *m_wlDisplay = nullptr; |
69 | bool m_displayBound = false; |
70 | |
71 | QHash<EGLint, YuvFormatConversion> m_yuvFormats; |
72 | bool m_supportsDmabufModifiers = false; |
73 | QHash<struct ::wl_resource *, LinuxDmabufWlBuffer *> m_importedBuffers; |
74 | QScopedPointer<LinuxDmabuf> m_linuxDmabuf; |
75 | }; |
76 | |
77 | class LinuxDmabufClientBuffer : public QtWayland::ClientBuffer |
78 | { |
79 | public: |
80 | ~LinuxDmabufClientBuffer() override; |
81 | |
82 | QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const override; |
83 | QSize size() const override; |
84 | QWaylandSurface::Origin origin() const override; |
85 | QOpenGLTexture *toOpenGlTexture(int plane) override; |
86 | |
87 | protected: |
88 | void setDestroyed() override; |
89 | |
90 | private: |
91 | friend class LinuxDmabufClientBufferIntegration; |
92 | friend class LinuxDmabufClientBufferIntegrationPrivate; |
93 | |
94 | LinuxDmabufClientBuffer(LinuxDmabufClientBufferIntegration* integration, wl_resource *bufferResource, LinuxDmabufWlBuffer *dmabufBuffer); |
95 | |
96 | LinuxDmabufWlBuffer *d = nullptr; |
97 | LinuxDmabufClientBufferIntegration *m_integration = nullptr; |
98 | }; |
99 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #endif // LINUXDMABUFCLIENTBUFFERINTEGRATION_H |
103 | |