@@ -10,14 +10,11 @@ use {
1010 Brush , Color , Fill , Mix ,
1111 } ,
1212 std:: pin:: Pin ,
13- vello_encoding:: {
14- BumpEstimator , Encoding as VelloEncoding , PathEncoder , RenderConfig , Transform ,
15- } ,
13+ vello_encoding:: { Encoding as VelloEncoding , RenderConfig , Transform } ,
1614} ;
1715
1816pub ( crate ) struct Encoding {
1917 encoding : VelloEncoding ,
20- estimator : BumpEstimator ,
2118}
2219
2320pub ( crate ) fn new_encoding ( ) -> Box < Encoding > {
@@ -32,7 +29,7 @@ impl Encoding {
3229 // the encoding as non-fragment achieves this.
3330 let mut encoding = VelloEncoding :: new ( ) ;
3431 encoding. reset ( ) ;
35- Encoding { encoding, estimator : BumpEstimator :: new ( ) , }
32+ Encoding { encoding }
3633 }
3734
3835 pub fn is_empty ( & self ) -> bool {
@@ -41,7 +38,6 @@ impl Encoding {
4138
4239 pub fn reset ( & mut self ) {
4340 self . encoding . reset ( ) ;
44- self . estimator . reset ( ) ;
4541 }
4642
4743 pub fn fill (
@@ -51,10 +47,10 @@ impl Encoding {
5147 brush : & ffi:: Brush ,
5248 path_iter : Pin < & mut ffi:: PathIterator > ,
5349 ) {
54- let t = Transform :: from_kurbo ( & transform . into ( ) ) ;
55- self . encoding . encode_transform ( t ) ;
50+ self . encoding
51+ . encode_transform ( Transform :: from_kurbo ( & transform . into ( ) ) ) ;
5652 self . encoding . encode_fill_style ( style. into ( ) ) ;
57- if self . encode_path ( path_iter, & t , None ) {
53+ if self . encode_path ( path_iter, /*is_fill=*/ true ) {
5854 self . encoding . encode_brush ( & Brush :: from ( brush) , 1.0 )
5955 }
6056 }
@@ -66,24 +62,23 @@ impl Encoding {
6662 brush : & ffi:: Brush ,
6763 path_iter : Pin < & mut ffi:: PathIterator > ,
6864 ) {
69- let t = Transform :: from_kurbo ( & transform. into ( ) ) ;
70- self . encoding . encode_transform ( t) ;
71-
65+ self . encoding
66+ . encode_transform ( Transform :: from_kurbo ( & transform. into ( ) ) ) ;
7267 // TODO: process any dash pattern here using kurbo's dash expander unless Graphite
7368 // handles dashing already.
74- let stroke = style. into ( ) ;
75- self . encoding . encode_stroke_style ( & stroke) ;
76- if self . encode_path ( path_iter, & t, Some ( & stroke) ) {
77- self . encoding . encode_brush ( & Brush :: from ( brush) , 1.0 ) ;
69+ self . encoding . encode_stroke_style ( & style. into ( ) ) ;
70+ if self . encode_path ( path_iter, /*is_fill=*/ false ) {
71+ self . encoding . encode_brush ( & Brush :: from ( brush) , 1.0 )
7872 }
7973 }
8074
8175 pub fn begin_clip ( & mut self , transform : ffi:: Affine , path_iter : Pin < & mut ffi:: PathIterator > ) {
82- let t = Transform :: from_kurbo ( & transform . into ( ) ) ;
83- self . encoding . encode_transform ( t ) ;
76+ self . encoding
77+ . encode_transform ( Transform :: from_kurbo ( & transform . into ( ) ) ) ;
8478 self . encoding . encode_fill_style ( Fill :: NonZero ) ;
85- self . encode_path ( path_iter, & t, None ) ;
86- self . encoding . encode_begin_clip ( Mix :: Clip . into ( ) , /*alpha=*/ 1.0 ) ;
79+ self . encode_path ( path_iter, /*is_fill=*/ true ) ;
80+ self . encoding
81+ . encode_begin_clip ( Mix :: Clip . into ( ) , /*alpha=*/ 1.0 ) ;
8782 }
8883
8984 pub fn end_clip ( & mut self ) {
@@ -98,83 +93,45 @@ impl Encoding {
9893 ) -> Box < RenderConfiguration > {
9994 let mut packed_scene = Vec :: new ( ) ;
10095 let layout = vello_encoding:: resolve_solid_paths_only ( & self . encoding , & mut packed_scene) ;
101- let mut config = RenderConfig :: new ( & layout, width, height, & background. into ( ) ) ;
102-
103- let bump_estimate = self . estimator . tally ( None ) ;
104- //println!("bump: {bump_estimate}");
105- config. buffer_sizes . bin_data = bump_estimate. binning ;
106- config. buffer_sizes . seg_counts = bump_estimate. seg_counts ;
107- config. buffer_sizes . segments = bump_estimate. segments ;
108- config. buffer_sizes . lines = bump_estimate. lines ;
109- config. gpu . binning_size = bump_estimate. binning . len ( ) ;
110- config. gpu . segments_size = bump_estimate. segments . len ( ) ;
111-
96+ let config = RenderConfig :: new ( & layout, width, height, & background. into ( ) ) ;
11297 Box :: new ( RenderConfiguration {
11398 packed_scene,
11499 config,
115100 } )
116101 }
117102
118- fn encode_path (
119- & mut self ,
120- iter : Pin < & mut ffi:: PathIterator > ,
121- transform : & Transform ,
122- stroke : Option < & Stroke > ,
123- ) -> bool {
124- let mut encoder = self . encoding . encode_path ( /*is_fill=*/ stroke. is_none ( ) ) ;
125-
126- // Wrap the input iterator inside a custom iterator, so that the path gets
127- // encoded as the estimator runs through it.
128- let path = IterablePathEncoder { iter, encoder : & mut encoder } ;
129- self . estimator . count_path ( path, transform, stroke) ;
130- encoder. finish ( /*insert_path_marker=*/ true ) != 0
131- }
132- }
133-
134- // This is path element iterator that encodes path elements as it gets polled.
135- struct IterablePathEncoder < ' a , ' b > {
136- iter : Pin < & ' a mut ffi:: PathIterator > ,
137- encoder : & ' a mut PathEncoder < ' b > ,
138- }
139-
140- impl Iterator for IterablePathEncoder < ' _ , ' _ > {
141- type Item = PathEl ;
142-
143- fn next ( & mut self ) -> Option < Self :: Item > {
144- let mut path_el = ffi:: PathElement :: default ( ) ;
145- if !unsafe { self . iter . as_mut ( ) . next_element ( & mut path_el) } {
146- return None ;
147- }
148- Some ( match path_el. verb {
149- ffi:: PathVerb :: MoveTo => {
150- let p = & path_el. points [ 0 ] ;
151- self . encoder . move_to ( p. x , p. y ) ;
152- PathEl :: MoveTo ( p. into ( ) )
153- }
154- ffi:: PathVerb :: LineTo => {
155- let p = & path_el. points [ 1 ] ;
156- self . encoder . line_to ( p. x , p. y ) ;
157- PathEl :: LineTo ( p. into ( ) )
158- }
159- ffi:: PathVerb :: QuadTo => {
160- let p0 = & path_el. points [ 1 ] ;
161- let p1 = & path_el. points [ 2 ] ;
162- self . encoder . quad_to ( p0. x , p0. y , p1. x , p1. y ) ;
163- PathEl :: QuadTo ( p0. into ( ) , p1. into ( ) )
103+ fn encode_path ( & mut self , mut path_iter : Pin < & mut ffi:: PathIterator > , is_fill : bool ) -> bool {
104+ let segments = {
105+ let mut path_encoder = self . encoding . encode_path ( is_fill) ;
106+ let mut path_el = ffi:: PathElement :: default ( ) ;
107+ while unsafe { path_iter. as_mut ( ) . next_element ( & mut path_el) } {
108+ match path_el. verb {
109+ ffi:: PathVerb :: MoveTo => {
110+ let p = & path_el. points [ 0 ] ;
111+ path_encoder. move_to ( p. x , p. y ) ;
112+ }
113+ ffi:: PathVerb :: LineTo => {
114+ let p = & path_el. points [ 1 ] ;
115+ path_encoder. line_to ( p. x , p. y ) ;
116+ }
117+ ffi:: PathVerb :: QuadTo => {
118+ let p0 = & path_el. points [ 1 ] ;
119+ let p1 = & path_el. points [ 2 ] ;
120+ path_encoder. quad_to ( p0. x , p0. y , p1. x , p1. y ) ;
121+ }
122+ ffi:: PathVerb :: CurveTo => {
123+ let p0 = & path_el. points [ 1 ] ;
124+ let p1 = & path_el. points [ 2 ] ;
125+ let p2 = & path_el. points [ 3 ] ;
126+ path_encoder. cubic_to ( p0. x , p0. y , p1. x , p1. y , p2. x , p2. y ) ;
127+ }
128+ ffi:: PathVerb :: Close => path_encoder. close ( ) ,
129+ _ => panic ! ( "invalid path verb" ) ,
130+ }
164131 }
165- ffi:: PathVerb :: CurveTo => {
166- let p0 = & path_el. points [ 1 ] ;
167- let p1 = & path_el. points [ 2 ] ;
168- let p2 = & path_el. points [ 3 ] ;
169- self . encoder . cubic_to ( p0. x , p0. y , p1. x , p1. y , p2. x , p2. y ) ;
170- PathEl :: CurveTo ( p0. into ( ) , p1. into ( ) , p2. into ( ) )
171- }
172- ffi:: PathVerb :: Close => {
173- self . encoder . close ( ) ;
174- PathEl :: ClosePath
175- }
176- _ => panic ! ( "invalid path verb" ) ,
177- } )
132+ path_encoder. finish ( /*insert_path_marker=*/ true )
133+ } ;
134+ segments != 0
178135 }
179136}
180137
0 commit comments