1 | // Copyright (C) 2019 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 VULKANSERVERBUFFERINTEGRATION_H |
5 | #define VULKANSERVERBUFFERINTEGRATION_H |
6 | |
7 | #include <QtWaylandClient/private/qwayland-wayland.h> |
8 | #include "qwayland-qt-vulkan-server-buffer-unstable-v1.h" |
9 | #include <QtWaylandClient/private/qwaylandserverbufferintegration_p.h> |
10 | |
11 | #include "vulkanserverbufferintegration.h" |
12 | #include <QtWaylandClient/private/qwaylanddisplay_p.h> |
13 | #include <QtCore/QTextStream> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | namespace QtWaylandClient { |
18 | |
19 | class VulkanServerBufferIntegration; |
20 | |
21 | class VulkanServerBuffer : public QWaylandServerBuffer |
22 | { |
23 | public: |
24 | VulkanServerBuffer(VulkanServerBufferIntegration *integration, struct ::qt_server_buffer *id, int32_t fd, uint32_t width, uint32_t height, uint32_t memory_size, uint32_t format); |
25 | ~VulkanServerBuffer() override; |
26 | QOpenGLTexture* toOpenGlTexture() override; |
27 | |
28 | private: |
29 | void import(); |
30 | |
31 | VulkanServerBufferIntegration *m_integration = nullptr; |
32 | struct ::qt_server_buffer *m_server_buffer = nullptr; |
33 | QOpenGLTexture *m_texture = nullptr; |
34 | int m_fd = -1; |
35 | uint m_memorySize = 0; |
36 | uint m_internalFormat = 0; |
37 | GLuint m_memoryObject = 0; |
38 | }; |
39 | |
40 | class VulkanServerBufferIntegration |
41 | : public QWaylandServerBufferIntegration |
42 | , public QtWayland::zqt_vulkan_server_buffer_v1 |
43 | { |
44 | public: |
45 | void initialize(QWaylandDisplay *display) override; |
46 | |
47 | QWaylandServerBuffer *serverBuffer(struct qt_server_buffer *buffer) override; |
48 | |
49 | void deleteGLTextureWhenPossible(QOpenGLTexture *texture) { orphanedTextures << texture; } |
50 | void deleteOrphanedTextures(); |
51 | |
52 | protected: |
53 | void zqt_vulkan_server_buffer_v1_server_buffer_created(qt_server_buffer *id, int32_t fd, uint32_t width, uint32_t height, uint32_t memory_size, uint32_t format) override; |
54 | |
55 | private: |
56 | static void wlDisplayHandleGlobal(void *data, struct ::wl_registry *registry, uint32_t id, |
57 | const QString &interface, uint32_t version); |
58 | QWaylandDisplay *m_display = nullptr; |
59 | QList<QOpenGLTexture *> orphanedTextures; |
60 | }; |
61 | |
62 | } |
63 | |
64 | QT_END_NAMESPACE |
65 | |
66 | #endif |
67 | |