diff --git a/editor/src/node_graph_executor.rs b/editor/src/node_graph_executor.rs index 1622e31cdc..640e776d0e 100644 --- a/editor/src/node_graph_executor.rs +++ b/editor/src/node_graph_executor.rs @@ -146,7 +146,7 @@ impl NodeGraphExecutor { }, time, #[cfg(any(feature = "resvg", feature = "vello"))] - export_format: graphene_std::application_io::ExportFormat::Canvas, + export_format: graphene_std::application_io::ExportFormat::Raster, #[cfg(not(any(feature = "resvg", feature = "vello")))] export_format: graphene_std::application_io::ExportFormat::Svg, render_mode: document.render_mode, @@ -190,10 +190,10 @@ impl NodeGraphExecutor { let size = bounds[1] - bounds[0]; let transform = DAffine2::from_translation(bounds[0]).inverse(); - let export_format = if export_config.file_type == FileType::Svg || cfg!(not(feature = "gpu")) { + let export_format = if export_config.file_type == FileType::Svg { graphene_std::application_io::ExportFormat::Svg } else { - graphene_std::application_io::ExportFormat::Texture + graphene_std::application_io::ExportFormat::Raster }; let render_config = RenderConfig { diff --git a/editor/src/node_graph_executor/runtime.rs b/editor/src/node_graph_executor/runtime.rs index e7a1e0bce6..a58ebd7c9b 100644 --- a/editor/src/node_graph_executor/runtime.rs +++ b/editor/src/node_graph_executor/runtime.rs @@ -7,7 +7,7 @@ use graph_craft::graphene_compiler::Compiler; use graph_craft::proto::GraphErrors; use graph_craft::wasm_application_io::EditorPreferences; use graph_craft::{ProtoNodeIdentifier, concrete}; -use graphene_std::application_io::{ApplicationIo, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig}; +use graphene_std::application_io::{ApplicationIo, ExportFormat, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig}; use graphene_std::bounds::RenderBoundingBox; use graphene_std::memo::IORecord; use graphene_std::ops::Convert; @@ -212,7 +212,19 @@ impl NodeRuntime { self.sender.send_generation_response(CompilationResponse { result, node_graph_errors }); } - GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, render_config, .. }) => { + GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, mut render_config, .. }) => { + // There are cases where we want to export via the svg pipeline eventhough raster was requested. + if matches!(render_config.export_format, ExportFormat::Raster) { + let vello_available = self.editor_api.application_io.as_ref().unwrap().gpu_executor().is_some(); + let use_vello = vello_available && self.editor_api.editor_preferences.use_vello(); + + // On web when the user has disabled vello rendering in the preferences or we are exporting. + // And on all platforms when vello is not supposed to be used. + if !use_vello || cfg!(target_family = "wasm") && render_config.for_export { + render_config.export_format = ExportFormat::Svg; + } + } + let result = self.execute_network(render_config).await; let mut responses = VecDeque::new(); // TODO: Only process monitor nodes if the graph has changed, not when only the Footprint changes diff --git a/node-graph/gapplication-io/src/lib.rs b/node-graph/gapplication-io/src/lib.rs index 0edaf96d23..ed0fdee36c 100644 --- a/node-graph/gapplication-io/src/lib.rs +++ b/node-graph/gapplication-io/src/lib.rs @@ -222,8 +222,7 @@ pub trait GetEditorPreferences { pub enum ExportFormat { #[default] Svg, - Canvas, - Texture, + Raster, } #[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, serde::Serialize, serde::Deserialize)] diff --git a/node-graph/gstd/src/render_node.rs b/node-graph/gstd/src/render_node.rs index ad40d91c6b..ba62ce9399 100644 --- a/node-graph/gstd/src/render_node.rs +++ b/node-graph/gstd/src/render_node.rs @@ -42,7 +42,6 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send + Context -> Table, )] data: impl Node, Output = T>, - editor_api: impl Node, Output = &'a WasmEditorApi>, ) -> RenderIntermediate { let render_params = ctx .vararg(0) @@ -58,39 +57,29 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send + data.collect_metadata(&mut metadata, footprint, None); let contains_artboard = data.contains_artboard(); - let use_vello = { - #[cfg(target_family = "wasm")] - { - let editor_api = editor_api.eval(None).await; - !render_params.for_export && editor_api.editor_preferences.use_vello() && matches!(render_params.render_output_type, graphene_svg_renderer::RenderOutputType::Vello) - } - #[cfg(not(target_family = "wasm"))] - { - let _ = editor_api; - matches!(render_params.render_output_type, graphene_svg_renderer::RenderOutputType::Vello) - } - }; - - if use_vello { - let mut scene = vello::Scene::new(); + match &render_params.render_output_type { + RenderOutputTypeRequest::Vello => { + let mut scene = vello::Scene::new(); - let mut context = wgpu_executor::RenderContext::default(); - data.render_to_vello(&mut scene, Default::default(), &mut context, render_params); + let mut context = wgpu_executor::RenderContext::default(); + data.render_to_vello(&mut scene, Default::default(), &mut context, render_params); - RenderIntermediate { - ty: RenderIntermediateType::Vello(Arc::new((scene, context))), - metadata, - contains_artboard, + RenderIntermediate { + ty: RenderIntermediateType::Vello(Arc::new((scene, context))), + metadata, + contains_artboard, + } } - } else { - let mut render = SvgRender::new(); + RenderOutputTypeRequest::Svg => { + let mut render = SvgRender::new(); - data.render_svg(&mut render, render_params); + data.render_svg(&mut render, render_params); - RenderIntermediate { - ty: RenderIntermediateType::Svg(Arc::new((render.svg.to_svg_string(), render.image_data, render.svg_defs.clone()))), - metadata, - contains_artboard, + RenderIntermediate { + ty: RenderIntermediateType::Svg(Arc::new((render.svg.to_svg_string(), render.image_data, render.svg_defs.clone()))), + metadata, + contains_artboard, + } } } } @@ -105,8 +94,7 @@ async fn create_context<'a: 'n>( let render_output_type = match render_config.export_format { ExportFormat::Svg => RenderOutputTypeRequest::Svg, - ExportFormat::Texture => RenderOutputTypeRequest::Vello, - ExportFormat::Canvas => RenderOutputTypeRequest::Vello, + ExportFormat::Raster => RenderOutputTypeRequest::Vello, }; let render_params = RenderParams { @@ -154,12 +142,7 @@ async fn render<'a: 'n>( None }; - let mut output_format = render_params.render_output_type; - // TODO: Actually request the right thing upfront - if let RenderIntermediateType::Svg(_) = ty { - output_format = RenderOutputTypeRequest::Svg; - } - let data = match (output_format, &ty) { + let data = match (render_params.render_output_type, &ty) { (RenderOutputTypeRequest::Svg, RenderIntermediateType::Svg(svg_data)) => { let mut svg_renderer = SvgRender::new(); if !contains_artboard && !render_params.hide_artboards { diff --git a/node-graph/interpreted-executor/src/util.rs b/node-graph/interpreted-executor/src/util.rs index 76da9a21b6..75278402a4 100644 --- a/node-graph/interpreted-executor/src/util.rs +++ b/node-graph/interpreted-executor/src/util.rs @@ -43,10 +43,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc