Skip to content

Commit 661e8bc

Browse files
Remove surface and window from ApplicationIo (#3941)
* Remove surface and window from ApplicationIo * Seperate Wasm and Native ApplicationIo * Fix warnings * Fix tests * Remove redundant PlatformApplicationIo::new_offscreen * Fixup * Remove unused From implementaitions for ApplicationIo
1 parent b100892 commit 661e8bc

File tree

36 files changed

+715
-772
lines changed

36 files changed

+715
-772
lines changed

Cargo.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ interpreted-executor = { path = "node-graph/interpreted-executor" }
8989
node-macro = { path = "node-graph/node-macro" }
9090
wgpu-executor = { path = "node-graph/libraries/wgpu-executor" }
9191
graphite-proc-macros = { path = "proc-macros" }
92+
graphite-editor = { path = "editor" }
93+
graphene-canvas-utils = { path = "node-graph/libraries/canvas-utils" }
9294

9395
# Workspace dependencies
9496
rustc-hash = "2.0"

desktop/wrapper/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ gpu = ["graphite-editor/gpu", "graphene-std/shader-nodes"]
1313

1414
[dependencies]
1515
# Local dependencies
16-
graphite-editor = { path = "../../editor", features = [
17-
"gpu",
18-
] }
16+
graphite-editor = { workspace = true }
1917
graphene-std = { workspace = true }
2018
graph-craft = { workspace = true }
2119
wgpu-executor = { workspace = true }

desktop/wrapper/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use graph_craft::wasm_application_io::WasmApplicationIo;
1+
use graph_craft::application_io::PlatformApplicationIo;
22
use graphite_editor::application::{Editor, Environment, Host, Platform};
33
use graphite_editor::messages::prelude::{FrontendMessage, Message};
44
use message_dispatcher::DesktopWrapperMessageDispatcher;
@@ -38,7 +38,7 @@ impl DesktopWrapper {
3838
}
3939

4040
pub fn init(&self, wgpu_context: WgpuContext) {
41-
let application_io = WasmApplicationIo::new_with_context(wgpu_context);
41+
let application_io = PlatformApplicationIo::new_with_context(wgpu_context);
4242
futures::executor::block_on(graphite_editor::node_graph_executor::replace_application_io(application_io));
4343
}
4444

@@ -51,7 +51,7 @@ impl DesktopWrapper {
5151
pub async fn execute_node_graph() -> NodeGraphExecutionResult {
5252
let result = graphite_editor::node_graph_executor::run_node_graph().await;
5353
match result {
54-
(true, texture) => NodeGraphExecutionResult::HasRun(texture.map(|t| t.texture)),
54+
(true, texture) => NodeGraphExecutionResult::HasRun(texture.map(Into::into)),
5555
(false, _) => NodeGraphExecutionResult::NotRun,
5656
}
5757
}

editor/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ repository = "https://github.com/GraphiteEditor/Graphite"
1111
license = "Apache-2.0"
1212

1313
[features]
14-
default = ["wasm", "gpu"]
15-
wasm = ["wasm-bindgen", "graphene-std/wasm"]
16-
gpu = ["interpreted-executor/gpu", "wgpu-executor"]
14+
default = ["gpu"]
15+
wasm = ["graphene-std/wasm", "interpreted-executor/wasm", "dep:wasm-bindgen"]
16+
gpu = ["interpreted-executor/gpu", "dep:wgpu-executor"]
1717

1818
[dependencies]
1919
# Local dependencies

editor/src/messages/frontend/frontend_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub enum FrontendMessage {
131131
TriggerOpen,
132132
TriggerImport,
133133
TriggerSavePreferences {
134-
#[tsify(type = "unknown")]
134+
#[cfg_attr(feature = "wasm", tsify(type = "unknown"))]
135135
preferences: PreferencesMessageHandler,
136136
},
137137
TriggerSaveWorkspaceLayout {

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -947,12 +947,12 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
947947
nodes: [
948948
DocumentNode {
949949
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::scope("editor-api"), NodeInput::import(concrete!(String), 1)],
950-
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::load_resource::IDENTIFIER),
950+
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::load_resource::IDENTIFIER),
951951
..Default::default()
952952
},
953953
DocumentNode {
954954
inputs: vec![NodeInput::node(NodeId(0), 0)],
955-
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::decode_image::IDENTIFIER),
955+
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::decode_image::IDENTIFIER),
956956
..Default::default()
957957
},
958958
]
@@ -1010,8 +1010,8 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
10101010
exports: vec![NodeInput::node(NodeId(2), 0)],
10111011
nodes: [
10121012
DocumentNode {
1013-
inputs: vec![NodeInput::scope("editor-api")],
1014-
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::create_surface::IDENTIFIER),
1013+
inputs: vec![],
1014+
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::create_canvas::IDENTIFIER),
10151015
skip_deduplication: true,
10161016
..Default::default()
10171017
},
@@ -1022,7 +1022,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
10221022
},
10231023
DocumentNode {
10241024
inputs: vec![NodeInput::import(generic!(T), 0), NodeInput::import(concrete!(Footprint), 1), NodeInput::node(NodeId(1), 0)],
1025-
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::rasterize::IDENTIFIER),
1025+
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::rasterize::IDENTIFIER),
10261026
..Default::default()
10271027
},
10281028
]

