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  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIRAL_WAYLAND_SHM_H
20 #define MIRAL_WAYLAND_SHM_H
21 
22 #include "mir/geometry/size.h"
23 
24 #include <wayland-client.h>
25 #include <memory>
26 #include <vector>
27 
28 class WaylandShm;
29 struct WaylandShmPool;
30 
31 class WaylandShmBuffer : public std::enable_shared_from_this<WaylandShmBuffer>
32 {
33 public:
35  std::shared_ptr<WaylandShmPool> pool,
36  void* data,
39  wl_buffer* buffer);
41 
42  auto data() const -> void* { return data_; }
43  auto size() const -> mir::geometry::Size { return size_; }
44  auto stride() const -> mir::geometry::Stride { return stride_; }
46  auto is_in_use() const -> bool { return self_ptr != nullptr; }
50  auto use() -> wl_buffer*;
51 
52 private:
53  friend WaylandShm;
54 
55  static wl_buffer_listener const buffer_listener;
56 
57  static void handle_release(void *data, wl_buffer*);
58 
59  std::shared_ptr<WaylandShmPool> const pool;
60  void* const data_;
61  mir::geometry::Size const size_;
62  mir::geometry::Stride const stride_;
63  wl_buffer* const buffer;
64  std::shared_ptr<WaylandShmBuffer> self_ptr;
65 };
66 
70 {
71 public:
73  WaylandShm(wl_shm* shm);
74 
76  auto get_buffer(mir::geometry::Size size, mir::geometry::Stride stride) -> std::shared_ptr<WaylandShmBuffer>;
77 
78 private:
79  wl_shm* const shm;
81  std::vector<std::shared_ptr<WaylandShmBuffer>> buffers;
82 };
83 
84 #endif // MIRAL_WAYLAND_SHM_H
Definition: wayland_shm.h:32
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:137
auto data() const -> void *
Definition: wayland_shm.h:42
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:46
auto stride() const -> mir::geometry::Stride
Definition: wayland_shm.h:44
auto size() const -> mir::geometry::Size
Definition: wayland_shm.h:43
~WaylandShmBuffer()
Definition: wayland_shm.cpp:132
WaylandShmBuffer(std::shared_ptr< WaylandShmPool > pool, void *data, mir::geometry::Size size, mir::geometry::Stride stride, wl_buffer *buffer)
Definition: wayland_shm.cpp:117
A single WaylandShm does not efficiently provision multiple buffers for multiple window sizes....
Definition: wayland_shm.h:70
WaylandShm(wl_shm *shm)
Does not take ownership of the wl_shm.
Definition: wayland_shm.cpp:153
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:158
Definition: dimensions.h:36
detail::IntWrapper< struct StrideTag > Stride
Definition: dimensions.h:55
Definition: splash_session.h:24
Definition: size.h:32

Copyright © 2012-2022 Canonical Ltd.
Generated on Thu Mar 3 22:46:49 UTC 2022
This documentation is licensed under the GPL version 2 or 3.