This repository was archived by the owner on Aug 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbackend.rs
70 lines (63 loc) · 2.88 KB
/
backend.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! A backend contains information about how clients connected and rendered.
//!
//! In nested environments such as Wayland and X11 the compositor is a client to the hosh
//! process.
//!
//! In the headless backend clients aren't rendered and the only OS resources used are
//! the Wayland file descriptor. This is useful for testing.
//!
//! On the DRM backend the compositor controls an entire TTY. This is the most invasive,
//! but also the most useful backend. If there's an infinite loop here then it is very
//! easy to get into a place where the only course of action is restarting the computer.
//!
//! On the multi backend multiple backends could be running at the same time.
use libc;
use wlroots_sys::{self, wlr_backend, wlr_backend_is_wl, wlr_backend_is_x11,
wlr_backend_is_drm, wlr_backend_is_headless, wlr_backend_is_multi,
wlr_backend_is_libinput};
use super::{WaylandBackend, X11Backend, DRMBackend, HeadlessBackend, MultiBackend, LibInputBackend};
/// A custom function to set up the renderer.
pub type UnsafeRenderSetupFunction = unsafe extern "C" fn(*mut wlroots_sys::wlr_egl,
u32,
*mut libc::c_void,
*mut i32, i32)
-> *mut wlroots_sys::wlr_renderer;
#[derive(Debug, Hash, Eq, PartialEq)]
pub enum Backend {
Wayland(WaylandBackend),
X11(X11Backend),
DRM(DRMBackend),
Headless(HeadlessBackend),
LibInput(LibInputBackend),
Multi(MultiBackend)
}
impl Backend {
/// Create a backend from a `*mut wlr_backend`.
pub unsafe fn from_backend(backend: *mut wlr_backend) -> Self {
if wlr_backend_is_wl(backend) {
Backend::Wayland(WaylandBackend{ backend })
} else if wlr_backend_is_x11(backend) {
Backend::X11(X11Backend{ backend })
} else if wlr_backend_is_drm(backend) {
Backend::DRM(DRMBackend{ backend })
} else if wlr_backend_is_headless(backend) {
Backend::Headless(HeadlessBackend{ backend })
} else if wlr_backend_is_multi(backend) {
Backend::Multi(MultiBackend{ backend })
} else if wlr_backend_is_libinput(backend) {
Backend::LibInput(LibInputBackend { backend })
} else {
panic!("Unknown backend {:p}", backend)
}
}
pub(crate) unsafe fn as_ptr(&self) -> *mut wlr_backend {
match *self {
Backend::Wayland(WaylandBackend { backend }) |
Backend::X11(X11Backend { backend }) |
Backend::DRM(DRMBackend { backend }) |
Backend::Headless(HeadlessBackend { backend }) |
Backend::Multi(MultiBackend { backend }) |
Backend::LibInput(LibInputBackend { backend }) => backend
}
}
}