atagen

monolith

public
Star0
Watch0
8ffa3fa4d4a9331f2638c1598a9f3c107e148296
1
ssh://brewery@pls.lobotomise.me:33/atagen/monolith.git
crates/monolith/src/backend.rsRust64 lines1.6 KB
1
//! Where frames go and input comes from. The set is closed: bare metal and
2
//! a window on another compositor, and later a headless one for tests.
3
4
use crate::drm::Drm;
5
use crate::nested::Host;
6
use monolith_layout::OutputId;
7
use smithay::backend::drm::DrmNode;
8
use smithay::output::Output;
9
use smithay::wayland::drm_syncobj::DrmSyncobjState;
10
11
pub enum Backend {
12
    /// Before `drm::init` or `nested::init` has run.
13
    Starting,
14
    Drm(Box<Drm>),
15
    Nested(Box<Host>),
16
}
17
18
impl Backend {
19
    pub fn drm(&self) -> Option<&Drm> {
20
        match self {
21
            Backend::Drm(d) => Some(d),
22
            _ => None,
23
        }
24
    }
25
26
    pub fn drm_mut(&mut self) -> Option<&mut Drm> {
27
        match self {
28
            Backend::Drm(d) => Some(d),
29
            _ => None,
30
        }
31
    }
32
33
    pub fn nested(&self) -> Option<&Host> {
34
        match self {
35
            Backend::Nested(h) => Some(h),
36
            _ => None,
37
        }
38
    }
39
40
    pub fn nested_mut(&mut self) -> Option<&mut Host> {
41
        match self {
42
            Backend::Nested(h) => Some(h),
43
            _ => None,
44
        }
45
    }
46
47
    /// The smithay output behind a layout output.
48
    pub fn output(&self, o: OutputId) -> Option<Output> {
49
        match self {
50
            Backend::Drm(d) => d.output(o),
51
            Backend::Nested(h) => (h.output_id == o).then(|| h.output.clone()),
52
            Backend::Starting => None,
53
        }
54
    }
55
56
    /// The node clients allocate dmabufs on, known on bare metal.
57
    pub fn render_node(&self) -> Option<DrmNode> {
58
        self.drm().map(|d| d.render_node)
59
    }
60
61
    pub fn syncobj_mut(&mut self) -> Option<&mut DrmSyncobjState> {
62
        self.drm_mut()?.syncobj.as_mut()
63
    }
64
}