Skip to content

Extract gapplication_io from gcore #2742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"proc-macros",
"frontend/wasm",
"frontend/src-tauri",
"node-graph/gapplication-io",
"node-graph/gcore",
"node-graph/gstd",
"node-graph/graph-craft",
Expand Down Expand Up @@ -35,6 +36,7 @@ bezier-rs = { path = "libraries/bezier-rs", features = ["dyn-any", "serde"] }
dyn-any = { path = "libraries/dyn-any", features = ["derive", "glam", "reqwest", "log-bad-types", "rc"] }
math-parser = { path = "libraries/math-parser" }
path-bool = { path = "libraries/path-bool" }
graphene-application-io = { path = "node-graph/gapplication-io" }
graphene-core = { path = "node-graph/gcore" }
graph-craft = { path = "node-graph/graph-craft" }
graphene-std = { path = "node-graph/gstd" }
Expand Down
2 changes: 1 addition & 1 deletion frontend/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ editor = { path = "../../editor", package = "graphite-editor", features = [
# Workspace dependencies
graph-craft = { workspace = true }
log = { workspace = true }
graphene-core = { workspace = true, features = ["wasm"] }
graphene-core = { workspace = true }
serde = { workspace = true }
wasm-bindgen = { workspace = true }
serde-wasm-bindgen = { workspace = true }
Expand Down
25 changes: 25 additions & 0 deletions node-graph/gapplication-io/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "graphene-application-io"
version = "0.1.0"
edition = "2024"
description = "graphene application io interface"
authors = ["Graphite Authors <[email protected]>"]
license = "MIT OR Apache-2.0"

[features]
wasm = ["dep:web-sys"]
wgpu = ["dep:wgpu"]

[dependencies]
# Local dependencies
dyn-any = { workspace = true }
graphene-core = { workspace = true }

# Workspace dependencies
glam = { workspace = true }
serde = { workspace = true }
log = { workspace = true }

# Optional workspace dependencies
web-sys = { workspace = true, optional = true }
wgpu = { workspace = true, optional = true }
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::text::FontCache;
use crate::transform::Footprint;
use crate::vector::style::ViewMode;
use dyn_any::{DynAny, StaticType, StaticTypeSized};
use glam::{DAffine2, UVec2};
use graphene_core::text::FontCache;
use graphene_core::transform::Footprint;
use graphene_core::vector::style::ViewMode;
use std::fmt::Debug;
use std::future::Future;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -131,6 +131,11 @@ unsafe impl<T: 'static> StaticType for SurfaceHandleFrame<T> {
type Static = SurfaceHandleFrame<T>;
}

#[cfg(feature = "wasm")]
pub type WasmSurfaceHandle = SurfaceHandle<web_sys::HtmlCanvasElement>;
#[cfg(feature = "wasm")]
pub type WasmSurfaceHandleFrame = SurfaceHandleFrame<web_sys::HtmlCanvasElement>;

// TODO: think about how to automatically clean up memory
/*
impl<'a, Surface> Drop for SurfaceHandle<'a, Surface> {
Expand Down
4 changes: 1 addition & 3 deletions node-graph/gcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ authors = ["Graphite Authors <[email protected]>"]
license = "MIT OR Apache-2.0"

[features]
default = ["serde", "wasm"]
default = ["serde"]
nightly = []
type_id_logging = []
wasm = ["web-sys"]
wgpu = ["dep:wgpu"]
vello = ["dep:vello", "bezier-rs/kurbo", "wgpu"]
dealloc_nodes = []
Expand Down Expand Up @@ -47,7 +46,6 @@ base64 = { workspace = true }
serde = { workspace = true, optional = true }
vello = { workspace = true, optional = true }
wgpu = { workspace = true, optional = true }
web-sys = { workspace = true, optional = true }

[dev-dependencies]
# Workspace dependencies
Expand Down
2 changes: 1 addition & 1 deletion node-graph/gcore/src/graphic_element/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl Default for SvgRender {

#[derive(Clone, Debug, Default)]
pub struct RenderContext {
#[cfg(feature = "wgpu")]
#[cfg(feature = "vello")]
pub resource_overrides: HashMap<u64, std::sync::Arc<wgpu::Texture>>,
}

Expand Down
8 changes: 0 additions & 8 deletions node-graph/gcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ mod graphic_element;
pub use graphic_element::*;
pub mod vector;

pub mod application_io;

pub mod registry;

pub use context::*;
Expand Down Expand Up @@ -140,12 +138,6 @@ impl<'i, I, O: 'i> Node<'i, I> for Pin<&'i (dyn NodeIO<'i, I, Output = O> + 'i)>
}
}

pub use crate::application_io::{SurfaceFrame, SurfaceId};
#[cfg(feature = "wasm")]
pub type WasmSurfaceHandle = application_io::SurfaceHandle<web_sys::HtmlCanvasElement>;
#[cfg(feature = "wasm")]
pub type WasmSurfaceHandleFrame = application_io::SurfaceHandleFrame<web_sys::HtmlCanvasElement>;

pub trait InputAccessorSource<'a, T>: InputAccessorSourceIdentifier + std::fmt::Debug {
fn get_input(&'a self, index: usize) -> Option<&'a T>;
fn set_input(&'a mut self, index: usize, value: T);
Expand Down
1 change: 1 addition & 0 deletions node-graph/graph-craft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ loading = ["serde_json"]
# Local dependencies
dyn-any = { workspace = true }
graphene-core = { workspace = true }
graphene-application-io = { workspace = true }

# Workspace dependencies
log = { workspace = true }
Expand Down
11 changes: 6 additions & 5 deletions node-graph/graph-craft/src/document/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::wasm_application_io::WasmEditorApi;
use dyn_any::DynAny;
pub use dyn_any::StaticType;
pub use glam::{DAffine2, DVec2, IVec2, UVec2};
use graphene_application_io::SurfaceFrame;
use graphene_core::raster::brush_cache::BrushCache;
use graphene_core::raster::{BlendMode, LuminanceCalculation};
use graphene_core::raster_types::CPU;
Expand All @@ -30,7 +31,7 @@ macro_rules! tagged_value {
None,
$( $(#[$meta] ) *$identifier( $ty ), )*
RenderOutput(RenderOutput),
SurfaceFrame(graphene_core::SurfaceFrame),
SurfaceFrame(SurfaceFrame),
#[serde(skip)]
EditorApi(Arc<WasmEditorApi>)
}
Expand Down Expand Up @@ -76,7 +77,7 @@ macro_rules! tagged_value {
Self::None => concrete!(()),
$( Self::$identifier(_) => concrete!($ty), )*
Self::RenderOutput(_) => concrete!(RenderOutput),
Self::SurfaceFrame(_) => concrete!(graphene_core::SurfaceFrame),
Self::SurfaceFrame(_) => concrete!(SurfaceFrame),
Self::EditorApi(_) => concrete!(&WasmEditorApi)
}
}
Expand All @@ -89,7 +90,7 @@ macro_rules! tagged_value {
x if x == TypeId::of::<()>() => Ok(TaggedValue::None),
$( x if x == TypeId::of::<$ty>() => Ok(TaggedValue::$identifier(*downcast(input).unwrap())), )*
x if x == TypeId::of::<RenderOutput>() => Ok(TaggedValue::RenderOutput(*downcast(input).unwrap())),
x if x == TypeId::of::<graphene_core::SurfaceFrame>() => Ok(TaggedValue::SurfaceFrame(*downcast(input).unwrap())),
x if x == TypeId::of::<SurfaceFrame>() => Ok(TaggedValue::SurfaceFrame(*downcast(input).unwrap())),


_ => Err(format!("Cannot convert {:?} to TaggedValue", DynAny::type_name(input.as_ref()))),
Expand All @@ -103,7 +104,7 @@ macro_rules! tagged_value {
x if x == TypeId::of::<()>() => Ok(TaggedValue::None),
$( x if x == TypeId::of::<$ty>() => Ok(TaggedValue::$identifier(<$ty as Clone>::clone(input.downcast_ref().unwrap()))), )*
x if x == TypeId::of::<RenderOutput>() => Ok(TaggedValue::RenderOutput(RenderOutput::clone(input.downcast_ref().unwrap()))),
x if x == TypeId::of::<graphene_core::SurfaceFrame>() => Ok(TaggedValue::SurfaceFrame(graphene_core::SurfaceFrame::clone(input.downcast_ref().unwrap()))),
x if x == TypeId::of::<SurfaceFrame>() => Ok(TaggedValue::SurfaceFrame(SurfaceFrame::clone(input.downcast_ref().unwrap()))),
_ => Err(format!("Cannot convert {:?} to TaggedValue",std::any::type_name_of_val(input))),
}
}
Expand Down Expand Up @@ -430,7 +431,7 @@ pub struct RenderOutput {

#[derive(Debug, Clone, PartialEq, dyn_any::DynAny, Hash, serde::Serialize, serde::Deserialize)]
pub enum RenderOutputType {
CanvasFrame(graphene_core::SurfaceFrame),
CanvasFrame(SurfaceFrame),
Svg(String),
Image(Vec<u8>),
}
Expand Down
10 changes: 5 additions & 5 deletions node-graph/graph-craft/src/wasm_application_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use dyn_any::StaticType;
use graphene_core::application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceId};
use graphene_application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceId};
#[cfg(target_arch = "wasm32")]
use js_sys::{Object, Reflect};
use std::collections::HashMap;
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'a> From<&'a WasmApplicationIo> for &'a WgpuExecutor {
}
}

pub type WasmEditorApi = graphene_core::application_io::EditorApi<WasmApplicationIo>;
pub type WasmEditorApi = graphene_application_io::EditorApi<WasmApplicationIo>;

impl ApplicationIo for WasmApplicationIo {
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -208,7 +208,7 @@ impl ApplicationIo for WasmApplicationIo {
// Use Reflect API to set property
Reflect::set(&canvases, &js_key, &js_value)?;
Ok::<_, JsValue>(SurfaceHandle {
window_id: graphene_core::SurfaceId(id),
window_id: SurfaceId(id),
surface: canvas,
})
};
Expand Down Expand Up @@ -313,15 +313,15 @@ impl ApplicationIo for WasmApplicationIo {
#[cfg(feature = "wgpu")]
pub type WasmSurfaceHandle = SurfaceHandle<wgpu_executor::Window>;
#[cfg(feature = "wgpu")]
pub type WasmSurfaceHandleFrame = graphene_core::application_io::SurfaceHandleFrame<wgpu_executor::Window>;
pub type WasmSurfaceHandleFrame = graphene_application_io::SurfaceHandleFrame<wgpu_executor::Window>;

#[derive(Clone, Debug, PartialEq, Hash, specta::Type, serde::Serialize, serde::Deserialize)]
pub struct EditorPreferences {
// pub imaginate_hostname: String,
pub use_vello: bool,
}

impl graphene_core::application_io::GetEditorPreferences for EditorPreferences {
impl graphene_application_io::GetEditorPreferences for EditorPreferences {
// fn hostname(&self) -> &str {
// &self.imaginate_hostname
// }
Expand Down
6 changes: 3 additions & 3 deletions node-graph/graphene-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use graph_craft::graphene_compiler::{Compiler, Executor};
use graph_craft::proto::ProtoNetwork;
use graph_craft::util::load_network;
use graph_craft::wasm_application_io::EditorPreferences;
use graphene_core::application_io::{ApplicationIo, NodeGraphUpdateSender};
use graphene_core::text::FontCache;
use graphene_std::application_io::{ApplicationIo, NodeGraphUpdateMessage, NodeGraphUpdateSender, RenderConfig};
use graphene_std::wasm_application_io::{WasmApplicationIo, WasmEditorApi};
use interpreted_executor::dynamic_executor::DynamicExecutor;
use interpreted_executor::util::wrap_network_in_scope;
Expand All @@ -18,7 +18,7 @@ use std::sync::Arc;
struct UpdateLogger {}

impl NodeGraphUpdateSender for UpdateLogger {
fn send(&self, message: graphene_core::application_io::NodeGraphUpdateMessage) {
fn send(&self, message: NodeGraphUpdateMessage) {
println!("{message:?}");
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
});
let executor = create_executor(proto_graph)?;
let render_config = graphene_core::application_io::RenderConfig::default();
let render_config = RenderConfig::default();

loop {
let result = (&executor).execute(render_config).await?;
Expand Down
5 changes: 3 additions & 2 deletions node-graph/gstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ license = "MIT OR Apache-2.0"
[features]
default = ["wasm", "imaginate"]
gpu = []
wgpu = ["gpu", "graph-craft/wgpu"]
wasm = ["wasm-bindgen", "web-sys"]
wgpu = ["gpu", "graph-craft/wgpu", "graphene-application-io/wgpu"]
wasm = ["wasm-bindgen", "web-sys", "graphene-application-io/wasm"]
imaginate = ["image/png", "base64", "web-sys", "wasm-bindgen-futures"]
image-compare = []
vello = ["dep:vello", "gpu", "graphene-core/vello"]
Expand All @@ -23,6 +23,7 @@ dyn-any = { workspace = true }
graph-craft = { workspace = true }
wgpu-executor = { workspace = true }
graphene-core = { workspace = true }
graphene-application-io = { workspace = true }

# Workspace dependencies
fastnoise-lite = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions node-graph/gstd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ pub mod vector;
#[cfg(feature = "wasm")]
pub mod wasm_application_io;

pub use graphene_application_io as application_io;
pub use graphene_core::*;
8 changes: 3 additions & 5 deletions node-graph/gstd/src/wasm_application_io.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use graph_craft::document::value::RenderOutput;
pub use graph_craft::document::value::RenderOutputType;
pub use graph_craft::wasm_application_io::*;
#[cfg(target_arch = "wasm32")]
use graphene_core::application_io::SurfaceHandle;
use graphene_core::application_io::{ApplicationIo, ExportFormat, RenderConfig};
use graphene_application_io::{ApplicationIo, ExportFormat, RenderConfig};
#[cfg(target_arch = "wasm32")]
use graphene_core::instances::Instances;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -127,7 +125,7 @@ async fn render_canvas(
surface_handle: wgpu_executor::WgpuSurface,
render_params: RenderParams,
) -> RenderOutputType {
use graphene_core::SurfaceFrame;
use graphene_application_io::SurfaceFrame;

let footprint = render_config.viewport;
let Some(exec) = editor.application_io.as_ref().unwrap().gpu_executor() else {
Expand Down Expand Up @@ -172,7 +170,7 @@ async fn rasterize<T: WasmNotSend + 'n>(
)]
mut data: Instances<T>,
footprint: Footprint,
surface_handle: Arc<SurfaceHandle<HtmlCanvasElement>>,
surface_handle: Arc<graphene_application_io::SurfaceHandle<HtmlCanvasElement>>,
) -> RasterDataTable<CPU>
where
Instances<T>: GraphicElementRendered,
Expand Down
6 changes: 3 additions & 3 deletions node-graph/interpreted-executor/src/node_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use graphene_core::{fn_type_fut, future};
use graphene_std::Context;
use graphene_std::GraphicElement;
use graphene_std::any::{ComposeTypeErased, DowncastBothNode, DynAnyNode, IntoTypeErasedNode};
use graphene_std::application_io::ImageTexture;
use graphene_std::application_io::{ImageTexture, SurfaceFrame};
use graphene_std::wasm_application_io::*;
use node_registry_macros::{async_node, into_node};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -80,8 +80,8 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => WindowHandle]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Option<WgpuSurface>]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => WindowHandle]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => graphene_std::SurfaceFrame]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: UVec2, fn_params: [UVec2 => graphene_std::SurfaceFrame]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => SurfaceFrame]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: UVec2, fn_params: [UVec2 => SurfaceFrame]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => f64]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => String]),
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => RenderOutput]),
Expand Down
3 changes: 2 additions & 1 deletion node-graph/wgpu-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ passthrough = []

[dependencies]
# Local dependencies
graphene-core = { workspace = true, features = ["wgpu"] }
graphene-core = { workspace = true, features = ["wgpu", "vello"] }
graphene-application-io = { workspace = true, features = ["wgpu"] }
dyn-any = { workspace = true }
node-macro = { workspace = true }

Expand Down
Loading
Loading