Skip to content

Commit 252c25f

Browse files
Seperate wasm and native application io
1 parent 2bade06 commit 252c25f

File tree

30 files changed

+280
-157
lines changed

30 files changed

+280
-157
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ 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" }
9293
graphene-canvas-utils = { path = "node-graph/libraries/canvas-utils" }
9394

9495
# Workspace dependencies

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: 2 additions & 2 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

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
@@ -130,7 +130,7 @@ pub enum FrontendMessage {
130130
TriggerOpen,
131131
TriggerImport,
132132
TriggerSavePreferences {
133-
#[tsify(type = "unknown")]
133+
#[cfg_attr(feature = "wasm", tsify(type = "unknown"))]
134134
preferences: PreferencesMessageHandler,
135135
},
136136
TriggerSaveActiveDocument {

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

Lines changed: 4 additions & 4 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
]
@@ -1011,7 +1011,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
10111011
nodes: [
10121012
DocumentNode {
10131013
inputs: vec![],
1014-
implementation: DocumentNodeImplementation::ProtoNode(wasm_application_io::create_canvas::IDENTIFIER),
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: 3 additions & 3 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};
1010
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

editor/src/node_graph_executor/runtime.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
use super::*;
22
use crate::messages::frontend::utility_types::{ExportBounds, FileType};
33
use glam::{DAffine2, UVec2};
4-
use graph_craft::document::value::TaggedValue;
4+
use graph_craft::application_io::{PlatformApplicationIo, PlatformEditorApi};
5+
use graph_craft::document::value::{RenderOutput, RenderOutputType, TaggedValue};
56
use graph_craft::document::{NodeId, NodeNetwork};
67
use graph_craft::graphene_compiler::Compiler;
78
use graph_craft::proto::GraphErrors;
8-
use graph_craft::wasm_application_io::EditorPreferences;
99
use graph_craft::{ProtoNodeIdentifier, concrete};
1010
use graphene_std::application_io::{ApplicationIo, ExportFormat, ImageTexture, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
1111
use graphene_std::bounds::RenderBoundingBox;
1212
use graphene_std::memo::IORecord;
1313
use graphene_std::ops::Convert;
14+
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
15+
use graphene_std::platform_application_io::canvas_utils::{Canvas, CanvasSurface, CanvasSurfaceHandle};
1416
use graphene_std::raster_types::Raster;
15-
use graphene_std::renderer::{Render, RenderParams, SvgRender};
16-
use graphene_std::renderer::{RenderSvgSegmentList, SvgSegment};
17+
use graphene_std::renderer::{Render, RenderParams, RenderSvgSegmentList, SvgRender, SvgSegment};
1718
use graphene_std::table::{Table, TableRow};
1819
use graphene_std::text::FontCache;
1920
use graphene_std::transform::RenderQuality;
2021
use graphene_std::vector::Vector;
2122
use graphene_std::vector::style::RenderMode;
22-
#[cfg(target_family = "wasm")]
23-
use graphene_std::wasm_application_io::canvas_utils::{Canvas, CanvasSurface, CanvasSurfaceHandle};
24-
use graphene_std::wasm_application_io::{RenderOutputType, WasmApplicationIo, WasmEditorApi};
2523
use graphene_std::{Artboard, Context, Graphic};
2624
use interpreted_executor::dynamic_executor::{DynamicExecutor, IntrospectError, ResolvedDocumentNodeTypesDelta};
2725
use interpreted_executor::util::wrap_network_in_scope;
@@ -30,7 +28,7 @@ use std::sync::Arc;
3028
use std::sync::mpsc::{Receiver, Sender};
3129

3230
/// Persistent data between graph executions. It's updated via message passing from the editor thread with [`GraphRuntimeRequest`]`.
33-
/// Some of these fields are put into a [`WasmEditorApi`] which is passed to the final compiled graph network upon each execution.
31+
/// Some of these fields are put into a [`PlatformEditorApi`] which is passed to the final compiled graph network upon each execution.
3432
/// Once the implementation is finished, this will live in a separate thread. Right now it's part of the main JS thread, but its own separate JS stack frame independent from the editor.
3533
pub struct NodeRuntime {
3634
#[cfg(test)]
@@ -43,7 +41,7 @@ pub struct NodeRuntime {
4341
old_graph: Option<NodeNetwork>,
4442
update_thumbnails: bool,
4543

46-
editor_api: Arc<WasmEditorApi>,
44+
editor_api: Arc<PlatformEditorApi>,
4745
node_graph_errors: GraphErrors,
4846
monitor_nodes: Vec<Vec<NodeId>>,
4947

@@ -59,10 +57,10 @@ pub struct NodeRuntime {
5957
vector_modify: HashMap<NodeId, Vector>,
6058

6159
/// Cached surface for Wasm viewport rendering (reused across frames)
62-
#[cfg(all(target_family = "wasm", feature = "gpu"))]
60+
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
6361
wasm_canvas_cache: CanvasSurfaceHandle,
6462
/// Currently displayed texture, the runtime keeps a reference to it to avoid the texture getting destroyed while it is still in use.
65-
#[cfg(all(target_family = "wasm", feature = "gpu"))]
63+
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
6664
current_viewport_texture: Option<ImageTexture>,
6765
}
6866

@@ -130,7 +128,7 @@ impl NodeRuntime {
130128
old_graph: None,
131129
update_thumbnails: true,
132130

133-
editor_api: WasmEditorApi {
131+
editor_api: PlatformEditorApi {
134132
font_cache: FontCache::default(),
135133
editor_preferences: Box::new(EditorPreferences::default()),
136134
node_graph_message_sender: Box::new(InternalNodeGraphUpdateSender(sender)),
@@ -156,11 +154,11 @@ impl NodeRuntime {
156154

157155
pub async fn run(&mut self) -> Option<ImageTexture> {
158156
if self.editor_api.application_io.is_none() {
159-
self.editor_api = WasmEditorApi {
157+
self.editor_api = PlatformEditorApi {
160158
#[cfg(all(not(test), target_family = "wasm"))]
161-
application_io: Some(WasmApplicationIo::new().await.into()),
159+
application_io: Some(PlatformApplicationIo::new().await.into()),
162160
#[cfg(any(test, not(target_family = "wasm")))]
163-
application_io: Some(WasmApplicationIo::new_offscreen().await.into()),
161+
application_io: Some(PlatformApplicationIo::new_offscreen().await.into()),
164162
font_cache: self.editor_api.font_cache.clone(),
165163
node_graph_message_sender: Box::new(self.sender.clone()),
166164
editor_preferences: Box::new(self.editor_preferences.clone()),
@@ -210,7 +208,7 @@ impl NodeRuntime {
210208
for request in requests {
211209
match request {
212210
GraphRuntimeRequest::FontCacheUpdate(font_cache) => {
213-
self.editor_api = WasmEditorApi {
211+
self.editor_api = PlatformEditorApi {
214212
font_cache,
215213
application_io: self.editor_api.application_io.clone(),
216214
node_graph_message_sender: Box::new(self.sender.clone()),
@@ -224,7 +222,7 @@ impl NodeRuntime {
224222
}
225223
GraphRuntimeRequest::EditorPreferencesUpdate(preferences) => {
226224
self.editor_preferences = preferences.clone();
227-
self.editor_api = WasmEditorApi {
225+
self.editor_api = PlatformEditorApi {
228226
font_cache: self.editor_api.font_cache.clone(),
229227
application_io: self.editor_api.application_io.clone(),
230228
node_graph_message_sender: Box::new(self.sender.clone()),
@@ -531,10 +529,10 @@ pub async fn replace_node_runtime(runtime: NodeRuntime) -> Option<NodeRuntime> {
531529
let mut node_runtime = NODE_RUNTIME.lock();
532530
node_runtime.replace(runtime)
533531
}
534-
pub async fn replace_application_io(application_io: WasmApplicationIo) {
532+
pub async fn replace_application_io(application_io: PlatformApplicationIo) {
535533
let mut node_runtime = NODE_RUNTIME.lock();
536534
if let Some(node_runtime) = &mut *node_runtime {
537-
node_runtime.editor_api = WasmEditorApi {
535+
node_runtime.editor_api = PlatformEditorApi {
538536
font_cache: node_runtime.editor_api.font_cache.clone(),
539537
application_io: Some(application_io.into()),
540538
node_graph_message_sender: Box::new(node_runtime.sender.clone()),

0 commit comments

Comments
 (0)