1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWaylandCompositor module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QWLTEXTURESHARINGEXTENSION_P_H
41#define QWLTEXTURESHARINGEXTENSION_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "wayland-util.h"
55
56#include <QtCore/QMap>
57#include <QtCore/QHash>
58
59#include <QtWaylandCompositor/QWaylandCompositorExtensionTemplate>
60#include <QtWaylandCompositor/QWaylandQuickExtension>
61#include <QtWaylandCompositor/QWaylandCompositor>
62
63#include <QQuickImageProvider>
64
65#include <QtWaylandCompositor/private/qwaylandcompositor_p.h>
66#include <QtWaylandCompositor/private/qwlserverbufferintegration_p.h>
67
68#include <QtWaylandCompositor/private/qwayland-server-qt-texture-sharing-unstable-v1.h>
69
70QT_BEGIN_NAMESPACE
71
72namespace QtWayland
73{
74 class ServerBufferIntegration;
75}
76
77class QWaylandTextureSharingExtension;
78class SharedTextureImageResponse;
79
80class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSharedTextureProvider : public QQuickAsyncImageProvider
81{
82public:
83 QWaylandSharedTextureProvider();
84 ~QWaylandSharedTextureProvider() override;
85
86 QQuickImageResponse *requestImageResponse(const QString &id, const QSize &requestedSize) override;
87 void setExtensionReady(QWaylandTextureSharingExtension *extension);
88
89private:
90 QVector<SharedTextureImageResponse*> m_pendingResponses;
91};
92
93class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandTextureSharingExtension
94 : public QWaylandCompositorExtensionTemplate<QWaylandTextureSharingExtension>
95 , public QtWaylandServer::zqt_texture_sharing_v1
96{
97 Q_OBJECT
98 Q_PROPERTY(QString imageSearchPath WRITE setImageSearchPath)
99public:
100 QWaylandTextureSharingExtension();
101 QWaylandTextureSharingExtension(QWaylandCompositor *compositor);
102 ~QWaylandTextureSharingExtension() override;
103
104 void initialize() override;
105
106 void setImageSearchPath(const QString &path);
107
108 static QWaylandTextureSharingExtension *self() { return s_self; }
109
110public slots:
111 void requestBuffer(const QString &key);
112
113signals:
114 void bufferResult(const QString &key, QtWayland::ServerBuffer *buffer);
115
116protected slots:
117 void cleanupBuffers();
118
119protected:
120 void zqt_texture_sharing_v1_request_image(Resource *resource, const QString &key) override;
121 void zqt_texture_sharing_v1_abandon_image(Resource *resource, const QString &key) override;
122 void zqt_texture_sharing_v1_destroy_resource(Resource *resource) override;
123
124 virtual bool customPixelData(const QString &key, QByteArray *data, QSize *size, uint *glInternalFormat)
125 {
126 Q_UNUSED(key);
127 Q_UNUSED(data);
128 Q_UNUSED(size);
129 Q_UNUSED(glInternalFormat);
130 return false;
131 }
132
133private:
134 QtWayland::ServerBuffer *getBuffer(const QString &key);
135 bool initServerBufferIntegration();
136 QtWayland::ServerBuffer *getCompressedBuffer(const QString &key);
137 QString getExistingFilePath(const QString &key) const;
138 void dumpBufferInfo();
139
140 struct BufferInfo
141 {
142 BufferInfo(QtWayland::ServerBuffer *b = nullptr) : buffer(b) {}
143 QtWayland::ServerBuffer *buffer = nullptr;
144 bool usedLocally = false;
145 };
146
147 QStringList m_image_dirs;
148 QStringList m_image_suffixes;
149 QHash<QString, BufferInfo> m_server_buffers;
150 QtWayland::ServerBufferIntegration *m_server_buffer_integration = nullptr;
151
152 static QWaylandTextureSharingExtension *s_self;
153};
154
155Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandTextureSharingExtension)
156
157QT_END_NAMESPACE
158
159#endif // QWLTEXTURESHARINGEXTENSION_P_H
160