ferroui_base/rendering/composition/server/
server_loaded_image_surface.rs1use super::{IServerCompositionSurface, IServerObject, ServerCompositionSurfaceChanged};
2use crate::utilities::RefCounted;
3use std::any::Any;
4use std::cell::RefCell;
5use std::rc::Rc;
6
7pub struct ServerLoadedImageSurface {
11 bitmap: RefCell<Option<RefCounted<crate::platform::SharedBitmapImpl>>>,
12 changed: ServerCompositionSurfaceChanged,
13}
14
15impl ServerLoadedImageSurface {
16 pub fn new(bitmap: Option<RefCounted<crate::platform::SharedBitmapImpl>>) -> Rc<ServerLoadedImageSurface> {
20 Rc::new(ServerLoadedImageSurface { bitmap: RefCell::new(bitmap), changed: ServerCompositionSurfaceChanged::new() })
21 }
22}
23
24impl IServerObject for ServerLoadedImageSurface {
25 fn dispose(&self) {
26 if let Some(bitmap) = self.bitmap.borrow_mut().take() {
27 bitmap.dispose();
28 }
29 self.changed.invoke();
30 }
31
32 fn as_surface(self: Rc<Self>) -> Option<Rc<dyn IServerCompositionSurface>> {
33 Some(self)
34 }
35
36 fn as_any(&self) -> &dyn Any {
37 self
38 }
39
40 fn into_any_rc(self: Rc<Self>) -> Rc<dyn Any> {
41 self
42 }
43}
44
45impl IServerCompositionSurface for ServerLoadedImageSurface {
46 fn bitmap(&self) -> Option<std::sync::Arc<crate::platform::SharedBitmapImpl>> {
47 self.bitmap.borrow().as_ref().filter(|bitmap| bitmap.is_alive()).map(|bitmap| bitmap.item())
48 }
49
50 fn changed(&self) -> &ServerCompositionSurfaceChanged {
51 &self.changed
52 }
53}