Desktop: Fix non-Vello render mode (#3259)

* fix non vello render mode

* move export overide desision from reneder node to node runtime

* fix

* cleanup

* Fix typo and cleanup export logic

---------

Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
Timon 2025-10-09 11:31:35 +02:00 committed by GitHub
parent 5df3196b58
commit e39fbb8903
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 50 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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)]

View File

@ -42,7 +42,6 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
Context -> Table<GradientStops>,
)]
data: impl Node<Context<'static>, Output = T>,
editor_api: impl Node<Context<'static>, Output = &'a WasmEditorApi>,
) -> RenderIntermediate {
let render_params = ctx
.vararg(0)
@ -58,20 +57,8 @@ 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 {
match &render_params.render_output_type {
RenderOutputTypeRequest::Vello => {
let mut scene = vello::Scene::new();
let mut context = wgpu_executor::RenderContext::default();
@ -82,7 +69,8 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
metadata,
contains_artboard,
}
} else {
}
RenderOutputTypeRequest::Svg => {
let mut render = SvgRender::new();
data.render_svg(&mut render, render_params);
@ -94,6 +82,7 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
}
}
}
}
#[node_macro::node(category(""))]
async fn create_context<'a: 'n>(
@ -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 {

View File

@ -43,10 +43,7 @@ pub fn wrap_network_in_scope(mut network: NodeNetwork, editor_api: Arc<WasmEdito
},
DocumentNode {
call_argument: concrete!(Context),
inputs: vec![
NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0),
NodeInput::scope("editor-api"),
],
inputs: vec![NodeInput::import(graphene_core::Type::Fn(Box::new(concrete!(Context)), Box::new(generic!(T))), 0)],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render_intermediate::IDENTIFIER),
context_features: graphene_std::ContextDependencies {
extract: ContextFeatures::VARARGS,