1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef DRMEGLSERVERBUFFERINTEGRATION_H |
5 | #define DRMEGLSERVERBUFFERINTEGRATION_H |
6 | |
7 | #include <QtWaylandClient/private/qwayland-wayland.h> |
8 | #include <QtCore/QVariant> |
9 | #include "qwayland-drm-egl-server-buffer.h" |
10 | #include <QtWaylandClient/private/qwaylandserverbufferintegration_p.h> |
11 | |
12 | #include "drmeglserverbufferintegration.h" |
13 | #include <QtWaylandClient/private/qwaylanddisplay_p.h> |
14 | #include <QtCore/QTextStream> |
15 | |
16 | #include <EGL/egl.h> |
17 | #include <EGL/eglext.h> |
18 | #ifndef EGL_KHR_image |
19 | typedef void *EGLImageKHR; |
20 | typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEIMAGEKHRPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); |
21 | typedef EGLBoolean (EGLAPIENTRYP PFNEGLDESTROYIMAGEKHRPROC) (EGLDisplay dpy, EGLImageKHR image); |
22 | #endif |
23 | |
24 | #ifndef GL_OES_EGL_image |
25 | typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image); |
26 | #endif |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | namespace QtWaylandClient { |
31 | |
32 | class DrmEglServerBufferIntegration; |
33 | |
34 | class DrmServerBuffer : public QWaylandServerBuffer |
35 | { |
36 | public: |
37 | DrmServerBuffer(DrmEglServerBufferIntegration *integration, int32_t name, int32_t width, int32_t height, int32_t stride, int32_t format); |
38 | ~DrmServerBuffer() override; |
39 | QOpenGLTexture* toOpenGlTexture() override; |
40 | private: |
41 | DrmEglServerBufferIntegration *m_integration = nullptr; |
42 | EGLImageKHR m_image; |
43 | QOpenGLTexture *m_texture = nullptr; |
44 | }; |
45 | |
46 | class DrmEglServerBufferIntegration |
47 | : public QWaylandServerBufferIntegration |
48 | , public QtWayland::qt_drm_egl_server_buffer |
49 | { |
50 | public: |
51 | void initialize(QWaylandDisplay *display) override; |
52 | |
53 | QWaylandServerBuffer *serverBuffer(struct qt_server_buffer *buffer) override; |
54 | |
55 | inline EGLImageKHR eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list); |
56 | inline EGLBoolean eglDestroyImageKHR (EGLImageKHR image); |
57 | inline void glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); |
58 | protected: |
59 | void drm_egl_server_buffer_server_buffer_created(struct ::qt_server_buffer *id, int32_t name, int32_t width, int32_t height, int32_t stride, int32_t format) override; |
60 | private: |
61 | static void wlDisplayHandleGlobal(void *data, struct ::wl_registry *registry, uint32_t id, |
62 | const QString &interface, uint32_t version); |
63 | void initializeEgl(); |
64 | |
65 | PFNEGLCREATEIMAGEKHRPROC m_egl_create_image; |
66 | PFNEGLDESTROYIMAGEKHRPROC m_egl_destroy_image; |
67 | PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_gl_egl_image_target_texture; |
68 | QWaylandDisplay *m_display = nullptr; |
69 | EGLDisplay m_egl_display = EGL_NO_DISPLAY; |
70 | bool m_egl_initialized = false; |
71 | }; |
72 | |
73 | EGLImageKHR DrmEglServerBufferIntegration::eglCreateImageKHR(EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) |
74 | { |
75 | if (!m_egl_initialized) |
76 | initializeEgl(); |
77 | if (!m_egl_create_image) { |
78 | qWarning(msg: "DrmEglServerBufferIntegration: Trying to used unresolved function eglCreateImageKHR" ); |
79 | return EGL_NO_IMAGE_KHR; |
80 | } |
81 | return m_egl_create_image(m_egl_display, ctx, target, buffer,attrib_list); |
82 | } |
83 | |
84 | EGLBoolean DrmEglServerBufferIntegration::eglDestroyImageKHR (EGLImageKHR image) |
85 | { |
86 | if (!m_egl_destroy_image) { |
87 | qWarning(msg: "DrmEglServerBufferIntegration: Trying to use unresolved function eglDestroyImageKHR" ); |
88 | return false; |
89 | } |
90 | return m_egl_destroy_image(m_egl_display, image); |
91 | } |
92 | |
93 | void DrmEglServerBufferIntegration::glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) |
94 | { |
95 | if (!m_gl_egl_image_target_texture) { |
96 | qWarning(msg: "DrmEglServerBufferIntegration: Trying to use unresolved function glEGLImageTargetRenderbufferStorageOES" ); |
97 | return; |
98 | } |
99 | m_gl_egl_image_target_texture(target,image); |
100 | } |
101 | |
102 | } |
103 | |
104 | QT_END_NAMESPACE |
105 | |
106 | #endif |
107 | |