diff --git a/piet-scene/src/scene/builder.rs b/piet-scene/src/scene/builder.rs index 85d75b2..39abc93 100644 --- a/piet-scene/src/scene/builder.rs +++ b/piet-scene/src/scene/builder.rs @@ -24,8 +24,8 @@ use core::borrow::Borrow; const MAX_BLEND_STACK: usize = 256; /// Creates a new builder for constructing a scene. -pub fn build_scene<'a>(scene: &'a mut Scene, resources: &'a mut ResourceContext) -> Builder<'a> { - Builder::new(&mut scene.data, ResourceData::Scene(resources)) +pub fn build_scene<'a>(scene: &'a mut Scene, rcx: &'a mut ResourceContext) -> Builder<'a> { + Builder::new(&mut scene.data, ResourceData::Scene(rcx)) } /// Creates a new builder for construction a scene fragment. @@ -62,7 +62,8 @@ impl<'a> Builder<'a> { } /// Pushes a transform matrix onto the stack. - pub fn push_transform(&mut self, transform: Affine) { + pub fn push_transform(&mut self, transform: impl Into) { + let transform = transform.into(); self.transform(transform); self.transforms.push(transform); } diff --git a/piet-scene/src/scene/mod.rs b/piet-scene/src/scene/mod.rs index 9f7be2f..abbc6d9 100644 --- a/piet-scene/src/scene/mod.rs +++ b/piet-scene/src/scene/mod.rs @@ -23,11 +23,13 @@ pub use builder::{build_fragment, build_scene, Builder}; pub use style::*; use super::brush::*; -use super::geometry::{Affine, Point, Rect}; +use super::geometry::{Affine, Point}; use super::path::Element; +use super::resource::ResourceContext; use core::ops::Range; +/// Raw data streams describing an encoded scene. #[derive(Default)] pub struct SceneData { pub transform_stream: Vec, @@ -83,6 +85,13 @@ pub struct Scene { } impl Scene { + /// Creates a new builder for filling the scene. Any current content in + /// the scene is cleared. + pub fn build<'a>(&'a mut self, rcx: &'a mut ResourceContext) -> Builder<'a> { + build_scene(self, rcx) + } + + /// Returns the raw encoded scene data streams. pub fn data(&self) -> &SceneData { &self.data } @@ -96,9 +105,17 @@ pub struct Fragment { } impl Fragment { + /// Returns the underlying stream of points that defined all encoded path + /// segments. pub fn points(&self) -> &[Point] { bytemuck::cast_slice(&self.data.pathseg_stream) } + + /// Creates a new builder for filling the fragment. Any current content in + /// the fragment is cleared. + pub fn build<'a>(&'a mut self) -> Builder<'a> { + build_fragment(self) + } } #[derive(Default)]