@@ -36,20 +36,24 @@ fn convert_image_cached(image: &peniko::ImageData) -> ImageSource {
3636 . clone ( )
3737}
3838
39- pub struct VelloCpuScenePainter ( pub vello_cpu:: RenderContext ) ;
39+ pub struct VelloCpuScenePainter {
40+ pub render_ctx : vello_cpu:: RenderContext ,
41+ pub resources : vello_cpu:: Resources ,
42+ }
4043
4144impl VelloCpuScenePainter {
42- pub fn finish ( self ) -> Pixmap {
43- let mut pixmap = Pixmap :: new ( self . 0 . width ( ) , self . 0 . height ( ) ) ;
44- self . 0 . render_to_pixmap ( & mut pixmap) ;
45+ pub fn finish ( mut self ) -> Pixmap {
46+ let mut pixmap = Pixmap :: new ( self . render_ctx . width ( ) , self . render_ctx . height ( ) ) ;
47+ self . render_ctx
48+ . render_to_pixmap ( & mut self . resources , & mut pixmap) ;
4549 pixmap
4650 }
4751}
4852
4953impl RenderContext for VelloCpuScenePainter { }
5054impl PaintScene for VelloCpuScenePainter {
5155 fn reset ( & mut self ) {
52- self . 0 . reset ( ) ;
56+ self . render_ctx . reset ( ) ;
5357 }
5458
5559 fn push_layer (
@@ -59,8 +63,8 @@ impl PaintScene for VelloCpuScenePainter {
5963 transform : Affine ,
6064 clip : & impl Shape ,
6165 ) {
62- self . 0 . set_transform ( transform) ;
63- self . 0 . push_layer (
66+ self . render_ctx . set_transform ( transform) ;
67+ self . render_ctx . push_layer (
6468 Some ( & clip. into_path ( DEFAULT_TOLERANCE ) ) ,
6569 Some ( blend. into ( ) ) ,
6670 Some ( alpha) ,
@@ -70,12 +74,13 @@ impl PaintScene for VelloCpuScenePainter {
7074 }
7175
7276 fn push_clip_layer ( & mut self , transform : Affine , clip : & impl Shape ) {
73- self . 0 . set_transform ( transform) ;
74- self . 0 . push_clip_layer ( & clip. into_path ( DEFAULT_TOLERANCE ) ) ;
77+ self . render_ctx . set_transform ( transform) ;
78+ self . render_ctx
79+ . push_clip_layer ( & clip. into_path ( DEFAULT_TOLERANCE ) ) ;
7580 }
7681
7782 fn pop_layer ( & mut self ) {
78- self . 0 . pop_layer ( ) ;
83+ self . render_ctx . pop_layer ( ) ;
7984 }
8085
8186 fn stroke < ' a > (
@@ -86,13 +91,14 @@ impl PaintScene for VelloCpuScenePainter {
8691 brush_transform : Option < Affine > ,
8792 shape : & impl Shape ,
8893 ) {
89- self . 0 . set_transform ( transform) ;
90- self . 0 . set_stroke ( style. clone ( ) ) ;
91- self . 0
94+ self . render_ctx . set_transform ( transform) ;
95+ self . render_ctx . set_stroke ( style. clone ( ) ) ;
96+ self . render_ctx
9297 . set_paint ( anyrender_paint_to_vello_cpu_paint ( paint. into ( ) ) ) ;
93- self . 0
98+ self . render_ctx
9499 . set_paint_transform ( brush_transform. unwrap_or ( Affine :: IDENTITY ) ) ;
95- self . 0 . stroke_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
100+ self . render_ctx
101+ . stroke_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
96102 }
97103
98104 fn fill < ' a > (
@@ -103,13 +109,14 @@ impl PaintScene for VelloCpuScenePainter {
103109 brush_transform : Option < Affine > ,
104110 shape : & impl Shape ,
105111 ) {
106- self . 0 . set_transform ( transform) ;
107- self . 0 . set_fill_rule ( style) ;
108- self . 0
112+ self . render_ctx . set_transform ( transform) ;
113+ self . render_ctx . set_fill_rule ( style) ;
114+ self . render_ctx
109115 . set_paint ( anyrender_paint_to_vello_cpu_paint ( paint. into ( ) ) ) ;
110- self . 0
116+ self . render_ctx
111117 . set_paint_transform ( brush_transform. unwrap_or ( Affine :: IDENTITY ) ) ;
112- self . 0 . fill_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
118+ self . render_ctx
119+ . fill_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
113120 }
114121
115122 fn draw_glyphs < ' a , ' s : ' a > (
@@ -123,10 +130,10 @@ impl PaintScene for VelloCpuScenePainter {
123130 _brush_alpha : f32 ,
124131 transform : Affine ,
125132 glyph_transform : Option < Affine > ,
126- glyphs : impl Iterator < Item = anyrender:: Glyph > ,
133+ glyphs : impl Iterator < Item = anyrender:: Glyph > + Clone ,
127134 ) {
128- self . 0 . set_transform ( transform) ;
129- self . 0
135+ self . render_ctx . set_transform ( transform) ;
136+ self . render_ctx
130137 . set_paint ( anyrender_paint_to_vello_cpu_paint ( paint. into ( ) ) ) ;
131138
132139 fn into_vello_cpu_glyph ( g : anyrender:: Glyph ) -> vello_cpu:: Glyph {
@@ -140,19 +147,19 @@ impl PaintScene for VelloCpuScenePainter {
140147 let style: StyleRef < ' a > = style. into ( ) ;
141148 match style {
142149 StyleRef :: Fill ( fill) => {
143- self . 0 . set_fill_rule ( fill) ;
144- self . 0
145- . glyph_run ( font)
150+ self . render_ctx . set_fill_rule ( fill) ;
151+ self . render_ctx
152+ . glyph_run ( & mut self . resources , font)
146153 . font_size ( font_size)
147154 . hint ( hint)
148155 . normalized_coords ( normalized_coords)
149156 . glyph_transform ( glyph_transform. unwrap_or_default ( ) )
150157 . fill_glyphs ( glyphs. map ( into_vello_cpu_glyph) ) ;
151158 }
152159 StyleRef :: Stroke ( stroke) => {
153- self . 0 . set_stroke ( stroke. clone ( ) ) ;
154- self . 0
155- . glyph_run ( font)
160+ self . render_ctx . set_stroke ( stroke. clone ( ) ) ;
161+ self . render_ctx
162+ . glyph_run ( & mut self . resources , font)
156163 . font_size ( font_size)
157164 . hint ( hint)
158165 . normalized_coords ( normalized_coords)
@@ -169,9 +176,9 @@ impl PaintScene for VelloCpuScenePainter {
169176 radius : f64 ,
170177 std_dev : f64 ,
171178 ) {
172- self . 0 . set_transform ( transform) ;
173- self . 0 . set_paint ( PaintType :: Solid ( color) ) ;
174- self . 0
179+ self . render_ctx . set_transform ( transform) ;
180+ self . render_ctx . set_paint ( PaintType :: Solid ( color) ) ;
181+ self . render_ctx
175182 . fill_blurred_rounded_rect ( & rect, radius as f32 , std_dev as f32 ) ;
176183 }
177184}
0 commit comments