1/****************************************************************************
2**
3** Copyright (C) 2017 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 QWLCLIENTBUFFER_P_H
31#define QWLCLIENTBUFFER_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 <QtCore/QRect>
45#include <QtGui/qopengl.h>
46#include <QImage>
47#include <QAtomicInt>
48
49#include <QtWaylandCompositor/QWaylandSurface>
50#include <QtWaylandCompositor/QWaylandBufferRef>
51
52#include <wayland-server-core.h>
53
54QT_BEGIN_NAMESPACE
55
56class QWaylandClientBufferIntegration;
57class QWaylandBufferRef;
58class QWaylandCompositor;
59class QOpenGLTexture;
60
61namespace QtWayland {
62
63struct surface_buffer_destroy_listener
64{
65 struct wl_listener listener;
66 class ClientBuffer *surfaceBuffer = nullptr;
67};
68
69class Q_WAYLAND_COMPOSITOR_EXPORT ClientBuffer
70{
71public:
72 ClientBuffer(struct ::wl_resource *bufferResource);
73
74 virtual ~ClientBuffer();
75
76 virtual QWaylandBufferRef::BufferFormatEgl bufferFormatEgl() const;
77 virtual QSize size() const = 0;
78 virtual QWaylandSurface::Origin origin() const = 0;
79
80 virtual quintptr lockNativeBuffer() { return 0; }
81 virtual void unlockNativeBuffer(quintptr native_buffer) const { Q_UNUSED(native_buffer); }
82
83 virtual QImage image() const { return QImage(); }
84
85 inline bool isCommitted() const { return m_committed; }
86 virtual void setCommitted(QRegion &damage);
87 bool isDestroyed() { return m_destroyed; }
88
89 inline struct ::wl_resource *waylandBufferHandle() const { return m_buffer; }
90
91 bool isSharedMemory() const { return wl_shm_buffer_get(resource: m_buffer); }
92
93#if QT_CONFIG(opengl)
94 virtual QOpenGLTexture *toOpenGlTexture(int plane = 0) = 0;
95#endif
96
97 static bool hasContent(ClientBuffer *buffer) { return buffer && buffer->waylandBufferHandle(); }
98
99protected:
100 void ref();
101 void deref();
102 void sendRelease();
103 virtual void setDestroyed();
104
105 struct ::wl_resource *m_buffer = nullptr;
106 QRegion m_damage;
107 bool m_textureDirty = false;
108
109private:
110 bool m_committed = false;
111 bool m_destroyed = false;
112
113 QAtomicInt m_refCount;
114
115 friend class ::QWaylandBufferRef;
116 friend class BufferManager;
117};
118
119class Q_WAYLAND_COMPOSITOR_EXPORT SharedMemoryBuffer : public ClientBuffer
120{
121public:
122 SharedMemoryBuffer(struct ::wl_resource *bufferResource);
123
124 QSize size() const override;
125 QWaylandSurface::Origin origin() const override;
126 QImage image() const override;
127
128#if QT_CONFIG(opengl)
129 QOpenGLTexture *toOpenGlTexture(int plane = 0) override;
130
131private:
132 QOpenGLTexture *m_shmTexture = nullptr;
133#endif
134};
135
136}
137
138QT_END_NAMESPACE
139
140#endif // QWLCLIENTBUFFER_P_H
141

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