KWayland

buffer.cpp
1 /*
2  SPDX-FileCopyrightText: 2013 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "buffer.h"
7 #include "buffer_p.h"
8 #include "shm_pool.h"
9 // system
10 #include <string.h>
11 // wayland
12 #include <wayland-client-protocol.h>
13 
14 namespace KWayland
15 {
16 namespace Client
17 {
18 
19 #ifndef K_DOXYGEN
20 const struct wl_buffer_listener Buffer::Private::s_listener = {
21  Buffer::Private::releasedCallback
22 };
23 #endif
24 
25 Buffer::Private::Private(Buffer *q, ShmPool *parent, wl_buffer *nativeBuffer, const QSize &size, int32_t stride, size_t offset, Format format)
26  : shm(parent)
27  , nativeBuffer(nativeBuffer)
28  , released(false)
29  , size(size)
30  , stride(stride)
31  , offset(offset)
32  , used(false)
33  , format(format)
34  , q(q)
35 {
36  wl_buffer_add_listener(nativeBuffer, &s_listener, this);
37 }
38 
39 Buffer::Private::~Private()
40 {
41  nativeBuffer.release();
42 }
43 
44 void Buffer::Private::destroy()
45 {
46  nativeBuffer.destroy();
47 }
48 
49 void Buffer::Private::releasedCallback(void *data, wl_buffer *buffer)
50 {
51  auto b = reinterpret_cast<Buffer::Private*>(data);
52  Q_ASSERT(b->nativeBuffer == buffer);
53  b->q->setReleased(true);
54 }
55 
56 Buffer::Buffer(ShmPool *parent, wl_buffer *buffer, const QSize &size, int32_t stride, size_t offset, Format format)
57  : d(new Private(this, parent, buffer, size, stride, offset, format))
58 {
59 }
60 
61 Buffer::~Buffer() = default;
62 
63 void Buffer::copy(const void *src)
64 {
65  memcpy(address(), src, d->size.height()*d->stride);
66 }
67 
68 uchar *Buffer::address()
69 {
70  return reinterpret_cast<uchar*>(d->shm->poolAddress()) + d->offset;
71 }
72 
73 wl_buffer *Buffer::buffer() const
74 {
75  return d->nativeBuffer;
76 }
77 
78 Buffer::operator wl_buffer*()
79 {
80  return d->nativeBuffer;
81 }
82 
83 Buffer::operator wl_buffer*() const
84 {
85  return d->nativeBuffer;
86 }
87 
88 bool Buffer::isReleased() const
89 {
90  return d->released;
91 }
92 
93 void Buffer::setReleased(bool released)
94 {
95  d->released = released;
96 }
97 
98 QSize Buffer::size() const
99 {
100  return d->size;
101 }
102 
103 int32_t Buffer::stride() const
104 {
105  return d->stride;
106 }
107 
108 bool Buffer::isUsed() const
109 {
110  return d->used;
111 }
112 
113 void Buffer::setUsed(bool used)
114 {
115  d->used = used;
116 }
117 
118 Buffer::Format Buffer::format() const
119 {
120  return d->format;
121 }
122 
123 quint32 Buffer::getId(wl_buffer *b)
124 {
125  return wl_proxy_get_id(reinterpret_cast<wl_proxy*>(b));
126 }
127 
128 }
129 }
Format
All image formats supported by the implementation.
Definition: buffer.h:37
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed Aug 12 2020 22:50:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.