Mir
wayland_shm.h
Go to the documentation of this file.
1/*
2 * Copyright © Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef MIRAL_WAYLAND_SHM_H
18#define MIRAL_WAYLAND_SHM_H
19
20#include "mir/geometry/size.h"
21
22#include <wayland-client.h>
23#include <memory>
24#include <vector>
25
26class WaylandShm;
27struct WaylandShmPool;
28
29class WaylandShmBuffer : public std::enable_shared_from_this<WaylandShmBuffer>
30{
31public:
33 std::shared_ptr<WaylandShmPool> pool,
34 void* data,
35 mir::geometry::Size size,
36 mir::geometry::Stride stride,
37 wl_buffer* buffer);
39
40 auto data() const -> void* { return data_; }
41 auto size() const -> mir::geometry::Size { return size_; }
42 auto stride() const -> mir::geometry::Stride { return stride_; }
43 /// Returns if this buffer is currently being used by the compositor. In-use buffers keep themselves alive.
44 auto is_in_use() const -> bool { return self_ptr != nullptr; }
45 /// Marks this buffer as in-use and assumes the resulting wl_buffer is sent to the compositor. Keeps this buffer
46 /// alive until the compositor releases it (if it's not sent to the compositor or the compositor never releases it
47 /// this buffer is leaked). Should only be called if the buffer is not already in-use.
48 auto use() -> wl_buffer*;
49
50private:
51 friend WaylandShm;
52
53 static wl_buffer_listener const buffer_listener;
54
55 static void handle_release(void *data, wl_buffer*);
56
57 std::shared_ptr<WaylandShmPool> const pool;
58 void* const data_;
59 mir::geometry::Size const size_;
60 mir::geometry::Stride const stride_;
61 wl_buffer* const buffer;
62 std::shared_ptr<WaylandShmBuffer> self_ptr; ///< Is set on use and cleared on release
63};
64
65/// A single WaylandShm does not efficiently provision multiple buffers for multiple window sizes. Please use one
66/// WaylandShm per window (if windows may have distinct sizes)
68{
69public:
70 /// Does not take ownership of the wl_shm
71 WaylandShm(wl_shm* shm);
72
73 /// Always returns a buffer of the correct size that is not in-use
74 auto get_buffer(mir::geometry::Size size, mir::geometry::Stride stride) -> std::shared_ptr<WaylandShmBuffer>;
75
76private:
77 wl_shm* const shm;
78 /// get_buffer() assumes all buffers in the list have the same size and stride
79 std::vector<std::shared_ptr<WaylandShmBuffer>> buffers;
80};
81
82#endif // MIRAL_WAYLAND_SHM_H
Definition: wayland_shm.h:30
auto use() -> wl_buffer *
Marks this buffer as in-use and assumes the resulting wl_buffer is sent to the compositor....
Definition: wayland_shm.cpp:135
auto data() const -> void *
Definition: wayland_shm.h:40
auto is_in_use() const -> bool
Returns if this buffer is currently being used by the compositor. In-use buffers keep themselves aliv...
Definition: wayland_shm.h:44
auto stride() const -> mir::geometry::Stride
Definition: wayland_shm.h:42
auto size() const -> mir::geometry::Size
Definition: wayland_shm.h:41
~WaylandShmBuffer()
Definition: wayland_shm.cpp:130
WaylandShmBuffer(std::shared_ptr< WaylandShmPool > pool, void *data, mir::geometry::Size size, mir::geometry::Stride stride, wl_buffer *buffer)
Definition: wayland_shm.cpp:115
A single WaylandShm does not efficiently provision multiple buffers for multiple window sizes....
Definition: wayland_shm.h:68
WaylandShm(wl_shm *shm)
Does not take ownership of the wl_shm.
Definition: wayland_shm.cpp:151
auto get_buffer(mir::geometry::Size size, mir::geometry::Stride stride) -> std::shared_ptr< WaylandShmBuffer >
Always returns a buffer of the correct size that is not in-use.
Definition: wayland_shm.cpp:156
Basic geometry types. Types for dimensions, displacements, etc. and the operations that they support.
Definition: size.h:27
Definition: runner.h:27

Copyright © 2012-2023 Canonical Ltd.
Generated on Tue 2 May 10:01:24 UTC 2023
This documentation is licensed under the GPL version 2 or 3.