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 
27 class WaylandShm;
28 
29 // TODO: migrate away from using this directly
30 struct wl_shm_pool* make_shm_pool(struct wl_shm* shm, int size, void **data);
31 
33 {
34 public:
35  WaylandShmBuffer(void* data, size_t data_size, wl_buffer* buffer);
37 
38  auto data() const -> void* { return data_; }
39  operator wl_buffer*() const { return buffer; }
40 
41 private:
42  friend WaylandShm;
43 
44  auto is_in_use() const -> bool { return self_ptr != nullptr; }
45 
46  static wl_buffer_listener const buffer_listener;
47 
48  static void handle_release(void *data, wl_buffer*);
49 
50  void* const data_;
51  size_t const data_size;
52  wl_buffer* const buffer;
53  std::shared_ptr<WaylandShmBuffer> self_ptr;
54 };
55 
57 {
58 public:
60  WaylandShm(wl_shm* shm);
61 
64 
65 private:
66  wl_shm* const shm;
67  std::shared_ptr<WaylandShmBuffer> current_buffer;
68 };
69 
70 #endif // MIRAL_WAYLAND_SHM_H
Definition: wayland_shm.h:33
auto data() const -> void *
Definition: wayland_shm.h:38
WaylandShmBuffer(void *data, size_t data_size, wl_buffer *buffer)
Definition: wayland_shm.cpp:90
~WaylandShmBuffer()
Definition: wayland_shm.cpp:98
Definition: wayland_shm.h:57
WaylandShm(wl_shm *shm)
Does not take ownership of the wl_shm.
Definition: wayland_shm.cpp:110
auto get_buffer(mir::geometry::Size size, mir::geometry::Stride stride) -> WaylandShmBuffer *
The returned buffer is automatically released as long as it is sent to the compositor.
Definition: wayland_shm.cpp:115
Definition: dimensions.h:37
Definition: size.h:32
struct wl_shm_pool * make_shm_pool(struct wl_shm *shm, int size, void **data)
Definition: wayland_shm.cpp:30

Copyright © 2012-2021 Canonical Ltd.
Generated on Thu Feb 11 23:56:40 UTC 2021
This documentation is licensed under the GPL version 2 or 3.