editor/src/messages/portfolio/document/overlays/utility_functions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ use graphene_std::vector::misc::ManipulatorPointId;
1111
use graphene_std::vector::{PointId, SegmentId, Vector};
1212
use std::collections::HashMap;
1313
use std::sync::{LazyLock, Mutex};
14+
#[cfg(target_family = "wasm")]
1415
use wasm_bindgen::JsCast;
1516

17+
#[cfg(target_family = "wasm")]
1618
pub fn overlay_canvas_element() -> Option<web_sys::HtmlCanvasElement> {
1719
let window = web_sys::window()?;
1820
let document = window.document()?;
1921
let canvas = document.query_selector("[data-overlays-canvas]").ok().flatten()?;
2022
canvas.dyn_into::<web_sys::HtmlCanvasElement>().ok()
2123
}
2224

25+
#[cfg(target_family = "wasm")]
2326
pub fn overlay_canvas_context() -> web_sys::CanvasRenderingContext2d {
2427
let create_context = || {
2528
let context = overlay_canvas_element()?.get_context("2d").ok().flatten()?;

editor/src/messages/preferences/preferences_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::messages::portfolio::document::utility_types::wires::GraphWireStyle;
44
use crate::messages::preferences::SelectionMode;
55
use crate::messages::prelude::*;
66
use crate::messages::tool::utility_types::ToolType;
7-
use graph_craft::wasm_application_io::EditorPreferences;
7+
use graph_craft::application_io::EditorPreferences;
88

99
#[derive(ExtractField)]
1010
pub struct PreferencesMessageContext<'a> {
@@ -51,7 +51,7 @@ impl PreferencesMessageHandler {
5151
}
5252

5353
pub fn supports_wgpu(&self) -> bool {
54-
graph_craft::wasm_application_io::wgpu_available().unwrap_or_default()
54+
graph_craft::application_io::wgpu_available().unwrap_or_default()
5555
}
5656
}
5757

editor/src/node_graph_executor.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use crate::messages::frontend::utility_types::{ExportBounds, FileType};
22
use crate::messages::prelude::*;
33
use glam::{DAffine2, DVec2, UVec2};
4-
use graph_craft::document::value::{RenderOutput, TaggedValue};
4+
use graph_craft::application_io::EditorPreferences;
5+
use graph_craft::document::value::{RenderOutput, RenderOutputType, TaggedValue};
56
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
67
use graph_craft::proto::GraphErrors;
7-
use graph_craft::wasm_application_io::EditorPreferences;
88
use graphene_std::application_io::{NodeGraphUpdateMessage, RenderConfig, TimingInformation};
99
use graphene_std::raster::{CPU, Raster};
10-
use graphene_std::renderer::{RenderMetadata, format_transform_matrix};
10+
use graphene_std::renderer::RenderMetadata;
1111
use graphene_std::text::FontCache;
1212
use graphene_std::transform::Footprint;
1313
use graphene_std::vector::Vector;
14-
use graphene_std::wasm_application_io::RenderOutputType;
1514
use interpreted_executor::dynamic_executor::ResolvedDocumentNodeTypesDelta;
1615

1716
mod runtime_io;
@@ -380,6 +379,7 @@ impl NodeGraphExecutor {
380379
let (data, width, height) = raster.to_flat_u8();
381380
responses.add(EyedropperToolMessage::PreviewImage { data, width, height });
382381
}
382+
NodeGraphUpdate::NodeGraphUpdateMessage(_) => {}
383383
}
384384
}
385385

@@ -397,12 +397,11 @@ impl NodeGraphExecutor {
397397
responses.add(FrontendMessage::UpdateImageData { image_data });
398398
responses.add(FrontendMessage::UpdateDocumentArtwork { svg });
399399
}
400-
RenderOutputType::CanvasFrame(frame) => {
401-
let matrix = format_transform_matrix(frame.transform);
402-
let transform = if matrix.is_empty() { String::new() } else { format!(" transform=\"{matrix}\"") };
400+
#[cfg(target_family = "wasm")]
401+
RenderOutputType::CanvasFrame { canvas_id, resolution } => {
403402
let svg = format!(
404-
r#"<svg><foreignObject width="{}" height="{}"{transform}><div data-canvas-placeholder="{}" data-is-viewport="true"></div></foreignObject></svg>"#,
405-
frame.resolution.x, frame.resolution.y, frame.surface_id.0,
403+
r#"<svg><foreignObject width="{}" height="{}"><div data-canvas-placeholder="{}" data-is-viewport="true"></div></foreignObject></svg>"#,
404+
resolution.x, resolution.y, canvas_id,
406405
);
407406
responses.add(FrontendMessage::UpdateDocumentArtwork { svg });
408407
}

0 commit comments

Comments
 (0)