Skip to main content

ferroui_base/rendering/composition/
composition_surface.rs

1use super::server::ServerObjectId;
2use super::{CompositionObject, Compositor, ICompositionObject};
3use std::any::Any;
4use std::rc::Rc;
5
6/// A surface that a surface visual shows. The server-side counterpart
7/// provides the bitmap.
8pub struct CompositionSurface {
9    object: CompositionObject,
10}
11
12impl CompositionSurface {
13    /// Creates the UI-thread side of a surface whose server side is the
14    /// object with the given id.
15    pub fn new(compositor: &Rc<Compositor>, server: ServerObjectId) -> Rc<CompositionSurface> {
16        Rc::new(CompositionSurface { object: CompositionObject::new(compositor, Some(server)) })
17    }
18
19    pub fn compositor(&self) -> &Rc<Compositor> {
20        self.object.compositor()
21    }
22
23    pub fn is_disposed(&self) -> bool {
24        self.object.is_disposed()
25    }
26
27    pub fn dispose(&self) {
28        self.object.dispose();
29    }
30}
31
32impl ICompositionObject for CompositionSurface {
33    fn server(&self) -> ServerObjectId {
34        self.object.required_server()
35    }
36
37    fn as_any(&self) -> &dyn Any {
38        self
39    }
40
41    fn into_any_rc(self: Rc<Self>) -> Rc<dyn Any> {
42        self
43    }
44}