| 1 | // Copyright (C) 2019 The Qt Company Ltd. | 
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 | |
| 4 | #ifndef QWLCLIENTBUFFER_P_H | 
| 5 | #define QWLCLIENTBUFFER_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 <QtCore/QRect> | 
| 19 | #include <QtGui/qopengl.h> | 
| 20 | #include <QImage> | 
| 21 | #include <QAtomicInt> | 
| 22 | #include <QScopedPointer> | 
| 23 | |
| 24 | #include <QtWaylandCompositor/QWaylandSurface> | 
| 25 | #include <QtWaylandCompositor/QWaylandBufferRef> | 
| 26 | #include <QtCore/private/qglobal_p.h> | 
| 27 | |
| 28 | #include <wayland-server-core.h> | 
| 29 | |
| 30 | QT_BEGIN_NAMESPACE | 
| 31 | |
| 32 | class QWaylandClientBufferIntegration; | 
| 33 | class QWaylandBufferRef; | 
| 34 | class QWaylandCompositor; | 
| 35 | class QOpenGLTexture; | 
| 36 | |
| 37 | namespace QtWayland { | 
| 38 | |
| 39 | struct surface_buffer_destroy_listener | 
| 40 | { | 
| 41 | struct wl_listener listener; | 
| 42 | class ClientBuffer *surfaceBuffer = nullptr; | 
| 43 | }; | 
| 44 | |
| 45 | class Q_WAYLANDCOMPOSITOR_EXPORT ClientBuffer | 
| 46 | { | 
| 47 | public: | 
| 48 | ClientBuffer(struct ::wl_resource *bufferResource); | 
| 49 | |
| 50 | virtual ~ClientBuffer(); | 
| 51 | |
| 52 | virtual QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const; | 
| 53 | virtual QSize size() const = 0; | 
| 54 | virtual QWaylandSurface::Origin origin() const = 0; | 
| 55 | |
| 56 | virtual quintptr lockNativeBuffer() { return 0; } | 
| 57 | virtual void unlockNativeBuffer(quintptr native_buffer) const { Q_UNUSED(native_buffer); } | 
| 58 | |
| 59 | virtual QImage image() const { return QImage(); } | 
| 60 | |
| 61 | inline bool isCommitted() const { return m_committed; } | 
| 62 | virtual void setCommitted(QRegion &damage); | 
| 63 | bool isDestroyed() { return m_destroyed; } | 
| 64 | |
| 65 | virtual bool isProtected() { return false; } | 
| 66 | |
| 67 | inline struct ::wl_resource *waylandBufferHandle() const { return m_buffer; } | 
| 68 | |
| 69 | bool isSharedMemory() const { return wl_shm_buffer_get(resource: m_buffer); } | 
| 70 | |
| 71 | #if QT_CONFIG(opengl) | 
| 72 | virtual QOpenGLTexture *toOpenGlTexture(int plane = 0) = 0; | 
| 73 | #endif | 
| 74 | |
| 75 | static bool hasContent(ClientBuffer *buffer) { return buffer && buffer->waylandBufferHandle(); } | 
| 76 | static bool hasProtectedContent(ClientBuffer *buffer) { return buffer && buffer->isProtected(); } | 
| 77 | |
| 78 | protected: | 
| 79 | void ref(); | 
| 80 | void deref(); | 
| 81 | void sendRelease(); | 
| 82 | virtual void setDestroyed(); | 
| 83 | |
| 84 | struct ::wl_resource *m_buffer = nullptr; | 
| 85 | QRegion m_damage; | 
| 86 | bool m_textureDirty = false; | 
| 87 | |
| 88 | private: | 
| 89 | bool m_committed = false; | 
| 90 | bool m_destroyed = false; | 
| 91 | |
| 92 | QAtomicInt m_refCount; | 
| 93 | |
| 94 | friend class ::QWaylandBufferRef; | 
| 95 | friend class BufferManager; | 
| 96 | }; | 
| 97 | |
| 98 | class Q_WAYLANDCOMPOSITOR_EXPORT SharedMemoryBuffer : public ClientBuffer | 
| 99 | { | 
| 100 | public: | 
| 101 | SharedMemoryBuffer(struct ::wl_resource *bufferResource); | 
| 102 | |
| 103 | QSize size() const override; | 
| 104 | QWaylandSurface::Origin origin() const override; | 
| 105 | QImage image() const override; | 
| 106 | |
| 107 | #if QT_CONFIG(opengl) | 
| 108 | QOpenGLTexture *toOpenGlTexture(int plane = 0) override; | 
| 109 | |
| 110 | private: | 
| 111 | QScopedPointer<QOpenGLTexture> m_shmTexture; | 
| 112 | #endif | 
| 113 | }; | 
| 114 | |
| 115 | } | 
| 116 | |
| 117 | QT_END_NAMESPACE | 
| 118 | |
| 119 | #endif // QWLCLIENTBUFFER_P_H | 
| 120 | 
