@@ -3,6 +3,7 @@ pub use graph_craft::document::value::RenderOutputType;
33pub use graph_craft:: wasm_application_io:: * ;
44use graphene_application_io:: { ApplicationIo , ExportFormat , ImageTexture , RenderConfig , SurfaceFrame } ;
55use graphene_core:: gradient:: GradientStops ;
6+ use graphene_core:: ops:: Convert ;
67use graphene_core:: raster:: image:: Image ;
78use graphene_core:: raster_types:: { CPU , Raster } ;
89use graphene_core:: table:: Table ;
@@ -44,7 +45,6 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
4445 data : impl Node < Context < ' static > , Output = T > ,
4546 editor_api : impl Node < Context < ' static > , Output = & ' a WasmEditorApi > ,
4647) -> RenderIntermediate {
47- let mut render = SvgRender :: new ( ) ;
4848 let render_params = ctx
4949 . vararg ( 0 )
5050 . expect ( "Did not find var args" )
@@ -61,7 +61,9 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
6161
6262 let editor_api = editor_api. eval ( None ) . await ;
6363
64- if !render_params. for_export && editor_api. editor_preferences . use_vello ( ) && matches ! ( render_params. render_output_type, graphene_svg_renderer:: RenderOutputType :: Vello ) {
64+ if ( !render_params. for_export && editor_api. editor_preferences . use_vello ( ) && matches ! ( render_params. render_output_type, graphene_svg_renderer:: RenderOutputType :: Texture ) )
65+ || matches ! ( render_params. render_output_type, RenderOutputTypeRequest :: Buffer )
66+ {
6567 let mut scene = vello:: Scene :: new ( ) ;
6668
6769 let mut context = wgpu_executor:: RenderContext :: default ( ) ;
@@ -73,6 +75,8 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
7375 contains_artboard,
7476 }
7577 } else {
78+ let mut render = SvgRender :: new ( ) ;
79+
7680 data. render_svg ( & mut render, render_params) ;
7781
7882 RenderIntermediate {
@@ -93,11 +97,11 @@ async fn create_context<'a: 'n>(
9397
9498 let render_output_type = match render_config. export_format {
9599 ExportFormat :: Svg => RenderOutputTypeRequest :: Svg ,
96- ExportFormat :: Png { .. } => todo ! ( ) ,
97- ExportFormat :: Jpeg => todo ! ( ) ,
98- ExportFormat :: Canvas => RenderOutputTypeRequest :: Vello ,
99- ExportFormat :: Texture => RenderOutputTypeRequest :: Vello ,
100+ ExportFormat :: Buffer => RenderOutputTypeRequest :: Buffer ,
101+ ExportFormat :: Texture => RenderOutputTypeRequest :: Texture ,
102+ ExportFormat :: Canvas => RenderOutputTypeRequest :: Texture ,
100103 } ;
104+
101105 let render_params = RenderParams {
102106 render_mode : render_config. render_mode ,
103107 hide_artboards : render_config. hide_artboards ,
@@ -106,6 +110,7 @@ async fn create_context<'a: 'n>(
106110 footprint : Footprint :: default ( ) ,
107111 ..Default :: default ( )
108112 } ;
113+
109114 let ctx = OwnedContextImpl :: default ( )
110115 . with_footprint ( footprint)
111116 . with_real_time ( render_config. time . time )
@@ -173,7 +178,7 @@ async fn render<'a: 'n>(
173178 image_data : svg_renderer. image_data ,
174179 }
175180 }
176- ( RenderOutputTypeRequest :: Vello , RenderIntermediateType :: Vello ( vello_data) ) => {
181+ ( render_output_request_type , RenderIntermediateType :: Vello ( vello_data) ) => {
177182 let Some ( exec) = editor_api. application_io . as_ref ( ) . unwrap ( ) . gpu_executor ( ) else {
178183 unreachable ! ( "Attempted to render with Vello when no GPU executor is available" ) ;
179184 } ;
@@ -198,6 +203,23 @@ async fn render<'a: 'n>(
198203 if !contains_artboard && !render_params. hide_artboards {
199204 background = Color :: WHITE ;
200205 }
206+
207+ if matches ! ( render_output_request_type, RenderOutputTypeRequest :: Buffer ) {
208+ let texture = exec
209+ . render_vello_scene_to_texture ( & scene, footprint. resolution , context, background)
210+ . await
211+ . expect ( "Failed to render Vello scene" ) ;
212+
213+ let raster_cpu = Raster :: new_gpu ( texture) . convert ( Footprint :: BOUNDLESS , exec) . await ;
214+
215+ let ( data, width, height) = raster_cpu. to_flat_u8 ( ) ;
216+
217+ return RenderOutput {
218+ data : RenderOutputType :: Buffer { data, width, height } ,
219+ metadata,
220+ } ;
221+ }
222+
201223 if let Some ( surface_handle) = surface_handle {
202224 exec. render_vello_scene ( & scene, & surface_handle, footprint. resolution , context, background)
203225 . await
0 commit comments