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