Mir
wayland_shm.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2018 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 
26 class WaylandShm;
27 struct WaylandShmPool;
28 
29 class WaylandShmBuffer : public std::enable_shared_from_this<WaylandShmBuffer>
30 {
31 public:
33  std::shared_ptr<WaylandShmPool> pool,
34  void* data,
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_; }
44  auto is_in_use() const -> bool { return self_ptr != nullptr; }
48  auto use() -> wl_buffer*;
49 
50 private:
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;
63 };
64 
68 {
69 public:
71  WaylandShm(wl_shm* shm);
72 
74  auto get_buffer(mir::geometry::Size size, mir::geometry::Stride stride) -> std::shared_ptr<WaylandShmBuffer>;
75 
76 private:
77  wl_shm* const shm;
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
Definition: dimensions.h:34
detail::IntWrapper< struct StrideTag > Stride
Definition: dimensions.h:53
Definition: splash_session.h:22
Definition: size.h:30

Copyright © 2012-2022 Canonical Ltd.
Generated on Tue May 24 14:35:34 UTC 2022
This documentation is licensed under the GPL version 2 or 3.