Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandbufferref.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QDebug>
5#include <QAtomicInt>
6
7#include "qwaylandbufferref.h"
9
10#include <type_traits>
11
13
14#define CHECK1(l, r, op) \
15 static_assert(std::is_same_v< \
16 bool, \
17 decltype(std::declval<QWaylandBufferRef l >() op \
18 std::declval<QWaylandBufferRef r >()) \
19 >)
20#define CHECK2(l, r) \
21 CHECK1(l, r, ==); \
22 CHECK1(l, r, !=)
23#define CHECK(l, r) \
24 CHECK2(l, r); \
25 CHECK2(l &, r); \
26 CHECK2(l &, r &); \
27 CHECK2(l, r &)
28
30CHECK(const, );
31CHECK(const, const);
32CHECK(, const);
33
34#undef CHECK
35#undef CHECK2
36#undef CHECK1
37
39{
40public:
42
44 return !buffer || buffer->isDestroyed();
45 }
46};
47
63{
64 d->buffer = nullptr;
65}
66
72{
73 d->buffer = buffer;
74 if (buffer)
75 buffer->ref();
76}
77
83{
84 d->buffer = ref.d->buffer;
85 if (d->buffer)
86 d->buffer->ref();
87}
88
93{
94 if (d->buffer)
95 d->buffer->deref();
96 delete d;
97}
98
104{
105 if (ref.d->buffer)
106 ref.d->buffer->ref();
107
108 if (d->buffer)
109 d->buffer->deref();
110
111 d->buffer = ref.d->buffer;
112
113 return *this;
114}
115
122bool operator==(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) noexcept
123{
124 return lhs.d->buffer == rhs.d->buffer;
125}
126
141{
142 return !d->buffer;
143}
144
151{
152 return d->buffer;
153}
160{
161 return QtWayland::ClientBuffer::hasContent(d->buffer);
162}
176
182{
183 return d->buffer && d->buffer->isDestroyed();
184}
185
189struct ::wl_resource *QWaylandBufferRef::wl_buffer() const
190{
191 return d->buffer ? d->buffer->waylandBufferHandle() : nullptr;
192}
193
197QtWayland::ClientBuffer *QWaylandBufferRef::buffer() const
198{
199 return d->buffer;
200}
201
207{
208 if (d->nullOrDestroyed())
209 return QSize();
210
211 return d->buffer->size();
212}
213
220{
221 if (d->buffer)
222 return d->buffer->origin();
223
225}
226
228{
229 if (d->nullOrDestroyed())
230 return BufferType_Null;
231
232 if (isSharedMemory())
234
235 return BufferType_Egl;
236}
237
239{
240 if (d->nullOrDestroyed())
242
243 return d->buffer->bufferFormatEgl();
244}
245
250{
251 if (d->nullOrDestroyed())
252 return false;
253
254 return d->buffer->isSharedMemory();
255}
256
261{
262 if (d->nullOrDestroyed())
263 return QImage();
264
265 return d->buffer->image();
266}
267
268#if QT_CONFIG(opengl)
278QOpenGLTexture *QWaylandBufferRef::toOpenGLTexture(int plane) const
279{
280 if (d->nullOrDestroyed())
281 return nullptr;
282
283 return d->buffer->toOpenGlTexture(plane);
284}
285
293{
294 return d->buffer->lockNativeBuffer();
295}
296
302{
303 d->buffer->unlockNativeBuffer(handle);
304}
305
306#endif
307
\inmodule QtGui
Definition qimage.h:37
\inmodule QtGui
\inmodule QtCore
Definition qsize.h:25
\inmodule QtWaylandCompositor
QWaylandBufferRef & operator=(const QWaylandBufferRef &ref)
Assigns ref to this buffer and adds a reference to it.
bool hasContent() const
Returns true if this QWaylandBufferRef references a buffer that has content.
void unlockNativeBuffer(quintptr handle)
bool isDestroyed() const
Returns true if this QWaylandBufferRef references a buffer that has been destroyed.
QWaylandSurface::Origin origin() const
Returns the origin of the buffer.
bool hasProtectedContent() const
Returns true if this QWaylandBufferRef references a buffer that has protected content.
~QWaylandBufferRef()
Dereferences the buffer.
bool isSharedMemory() const
Returns true if the buffer is a shared memory buffer.
QWaylandBufferRef()
Constructs a null buffer ref.
quintptr lockNativeBuffer()
bool hasBuffer() const
Returns true if this QWaylandBufferRef references a buffer.
BufferFormatEgl bufferFormatEgl() const
bool isNull() const
Returns true if this QWaylandBufferRef does not reference a buffer.
BufferType bufferType() const
struct wl_resource * wl_buffer() const
Returns the Wayland resource for the buffer.
QSize size() const
Returns the size of the buffer.
QImage image() const
Returns an image with the contents of the buffer.
Origin
This enum type is used to specify the origin of a QWaylandSurface's buffer.
static bool hasProtectedContent(ClientBuffer *buffer)
static bool hasContent(ClientBuffer *buffer)
Combined button and popup list for selecting options.
GLuint64 GLenum void * handle
GLenum GLuint buffer
GLint ref
size_t quintptr
Definition qtypes.h:167
#define CHECK(l, r)
bool operator==(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) noexcept