1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef VULKANSERVERBUFFERINTEGRATION_H
5#define VULKANSERVERBUFFERINTEGRATION_H
6
7#include <QtWaylandCompositor/private/qwlserverbufferintegration_p.h>
8
9#include "qwayland-server-qt-vulkan-server-buffer-unstable-v1.h"
10
11#include <QtGui/QImage>
12#include <QtGui/QWindow>
13#include <QtGui/qpa/qplatformnativeinterface.h>
14#include <QtGui/QGuiApplication>
15
16#include <QtWaylandCompositor/qwaylandcompositor.h>
17#include <QtWaylandCompositor/private/qwayland-server-server-buffer-extension.h>
18
19QT_BEGIN_NAMESPACE
20
21class VulkanServerBufferIntegration;
22class VulkanWrapper;
23struct VulkanImageWrapper;
24
25class VulkanServerBuffer : public QtWayland::ServerBuffer, public QtWaylandServer::qt_server_buffer
26{
27public:
28 VulkanServerBuffer(VulkanServerBufferIntegration *integration, const QImage &qimage, QtWayland::ServerBuffer::Format format);
29 VulkanServerBuffer(VulkanServerBufferIntegration *integration, VulkanImageWrapper *vImage, uint glInternalFormat, const QSize &size);
30 ~VulkanServerBuffer() override;
31
32 struct ::wl_resource *resourceForClient(struct ::wl_client *) override;
33 bool bufferInUse() override;
34 QOpenGLTexture *toOpenGlTexture() override;
35 void releaseOpenGlTexture() override;
36
37protected:
38 void server_buffer_release(Resource *resource) override;
39
40private:
41 VulkanServerBufferIntegration *m_integration = nullptr;
42
43 int m_width;
44 int m_height;
45 int m_memorySize;
46 int m_fd = -1;
47 VulkanImageWrapper *m_vImage = nullptr;
48 QOpenGLTexture *m_texture = nullptr;
49 uint m_glInternalFormat;
50 GLuint m_memoryObject;
51};
52
53class VulkanServerBufferIntegration :
54 public QtWayland::ServerBufferIntegration,
55 public QtWaylandServer::zqt_vulkan_server_buffer_v1
56{
57public:
58 VulkanServerBufferIntegration();
59 ~VulkanServerBufferIntegration() override;
60
61 VulkanWrapper *vulkanWrapper() const { return m_vulkanWrapper; }
62
63 bool initializeHardware(QWaylandCompositor *) override;
64
65 bool supportsFormat(QtWayland::ServerBuffer::Format format) const override;
66 QtWayland::ServerBuffer *createServerBufferFromImage(const QImage &qimage, QtWayland::ServerBuffer::Format format) override;
67 QtWayland::ServerBuffer *createServerBufferFromData(QByteArrayView view, const QSize &size,
68 uint glInternalFormat) override;
69
70private:
71 VulkanWrapper *m_vulkanWrapper = nullptr;
72};
73
74QT_END_NAMESPACE
75
76#endif
77

source code of qtwayland/src/hardwareintegration/compositor/vulkan-server/vulkanserverbufferintegration.h