diff --git a/crates/encoding/src/encoding.rs b/crates/encoding/src/encoding.rs index a9eee83a0..b39c05df0 100644 --- a/crates/encoding/src/encoding.rs +++ b/crates/encoding/src/encoding.rs @@ -16,6 +16,11 @@ use { }; /// Encoded data streams for a scene. +/// +/// # Invariants +/// +/// * At least one transform and style must be encoded before any path data +/// or draw object. #[derive(Clone, Default)] pub struct Encoding { /// The path tag stream. @@ -65,7 +70,7 @@ impl Encoding { } /// Clears the encoding. - pub fn reset(&mut self, is_fragment: bool) { + pub fn reset(&mut self) { self.transforms.clear(); self.path_tags.clear(); self.path_data.clear(); @@ -79,10 +84,6 @@ impl Encoding { self.flags = 0; #[cfg(feature = "full")] self.resources.reset(); - if !is_fragment { - self.transforms.push(Transform::IDENTITY); - self.styles.push(Style::from_fill(Fill::NonZero)); - } } /// Appends another encoding to this one with an optional transform. diff --git a/crates/encoding/src/glyph_cache.rs b/crates/encoding/src/glyph_cache.rs index 330f6d73c..925160e59 100644 --- a/crates/encoding/src/glyph_cache.rs +++ b/crates/encoding/src/glyph_cache.rs @@ -28,7 +28,7 @@ pub struct GlyphCache { impl GlyphCache { pub fn clear(&mut self) { - self.encoding.reset(true); + self.encoding.reset(); self.glyphs.clear(); } diff --git a/shader/flatten.wgsl b/shader/flatten.wgsl index f90e265e9..3d0b8aa66 100644 --- a/shader/flatten.wgsl +++ b/shader/flatten.wgsl @@ -476,6 +476,12 @@ fn compute_tag_monoid(ix: u32) -> PathTagData { // TODO: this can be a read buf overflow. Conditionalize by tag byte? tm = combine_tag_monoid(tag_monoids[ix >> 2u], tm); var tag_byte = (tag_word >> shift) & 0xffu; + // We no longer encode an initial transform and style so these + // are off by one. + // Note: an alternative would be to adjust config.transform_base and + // config.style_base. + tm.trans_ix -= 1u; + tm.style_ix -= STYLE_SIZE_IN_WORDS; return PathTagData(tag_byte, tm); } diff --git a/src/cpu_shader/flatten.rs b/src/cpu_shader/flatten.rs index fba717390..7b31d7438 100644 --- a/src/cpu_shader/flatten.rs +++ b/src/cpu_shader/flatten.rs @@ -524,6 +524,10 @@ fn compute_tag_monoid(ix: usize, pathtags: &[u32], tag_monoids: &[PathMonoid]) - if tag_byte != 0 { tm = tag_monoids[ix >> 2].combine(&tm); } + // We no longer encode an initial transform and style so these + // are off by one. + tm.trans_ix -= 1; + tm.style_ix -= core::mem::size_of::