@@ -36,20 +36,23 @@ 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 . render_to_pixmap ( & mut self . resources , & mut pixmap) ;
4548 pixmap
4649 }
4750}
4851
4952impl RenderContext for VelloCpuScenePainter { }
5053impl PaintScene for VelloCpuScenePainter {
5154 fn reset ( & mut self ) {
52- self . 0 . reset ( ) ;
55+ self . render_ctx . reset ( ) ;
5356 }
5457
5558 fn push_layer (
@@ -59,8 +62,8 @@ impl PaintScene for VelloCpuScenePainter {
5962 transform : Affine ,
6063 clip : & impl Shape ,
6164 ) {
62- self . 0 . set_transform ( transform) ;
63- self . 0 . push_layer (
65+ self . render_ctx . set_transform ( transform) ;
66+ self . render_ctx . push_layer (
6467 Some ( & clip. into_path ( DEFAULT_TOLERANCE ) ) ,
6568 Some ( blend. into ( ) ) ,
6669 Some ( alpha) ,
@@ -70,12 +73,13 @@ impl PaintScene for VelloCpuScenePainter {
7073 }
7174
7275 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 ) ) ;
76+ self . render_ctx . set_transform ( transform) ;
77+ self . render_ctx
78+ . push_clip_layer ( & clip. into_path ( DEFAULT_TOLERANCE ) ) ;
7579 }
7680
7781 fn pop_layer ( & mut self ) {
78- self . 0 . pop_layer ( ) ;
82+ self . render_ctx . pop_layer ( ) ;
7983 }
8084
8185 fn stroke < ' a > (
@@ -86,13 +90,14 @@ impl PaintScene for VelloCpuScenePainter {
8690 brush_transform : Option < Affine > ,
8791 shape : & impl Shape ,
8892 ) {
89- self . 0 . set_transform ( transform) ;
90- self . 0 . set_stroke ( style. clone ( ) ) ;
91- self . 0
93+ self . render_ctx . set_transform ( transform) ;
94+ self . render_ctx . set_stroke ( style. clone ( ) ) ;
95+ self . render_ctx
9296 . set_paint ( anyrender_paint_to_vello_cpu_paint ( paint. into ( ) ) ) ;
93- self . 0
97+ self . render_ctx
9498 . set_paint_transform ( brush_transform. unwrap_or ( Affine :: IDENTITY ) ) ;
95- self . 0 . stroke_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
99+ self . render_ctx
100+ . stroke_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
96101 }
97102
98103 fn fill < ' a > (
@@ -103,13 +108,14 @@ impl PaintScene for VelloCpuScenePainter {
103108 brush_transform : Option < Affine > ,
104109 shape : & impl Shape ,
105110 ) {
106- self . 0 . set_transform ( transform) ;
107- self . 0 . set_fill_rule ( style) ;
108- self . 0
111+ self . render_ctx . set_transform ( transform) ;
112+ self . render_ctx . set_fill_rule ( style) ;
113+ self . render_ctx
109114 . set_paint ( anyrender_paint_to_vello_cpu_paint ( paint. into ( ) ) ) ;
110- self . 0
115+ self . render_ctx
111116 . set_paint_transform ( brush_transform. unwrap_or ( Affine :: IDENTITY ) ) ;
112- self . 0 . fill_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
117+ self . render_ctx
118+ . fill_path ( & shape. into_path ( DEFAULT_TOLERANCE ) ) ;
113119 }
114120
115121 fn draw_glyphs < ' a , ' s : ' a > (
@@ -123,10 +129,10 @@ impl PaintScene for VelloCpuScenePainter {
123129 _brush_alpha : f32 ,
124130 transform : Affine ,
125131 glyph_transform : Option < Affine > ,
126- glyphs : impl Iterator < Item = anyrender:: Glyph > ,
132+ glyphs : impl Iterator < Item = anyrender:: Glyph > + Clone ,
127133 ) {
128- self . 0 . set_transform ( transform) ;
129- self . 0
134+ self . render_ctx . set_transform ( transform) ;
135+ self . render_ctx
130136 . set_paint ( anyrender_paint_to_vello_cpu_paint ( paint. into ( ) ) ) ;
131137
132138 fn into_vello_cpu_glyph ( g : anyrender:: Glyph ) -> vello_cpu:: Glyph {
@@ -140,19 +146,19 @@ impl PaintScene for VelloCpuScenePainter {
140146 let style: StyleRef < ' a > = style. into ( ) ;
141147 match style {
142148 StyleRef :: Fill ( fill) => {
143- self . 0 . set_fill_rule ( fill) ;
144- self . 0
145- . glyph_run ( font)
149+ self . render_ctx . set_fill_rule ( fill) ;
150+ self . render_ctx
151+ . glyph_run ( & mut self . resources , font)
146152 . font_size ( font_size)
147153 . hint ( hint)
148154 . normalized_coords ( normalized_coords)
149155 . glyph_transform ( glyph_transform. unwrap_or_default ( ) )
150156 . fill_glyphs ( glyphs. map ( into_vello_cpu_glyph) ) ;
151157 }
152158 StyleRef :: Stroke ( stroke) => {
153- self . 0 . set_stroke ( stroke. clone ( ) ) ;
154- self . 0
155- . glyph_run ( font)
159+ self . render_ctx . set_stroke ( stroke. clone ( ) ) ;
160+ self . render_ctx
161+ . glyph_run ( & mut self . resources , font)
156162 . font_size ( font_size)
157163 . hint ( hint)
158164 . normalized_coords ( normalized_coords)
@@ -169,9 +175,9 @@ impl PaintScene for VelloCpuScenePainter {
169175 radius : f64 ,
170176 std_dev : f64 ,
171177 ) {
172- self . 0 . set_transform ( transform) ;
173- self . 0 . set_paint ( PaintType :: Solid ( color) ) ;
174- self . 0
178+ self . render_ctx . set_transform ( transform) ;
179+ self . render_ctx . set_paint ( PaintType :: Solid ( color) ) ;
180+ self . render_ctx
175181 . fill_blurred_rounded_rect ( & rect, radius as f32 , std_dev as f32 ) ;
176182 }
177183}
0 commit comments