1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QWLTEXTURESHARINGEXTENSION_P_H
5#define QWLTEXTURESHARINGEXTENSION_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "wayland-util.h"
19
20#include <QtCore/QMap>
21#include <QtCore/QHash>
22
23#include <QtWaylandCompositor/QWaylandCompositorExtensionTemplate>
24#include <QtWaylandCompositor/QWaylandQuickExtension>
25#include <QtWaylandCompositor/QWaylandCompositor>
26
27#include <QQuickImageProvider>
28
29#include <QtWaylandCompositor/private/qwaylandcompositor_p.h>
30#include <QtWaylandCompositor/private/qwlserverbufferintegration_p.h>
31
32#include <QtWaylandCompositor/private/qwayland-server-qt-texture-sharing-unstable-v1.h>
33
34QT_BEGIN_NAMESPACE
35
36namespace QtWayland
37{
38 class ServerBufferIntegration;
39}
40
41class QWaylandTextureSharingExtension;
42class SharedTextureImageResponse;
43
44class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSharedTextureProvider : public QQuickAsyncImageProvider
45{
46public:
47 QWaylandSharedTextureProvider();
48 ~QWaylandSharedTextureProvider() override;
49
50 QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
51 void setExtensionReady(QWaylandTextureSharingExtension *extension);
52
53private:
54 QList<SharedTextureImageResponse*> m_pendingResponses;
55};
56
57class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandTextureSharingExtension
58 : public QWaylandCompositorExtensionTemplate<QWaylandTextureSharingExtension>
59 , public QtWaylandServer::zqt_texture_sharing_v1
60{
61 Q_OBJECT
62 Q_PROPERTY(QString imageSearchPath WRITE setImageSearchPath)
63public:
64 QWaylandTextureSharingExtension();
65 QWaylandTextureSharingExtension(QWaylandCompositor *compositor);
66 ~QWaylandTextureSharingExtension() override;
67
68 void initialize() override;
69
70 void setImageSearchPath(const QString &path);
71
72 static QWaylandTextureSharingExtension *self() { return s_self; }
73
74public slots:
75 void requestBuffer(const QString &key);
76
77signals:
78 void bufferResult(const QString &key, QtWayland::ServerBuffer *buffer);
79
80protected slots:
81 void cleanupBuffers();
82
83protected:
84 void zqt_texture_sharing_v1_request_image(Resource *resource, const QString &key) override;
85 void zqt_texture_sharing_v1_abandon_image(Resource *resource, const QString &key) override;
86 void zqt_texture_sharing_v1_destroy_resource(Resource *resource) override;
87
88 virtual bool customPixelData(const QString &key, QByteArray *data, QSize *size, uint *glInternalFormat)
89 {
90 Q_UNUSED(key);
91 Q_UNUSED(data);
92 Q_UNUSED(size);
93 Q_UNUSED(glInternalFormat);
94 return false;
95 }
96
97private:
98 QtWayland::ServerBuffer *getBuffer(const QString &key);
99 bool initServerBufferIntegration();
100 QtWayland::ServerBuffer *getCompressedBuffer(const QString &key);
101 QString getExistingFilePath(const QString &key) const;
102 void dumpBufferInfo();
103
104 struct BufferInfo
105 {
106 BufferInfo(QtWayland::ServerBuffer *b = nullptr) : buffer(b) {}
107 QtWayland::ServerBuffer *buffer = nullptr;
108 bool usedLocally = false;
109 };
110
111 QStringList m_image_dirs;
112 QStringList m_image_suffixes;
113 QHash<QString, BufferInfo> m_server_buffers;
114 QtWayland::ServerBufferIntegration *m_server_buffer_integration = nullptr;
115
116 static QWaylandTextureSharingExtension *s_self;
117};
118
119Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandTextureSharingExtension)
120
121QT_END_NAMESPACE
122
123#endif // QWLTEXTURESHARINGEXTENSION_P_H
124

source code of qtwayland/src/compositor/extensions/qwltexturesharingextension_p.h