Skip to main content

ferroui_base/rendering/composition/generated/
composition_surface_visual.rs

1// @generated by scripts/generate_composition.py — do not edit
2
3//! `CompositionSurfaceVisual`.
4
5use bitflags::bitflags;
6use crate::rendering::composition::ICompositionObject;
7use crate::rendering::composition::animations::ICompositionAnimation;
8use crate::rendering::composition::expressions::ExpressionVariant;
9use crate::rendering::composition::server::AsServerRenderResource;
10use crate::rendering::composition::server::CompositionProperty;
11use crate::rendering::composition::server::CompositionPropertyOf;
12use crate::rendering::composition::server::IServerAnimatedPropertyHost;
13use crate::rendering::composition::server::IServerObject;
14use crate::rendering::composition::server::ServerPropertyValue;
15use crate::rendering::composition::server::ServerValueChange;
16use crate::rendering::composition::server::props_of;
17use crate::rendering::composition::server::read_server_object;
18use crate::rendering::composition::transport::BatchStreamReader;
19use crate::rendering::composition::transport::BatchStreamWriter;
20use crate::rendering::composition::transport::BatchValue;
21use crate::rendering::composition::transport::BatchValueReader;
22use std::any::Any;
23use std::any::TypeId;
24use std::cell::Cell;
25use std::cell::RefCell;
26use std::rc::Rc;
27use std::sync::OnceLock;
28use std::time::Duration;
29use super::CompositionContainerVisualHooks;
30use super::CompositionContainerVisualProps;
31
32bitflags! {
33    /// The fields of `CompositionSurfaceVisual` that changed since its last serialization.
34    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
35    pub struct CompositionSurfaceVisualChangedFields: u8 {
36        const SURFACE = 1;
37    }
38}
39
40impl BatchValue for CompositionSurfaceVisualChangedFields {
41    #[inline]
42    fn write_to(&self, out: &mut Vec<u8>) {
43        self.bits().write_to(out);
44    }
45
46    #[inline]
47    fn read_from(input: &mut BatchValueReader<'_>) -> Self {
48        CompositionSurfaceVisualChangedFields::from_bits_retain(u8::read_from(input))
49    }
50}
51
52/// The partial methods of `CompositionSurfaceVisual`: implemented by the class that embeds
53/// [`CompositionSurfaceVisualProps`]. Every hook defaults to doing nothing.
54pub trait CompositionSurfaceVisualHooks: CompositionContainerVisualHooks {
55    fn initialize_defaults_extra(&self) {}
56
57    fn validate_surface_change(&self, _old_value: &Option<Rc<dyn ICompositionObject>>, _new_value: &Option<Rc<dyn ICompositionObject>>) {}
58    fn on_surface_changed(&self) {}
59    fn on_surface_changing(&self) {}
60}
61
62/// The UI-thread properties of `CompositionSurfaceVisual`.
63pub struct CompositionSurfaceVisualProps {
64    base: CompositionContainerVisualProps,
65    changed_fields_of_composition_surface_visual: Cell<CompositionSurfaceVisualChangedFields>,
66    surface: RefCell<Option<Rc<dyn ICompositionObject>>>,
67}
68
69impl Default for CompositionSurfaceVisualProps {
70    fn default() -> Self {
71        Self::new()
72    }
73}
74
75impl CompositionSurfaceVisualProps {
76    /// Creates the properties with every field at the default of its type.
77    /// The defaults of the schema are applied by
78    /// [`initialize_defaults`](Self::initialize_defaults).
79    pub fn new() -> Self {
80        Self {
81            base: CompositionContainerVisualProps::new(),
82            changed_fields_of_composition_surface_visual: Cell::new(CompositionSurfaceVisualChangedFields::empty()),
83            surface: RefCell::new(None),
84        }
85    }
86
87    /// The properties of the base class.
88    pub fn base(&self) -> &CompositionContainerVisualProps {
89        &self.base
90    }
91
92    /// The `InitializeDefaults` calls of the constructor chain: the base
93    /// classes first, then this class.
94    pub fn initialize_defaults(&self, host: &dyn CompositionSurfaceVisualHooks) {
95        self.base.initialize_defaults(host);
96        self.initialize_own_defaults(host);
97    }
98
99    /// `InitializeDefaults` of this class alone.
100    pub fn initialize_own_defaults(&self, host: &dyn CompositionSurfaceVisualHooks) {
101        CompositionSurfaceVisualHooks::initialize_defaults_extra(host);
102    }
103
104    /// `Surface`.
105    pub fn surface(&self) -> Option<Rc<dyn ICompositionObject>> {
106        self.surface.borrow().clone()
107    }
108
109    /// Sets `Surface`.
110    pub fn set_surface(&self, host: &dyn CompositionSurfaceVisualHooks, value: Option<Rc<dyn ICompositionObject>>) {
111        let mut changed = false;
112        let old_value = self.surface.borrow().clone();
113        if old_value.differs(&value) {
114            CompositionSurfaceVisualHooks::validate_surface_change(host, &old_value, &value);
115            CompositionSurfaceVisualHooks::on_surface_changing(host);
116            changed = true;
117            // Update the backing value
118            *self.surface.borrow_mut() = value.clone();
119            // Register object for serialization in the next batch
120            self.changed_fields_of_composition_surface_visual.set(self.changed_fields_of_composition_surface_visual.get() | CompositionSurfaceVisualChangedFields::SURFACE);
121            host.register_for_serialization();
122        }
123        *self.surface.borrow_mut() = value;
124        if changed {
125            CompositionSurfaceVisualHooks::on_surface_changed(host);
126        }
127    }
128
129    /// Connects an animation with the named property. Returns `false` when
130    /// neither this class nor its generated bases have an animated property
131    /// of that name: the caller continues with its hand-written base.
132    pub fn start_animation(
133        &self,
134        host: &dyn CompositionSurfaceVisualHooks,
135        property_name: &str,
136        animation: &dyn ICompositionAnimation,
137        final_value: Option<ExpressionVariant>,
138    ) -> bool {
139        self.base.start_animation(host, property_name, animation, final_value)
140    }
141
142    /// Writes the changes of the object: the base class first, then the
143    /// changed-fields mask and the changed members of this class.
144    pub fn serialize_changes_core(&self, host: &dyn CompositionSurfaceVisualHooks, writer: &mut BatchStreamWriter<'_>) {
145        self.base.serialize_changes_core(host, writer);
146        let changed = self.changed_fields_of_composition_surface_visual.get();
147        writer.write(changed);
148        if changed.contains(CompositionSurfaceVisualChangedFields::SURFACE) {
149            writer.write_server_object(self.surface.borrow().clone().map(|o| o.server()));
150        }
151        self.changed_fields_of_composition_surface_visual.set(CompositionSurfaceVisualChangedFields::empty());
152    }
153}
154
155/// The partial methods of `ServerCompositionSurfaceVisual`: implemented by the class that embeds
156/// [`ServerCompositionSurfaceVisualProps`]. Every hook defaults to doing nothing.
157pub trait ServerCompositionSurfaceVisualHooks: IServerAnimatedPropertyHost {
158    /// `base.DeserializeChangesCore(reader, committedAt)`: reads the changes of
159    /// the hand-written base class `ServerSizeDependantVisual`.
160    fn base_deserialize_changes_core(&self, reader: &mut BatchStreamReader<'_>, committed_at: Duration);
161
162    fn deserialize_changes_extra(&self, _reader: &mut BatchStreamReader<'_>) {}
163    fn on_fields_deserialized(&self, _changed: CompositionSurfaceVisualChangedFields) {}
164
165    fn on_surface_changed(&self) {}
166    fn on_surface_changing(&self) {}
167}
168
169/// The server-side properties of `ServerCompositionSurfaceVisual`.
170pub struct ServerCompositionSurfaceVisualProps {
171    surface: RefCell<Option<Rc<dyn IServerObject>>>,
172}
173
174impl Default for ServerCompositionSurfaceVisualProps {
175    fn default() -> Self {
176        Self::new()
177    }
178}
179
180impl ServerCompositionSurfaceVisualProps {
181    /// Creates the properties with every field at the default of its type; the
182    /// values of the UI thread arrive with the first batch.
183    pub fn new() -> Self {
184        Self {
185            surface: RefCell::new(None),
186        }
187    }
188
189    /// This block or the block of a base class, by type: what
190    /// `IServerObject::get_props` of the embedding class returns.
191    pub fn find_props(&self, type_id: TypeId) -> Option<&dyn Any> {
192        if type_id == TypeId::of::<Self>() {
193            return Some(self);
194        }
195        None
196    }
197
198    /// The composition property of `Surface`.
199    pub fn id_of_surface_property() -> &'static CompositionPropertyOf<Option<Rc<dyn IServerObject>>> {
200        static PROPERTY: OnceLock<CompositionPropertyOf<Option<Rc<dyn IServerObject>>>> = OnceLock::new();
201        PROPERTY.get_or_init(|| {
202            CompositionProperty::register::<ServerCompositionSurfaceVisualProps, Option<Rc<dyn IServerObject>>>(
203                "Surface",
204                "ServerCompositionSurfaceVisual",
205                |obj| props_of::<ServerCompositionSurfaceVisualProps>(obj).surface.borrow().clone(),
206                |obj, v| *props_of::<ServerCompositionSurfaceVisualProps>(obj).surface.borrow_mut() = v,
207                None,
208                None,
209            )
210        })
211    }
212
213    /// `Surface`.
214    pub fn surface(&self) -> Option<Rc<dyn IServerObject>> {
215        self.surface.borrow().clone()
216    }
217
218    pub fn set_surface(&self, host: &dyn ServerCompositionSurfaceVisualHooks, value: Option<Rc<dyn IServerObject>>) {
219        let old_value = self.surface.borrow().clone();
220        let mut changed = false;
221        if old_value.differs(&value) {
222            ServerCompositionSurfaceVisualHooks::on_surface_changing(host);
223            changed = true;
224        }
225        host.set_value(
226            Self::id_of_surface_property().base(),
227            ServerValueChange {
228                equal: old_value.default_equals(&value),
229                old_resource: old_value.as_server_render_resource(),
230                new_resource: value.as_server_render_resource(),
231                assign: &mut || *self.surface.borrow_mut() = value.clone(),
232            },
233        );
234        if changed {
235            ServerCompositionSurfaceVisualHooks::on_surface_changed(host);
236        }
237    }
238
239    /// Reads the changes of the object: the base class first, then the
240    /// changed-fields mask and the changed members of this class.
241    pub fn deserialize_changes_core(
242        &self,
243        host: &dyn ServerCompositionSurfaceVisualHooks,
244        reader: &mut BatchStreamReader<'_>,
245        committed_at: Duration,
246    ) {
247        let compositor = host.server_compositor();
248        ServerCompositionSurfaceVisualHooks::base_deserialize_changes_core(host, reader, committed_at);
249        ServerCompositionSurfaceVisualHooks::deserialize_changes_extra(host, reader);
250        let changed = reader.read::<CompositionSurfaceVisualChangedFields>();
251        if changed.contains(CompositionSurfaceVisualChangedFields::SURFACE) {
252            let value = read_server_object(reader, compositor.as_ref());
253            self.set_surface(host, value);
254        }
255        ServerCompositionSurfaceVisualHooks::on_fields_deserialized(host, changed);
256    }
257}