Skip to main content

motion_core/drawing/
evaluation.rs

1//! Immutable evaluation environment shared by scene and drawing contexts.
2
3use std::sync::Arc;
4
5use super::RenderQuality;
6
7/// Time, quality and explicit resources for one evaluation.
8///
9/// `SceneContext` and `DrawContext` build on the same environment so deferred
10/// content sees identical time, quality, assets, fonts, diagnostics and compute
11/// caches whichever one measures or records it. The environment is immutable
12/// once shared; builders take `self` and drawing contexts hold it by [`Arc`].
13#[derive(Clone, Debug)]
14pub struct Evaluation {
15    time: crate::Time,
16    quality: RenderQuality,
17    assets: crate::Assets,
18    fonts: Option<crate::asset::environment::FontEnvironment>,
19    diagnostics: crate::RequestDiagnostics,
20    cache: Option<crate::RenderCache>,
21}
22
23impl Default for Evaluation {
24    fn default() -> Self {
25        Self {
26            time: crate::Time::ZERO,
27            quality: RenderQuality::Final,
28            assets: crate::Assets::default(),
29            fonts: None,
30            diagnostics: crate::RequestDiagnostics::default(),
31            cache: None,
32        }
33    }
34}
35
36impl Evaluation {
37    /// Creates a Final-quality environment at time zero without assets or caches.
38    pub fn new() -> Self {
39        Self::default()
40    }
41
42    /// Selects an explicit approximation policy for deferred content.
43    pub fn with_quality(mut self, quality: RenderQuality) -> Self {
44        self.quality = quality;
45        self
46    }
47
48    /// Production quality is the default.
49    pub fn quality(&self) -> RenderQuality {
50        self.quality
51    }
52
53    /// Supplies scene-local signed time to deferred content effects.
54    pub fn with_time(mut self, time: crate::Time) -> Self {
55        self.time = time;
56        self
57    }
58
59    /// Scene-local time; defaults to zero.
60    pub fn time(&self) -> crate::Time {
61        self.time
62    }
63
64    /// Captures the same lazy/preloaded owner used by the enclosing session.
65    ///
66    /// The assets inherit this environment's diagnostics, and their font
67    /// environment replaces any previously supplied one.
68    pub fn with_assets(mut self, assets: &crate::Assets) -> Self {
69        self.assets = assets.clone().with_diagnostics(self.diagnostics.clone());
70        if let Some(fonts) = assets.fonts() {
71            self.fonts = Some(fonts.clone());
72        }
73        self
74    }
75
76    /// Explicit resource owner; an unconfigured environment resolves no relative files.
77    pub fn assets(&self) -> &crate::Assets {
78        &self.assets
79    }
80
81    /// Supplies a shared explicit font snapshot.
82    pub fn with_fonts(
83        mut self,
84        fonts: impl Into<crate::asset::environment::FontEnvironment>,
85    ) -> Self {
86        self.fonts = Some(fonts.into());
87        self
88    }
89
90    /// Font environment for paragraph text, optional for geometry-only content.
91    pub fn fonts(&self) -> Option<&crate::asset::environment::FontEnvironment> {
92        self.fonts.as_ref()
93    }
94
95    /// Carries request diagnostics explicitly through deferred content compilation.
96    pub fn with_diagnostics(mut self, diagnostics: crate::RequestDiagnostics) -> Self {
97        self.diagnostics = diagnostics;
98        self.assets = self.assets.with_diagnostics(self.diagnostics.clone());
99        self
100    }
101
102    /// Request-owned sink; cloning the environment preserves its identity.
103    pub fn diagnostics(&self) -> &crate::RequestDiagnostics {
104        &self.diagnostics
105    }
106
107    /// Supplies partitioned compute caches shared by rendering workers.
108    pub fn with_cache(mut self, cache: crate::RenderCache) -> Self {
109        self.cache = Some(cache);
110        self
111    }
112
113    /// Shared compute-cache partitions, absent for standalone uncached evaluation.
114    pub fn cache(&self) -> Option<&crate::RenderCache> {
115        self.cache.as_ref()
116    }
117
118    /// Shares this environment between contexts without copying it.
119    pub fn shared(self) -> Arc<Self> {
120        Arc::new(self)
121    }
122}