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

source code of qtwayland/src/compositor/wayland_wrapper/qwlclientbuffer_p.h