pub struct DrawContext { /* private fields */ }Expand description
Time-independent drawing inputs for the frontend.
Device scale and an optional immutable font snapshot are shared by bounds measurement and recording; neither implicitly discovers resources.
Implementations§
Source§impl DrawContext
impl DrawContext
Sourcepub fn new(device_scale: f64) -> Result<Self, ValidationError>
pub fn new(device_scale: f64) -> Result<Self, ValidationError>
Creates drawing inputs with a finite, strictly positive device scale.
Sourcepub fn quality(self, quality: RenderQuality) -> Self
pub fn quality(self, quality: RenderQuality) -> Self
Selects an explicit approximation policy for deferred content recording.
Sourcepub fn render_quality(&self) -> RenderQuality
pub fn render_quality(&self) -> RenderQuality
Production quality is the default for every standalone drawing context.
Sourcepub fn with_time(self, time: Time) -> Self
pub fn with_time(self, time: Time) -> Self
Supplies scene-local signed time to deferred content effects.
Sourcepub fn device_scale(&self) -> f64
pub fn device_scale(&self) -> f64
Device pixels per logical unit; does not implicitly modify local geometry.
Sourcepub fn with_fonts(self, fonts: impl Into<FontEnvironment>) -> Self
pub fn with_fonts(self, fonts: impl Into<FontEnvironment>) -> Self
Supplies a shared explicit font snapshot to paragraph bounds and drawing.
Sourcepub fn fonts(&self) -> Option<&FontEnvironment>
pub fn fonts(&self) -> Option<&FontEnvironment>
Font environment for paragraph text, optional for geometry-only drawing.
Sourcepub fn with_assets(self, assets: &Assets) -> Self
pub fn with_assets(self, assets: &Assets) -> Self
Captures the same lazy/preloaded owner used by the enclosing session.
Sourcepub fn assets(&self) -> &Assets
pub fn assets(&self) -> &Assets
Explicit resource owner; an unconfigured context does not resolve relative files.
Sourcepub fn record(
&self,
drawable: &dyn Drawable,
limits: ValidationLimits,
) -> Result<Vec<DrawCommand>, ValidationError>
pub fn record( &self, drawable: &dyn Drawable, limits: ValidationLimits, ) -> Result<Vec<DrawCommand>, ValidationError>
Records a drawable’s local commands without rendering or color quantization.
Limits charge the drawable at depth one and every command at depth two.
Callback errors and ignored canvas errors both fail the recording.
This local buffer is not a scene DisplayList; use crate::Node::compile
for layout, global transforms and isolated subtree opacity.
use motion_core::prelude::*;
use motion_core::{
DisplayList, RasterLimits, ResourcePool, ValidatedDisplayList, MAX_PATH_VERBS,
MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let bounds = Rect::new(0.1, 0.2, 10.3, 20.4);
let color = Color::from_rgb_float(1.25, -0.125, 0.333);
let commands =
DrawContext::new(2.0)?.record(&bounds.fill(color), ValidationLimits::default())?;
assert_eq!(
commands,
vec![DrawCommand::FillRect {
bounds,
transform: Transform::IDENTITY,
paint: Paint::Solid(color)
}]
);Sourcepub fn with_validation_limits(self, limits: ValidationLimits) -> Self
pub fn with_validation_limits(self, limits: ValidationLimits) -> Self
Supplies the enclosing structural policy to deferred layout callbacks.
Sourcepub fn validation_limits(&self) -> ValidationLimits
pub fn validation_limits(&self) -> ValidationLimits
Structural policy supplied by the enclosing measurement or compilation.
Sourcepub fn with_layout_cache(self, cache: Arc<SceneCache>) -> Self
pub fn with_layout_cache(self, cache: Arc<SceneCache>) -> Self
Supplies content-layout LRU storage shared by one render session.
Sourcepub fn layout_cache(&self) -> Option<&Arc<SceneCache>>
pub fn layout_cache(&self) -> Option<&Arc<SceneCache>>
Optional session layout cache, separate from active-frame budgets.
Sourcepub fn render_cache(self, cache: RenderCache) -> Self
pub fn render_cache(self, cache: RenderCache) -> Self
Supplies partitioned pure caches shared by rendering workers.
Sourcepub fn configured_render_cache(&self) -> Option<&RenderCache>
pub fn configured_render_cache(&self) -> Option<&RenderCache>
Shared cache partitions, absent for standalone uncached drawing.
Sourcepub fn cache_layout<Key: Eq + Hash + Send + Sync + 'static, Value: Send + Sync + 'static>(
&self,
key: Key,
build: impl FnOnce() -> Value,
cost: impl FnOnce(&Value) -> usize,
) -> Arc<Value> ⓘ
pub fn cache_layout<Key: Eq + Hash + Send + Sync + 'static, Value: Send + Sync + 'static>( &self, key: Key, build: impl FnOnce() -> Value, cost: impl FnOnce(&Value) -> usize, ) -> Arc<Value> ⓘ
Caches immutable layout by full typed key and declared logical payload.
Sourcepub fn with_font_usage(self, usage: FontUsage) -> Self
pub fn with_font_usage(self, usage: FontUsage) -> Self
Carries an export-owned font observation sink into every recorded glyph.
Sourcepub fn font_usage(&self) -> &FontUsage
pub fn font_usage(&self) -> &FontUsage
Font sources actually painted through this context.
Sourcepub fn with_diagnostics(self, diagnostics: RequestDiagnostics) -> Self
pub fn with_diagnostics(self, diagnostics: RequestDiagnostics) -> Self
Carries request diagnostics explicitly through deferred content compilation.
Sourcepub fn diagnostics(&self) -> &RequestDiagnostics
pub fn diagnostics(&self) -> &RequestDiagnostics
Request-owned sink; cloning this drawing context preserves its identity.