Refactor Graphite dependency management (#1455)

* Refactor Graphite dependency management

* Remove deprecated future executor

* Code review nits

* Remove unused dependencies

* Update dependencies and make compile with all features

* Replace use of future_executor with wasm-bindgen-futures

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert 2023-12-04 12:39:55 +01:00 committed by GitHub
parent b7fe38cf31
commit d2450b4d61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 1584 additions and 1209 deletions

View file

@ -83,7 +83,7 @@ jobs:
- name: 🦀 Build Rust code
run: |
mold -run cargo build
mold -run cargo build --all-features
- name: 🧪 Run Rust tests
run: |

2010
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,6 @@ members = [
"node-graph/vulkan-executor",
"node-graph/wgpu-executor",
"node-graph/gpu-executor",
"node-graph/future-executor",
"node-graph/gpu-compiler/gpu-compiler-bin-wrapper",
"libraries/dyn-any",
"libraries/bezier-rs",
@ -38,6 +37,59 @@ specta = { git = "https://github.com/0HyperCube/specta.git", rev = "c47a22b4c086
rustc-hash = "1.1.0"
# wasm-bindgen upgrades may break various things so we pin the version
wasm-bindgen = "=0.2.87"
dyn-any = { path = "libraries/dyn-any", features = ["derive", "glam"] }
document-legacy = { path = "document-legacy", package = "graphite-document-legacy" }
graphene-core = { path = "node-graph/gcore" }
graph-craft = { path = "node-graph/graph-craft", features = ["serde"] }
spirv-std = { version = "0.9" }
bytemuck = { version = "1.13", features = ["derive"] }
async-trait = { version = "0.1" }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
reqwest = { version = "0.11", features = ["rustls", "rustls-tls", "json"] }
futures = "0.3"
log = { version = "0.4" }
bitflags = { version = "2.4", features = ["serde"] }
remain = "0.2.2"
derivative = "2.2.0"
tempfile = "3"
thiserror = "1.0"
anyhow = "1.0.66"
proc-macro2 = "1"
syn = { version = "2.0", default-features = false, features = ["full"] }
quote = "1.0"
axum = "0.6"
chrono = "^0.4.23"
ron = "0.8"
wgpu-types = "0.17"
wgpu = "0.17"
wasm-bindgen-futures = { version = "0.4.36" }
winit = "0.28.6"
url = "2.4.0"
tokio = { version = "1.29", features = ["fs", "io-std"] }
vello = { git = "https://github.com/linebender/vello", version = "0.0.1" }
vello_svg = { git = "https://github.com/linebender/vello", version = "0.0.1" }
resvg = { version = "0.35.0" }
rand = { version = "0.8.5", default-features = false }
rand_chacha = { version = "0.3.1" }
bezier-rs = { path = "libraries/bezier-rs", features = ["dyn-any"] }
kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
"serde",
] }
glam = { version = "0.24", default-features = false, features = ["serde"] }
node-macro = { path = "node-graph/node-macro" }
base64 = { version = "0.21" }
image = { version = "0.24", default-features = false, features = ["png"] }
rustybuzz = { version = "0.8.0" }
num-derive = { version = "0.4" }
num-traits = { version = "0.2.15", default-features = false, features = [
"i128",
] }
js-sys = { version = "0.3.55" }
usvg = "0.35.0"
web-sys = { version = "0.3.55" }
spirv = "0.2.0"
fern = { version = "0.6", features = ["colored"] }
[profile.dev.package.graphite-editor]
opt-level = 1

View file

@ -13,17 +13,13 @@ license = "Apache-2.0"
[dependencies]
graph-craft = { path = "../node-graph/graph-craft", features = ["serde"] }
graphene-std = { path = "../node-graph/gstd", features = ["serde"] }
graphene-core = { path = "../node-graph/gcore", features = ["serde"] }
image = { version = "0.24", default-features = false }
log = "0.4"
bezier-rs = { path = "../libraries/bezier-rs" }
kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
"serde",
] }
specta.workspace = true
serde = { version = "1.0", features = ["derive"] }
base64 = "0.21"
glam = { version = "0.24", features = ["serde"] }
rustybuzz = "0.8"
graphene-core = { workspace = true, features = ["serde"] }
image = { workspace = true, default-features = false }
log = { workspace = true }
bezier-rs = { workspace = true }
kurbo = { workspace = true }
specta = { workspace = true }
serde = { workspace = true }
base64 = { workspace = true }
glam = { workspace = true }
rustybuzz = { workspace = true }

View file

@ -12,49 +12,47 @@ license = "Apache-2.0"
[features]
default = ["wasm"]
gpu = ["interpreted-executor/gpu", "graphene-std/gpu", "graphene-core/gpu", "wgpu-executor", "gpu-executor"]
gpu = [
"interpreted-executor/gpu",
"graphene-std/gpu",
"graphene-core/gpu",
"wgpu-executor",
"gpu-executor",
]
quantization = [
"graphene-std/quantization",
"interpreted-executor/quantization",
]
wasm = ["wasm-bindgen", "future-executor", "graphene-std/wasm"]
wasm = ["wasm-bindgen", "graphene-std/wasm", "wasm-bindgen-futures"]
[dependencies]
log = "0.4"
bitflags = { version = "2.3", features = ["serde"] }
thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
log = { workspace = true }
bitflags = { workspace = true }
thiserror = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
graphite-proc-macros = { path = "../proc-macros" }
bezier-rs = { path = "../libraries/bezier-rs" }
glam = { version = "0.24", features = ["serde", "debug-glam-assert"] }
remain = "0.2.2"
derivative = "2.2.0"
once_cell = "1.13.0" # Remove when `core::cell::LazyCell` is stabilized (<https://doc.rust-lang.org/core/cell/struct.LazyCell.html>)
bezier-rs = { workspace = true }
glam = { workspace = true, features = ["serde", "debug-glam-assert"] }
remain = { workspace = true }
derivative = { workspace = true }
specta.workspace = true
# Node graph
image = { version = "0.24", default-features = false, features = [
"bmp",
"png",
] }
image = { workspace = true, features = ["bmp", "png"] }
graph-craft = { path = "../node-graph/graph-craft" }
wgpu-executor = { path = "../node-graph/wgpu-executor", optional = true }
gpu-executor = { path = "../node-graph/gpu-executor", optional = true }
interpreted-executor = { path = "../node-graph/interpreted-executor" }
dyn-any = { path = "../libraries/dyn-any" }
dyn-any = { workspace = true }
graphene-core = { path = "../node-graph/gcore" }
graphene-std = { path = "../node-graph/gstd" }
future-executor = { path = "../node-graph/future-executor", optional = true }
num_enum = "0.6.1"
wasm-bindgen = { workspace = true, optional = true }
[dependencies.document-legacy]
path = "../document-legacy"
package = "graphite-document-legacy"
wasm-bindgen-futures = { workspace = true, optional = true }
document-legacy = { workspace = true }
# Remove when `core::cell::LazyCell` is stabilized (<https://doc.rust-lang.org/core/cell/struct.LazyCell.html>)
once_cell = "1.13.0"
[dev-dependencies]
env_logger = "0.10"
test-case = "3.1"
futures = "0.3.28"
futures = { workspace = true }

View file

@ -293,7 +293,7 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
self.persistent_data.imaginate.poll_server_check();
#[cfg(target_arch = "wasm32")]
if let Some(fut) = self.persistent_data.imaginate.initiate_server_check() {
future_executor::spawn(async move {
wasm_bindgen_futures::spawn_local(async move {
let () = fut.await;
use wasm_bindgen::prelude::*;

View file

@ -15,24 +15,29 @@ rust-version = "1.66.0"
tauri-build = { version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["api-all", "devtools", "linux-protocol-headers", "wry"] }
axum = "0.6.1"
graphite-editor = { version = "0.0.0", path = "../../editor" }
chrono = "^0.4.23"
tokio = { version = "1", features = ["full"] }
ron = "0.8"
log = "0.4"
fern = { version = "0.6", features = ["colored"] }
futures = "0.3.25"
serde_json = { workspace = true }
serde = { workspace = true }
tauri = { version = "1.5", features = [
"api-all",
"devtools",
"linux-protocol-headers",
"wry",
] }
axum = { workspace = true }
graphite-editor = { path = "../../editor" }
chrono = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
ron = { workspace = true }
log = { workspace = true }
fern = { workspace = true }
futures = { workspace = true }
[features]
gpu = ["graphite-editor/gpu"]
quantization = ["graphite-editor/quantization"]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
default = ["custom-protocol"]
# this feature is used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = ["tauri/custom-protocol"]

View file

@ -20,27 +20,23 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
editor = { path = "../../editor", package = "graphite-editor" }
document-legacy = { path = "../../document-legacy", package = "graphite-document-legacy" }
graph-craft = { path = "../../node-graph/graph-craft" }
log = "0.4"
graphene-core = { path = "../../node-graph/gcore", features = [
"async",
"std",
"alloc",
] }
serde = { version = "1.0", features = ["derive"] }
document-legacy = { workspace = true }
graph-craft = { workspace = true }
log = { workspace = true }
graphene-core = { workspace = true, features = ["std", "alloc"] }
serde = { workspace = true, features = ["derive"] }
wasm-bindgen = { workspace = true }
serde-wasm-bindgen = "0.5.0"
js-sys = "0.3.63"
wasm-bindgen-futures = "0.4.36"
serde-wasm-bindgen = "0.6"
js-sys = { workspace = true }
wasm-bindgen-futures = { workspace = true }
ron = { version = "0.8", optional = true }
bezier-rs = { path = "../../libraries/bezier-rs" }
bezier-rs = { workspace = true }
# We don't have wgpu on multiple threads (yet) https://github.com/gfx-rs/wgpu/blob/trunk/CHANGELOG.md#wgpu-types-now-send-sync-on-wasm
wgpu = { version = "0.17", features = ["fragile-send-sync-non-atomic-wasm"] }
meval = "0.2.0"
[dependencies.web-sys]
version = "0.3.4"
workspace = true
features = [
"Window",
"CanvasRenderingContext2d",
@ -48,9 +44,6 @@ features = [
"HtmlCanvasElement",
]
[dev-dependencies]
wasm-bindgen-test = "0.3.22"
[package.metadata.wasm-pack.profile.dev]
wasm-opt = false

View file

@ -16,5 +16,5 @@ documentation = "https://graphite.rs/libraries/bezier-rs/"
[dependencies]
glam = { version = "0.24", features = ["serde"] }
dyn-any = { version = "0.3.0", path = "../dyn-any", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
dyn-any = { workspace = true, optional = true }
serde = { workspace = true, optional = true }

View file

@ -14,9 +14,9 @@ readme = "../README.md"
proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "1", default-features = false, features = [
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true, default-features = false, features = [
"derive",
"parsing",
"proc-macro",

View file

@ -5,7 +5,7 @@ extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use syn::{parse_macro_input, DeriveInput, GenericParam, Lifetime, LifetimeDef, TypeParamBound};
use syn::{parse_macro_input, DeriveInput, GenericParam, Lifetime, LifetimeParam, TypeParamBound};
/// Derives an implementation for the [`DynAny`] trait.
///
@ -59,7 +59,7 @@ fn replace_lifetimes(generics: &syn::Generics, replacement: &str) -> Vec<proc_ma
.iter()
.map(|param| {
let param = match param {
GenericParam::Lifetime(_) => GenericParam::Lifetime(LifetimeDef::new(Lifetime::new(replacement, Span::call_site()))),
GenericParam::Lifetime(_) => GenericParam::Lifetime(LifetimeParam::new(Lifetime::new(replacement, Span::call_site()))),
GenericParam::Type(t) => {
let mut t = t.clone();
t.bounds.iter_mut().for_each(|bond| {

View file

@ -12,11 +12,10 @@ serde_json = "1.0"
graph-craft = { version = "0.1.0", path = "../graph-craft", features = [
"serde",
] }
graphene-core = { version = "0.1.0", path = "../gcore" }
graphene-core = { workspace = true }
gpu-executor = { version = "0.1.0", path = "../gpu-executor" }
gpu-compiler-bin-wrapper = { version = "0.1.0", path = "../gpu-compiler/gpu-compiler-bin-wrapper" }
tempfile = "3.3.0"
anyhow = "1.0.68"
anyhow = { workspace = true }
reqwest = { version = "0.11", features = [
"blocking",
"serde_json",
@ -24,4 +23,3 @@ reqwest = { version = "0.11", features = [
"rustls",
"rustls-tls",
] }
future-executor = { path = "../future-executor" }

View file

@ -16,10 +16,6 @@ pub async fn compile(networks: Vec<ProtoNetwork>, inputs: Vec<Type>, outputs: Ve
})
}
pub fn compile_sync(networks: Vec<ProtoNetwork>, inputs: Vec<Type>, outputs: Vec<Type>, io: ShaderIO) -> Result<Shader, reqwest::Error> {
future_executor::block_on(compile(networks, inputs, outputs, io))
}
// TODO: should we add the entry point as a field?
/// A compiled shader with type annotations.
pub struct Shader {

View file

@ -7,13 +7,15 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.29", features = ["full"] }
axum = "0.6.18"
tokio = { version = "1", features = ["full"] }
axum = "0.7"
serde_json = "1.0"
graph-craft = { version = "0.1.0", path = "../graph-craft", features = ["serde"] }
graph-craft = { version = "0.1.0", path = "../graph-craft", features = [
"serde",
] }
gpu-compiler-bin-wrapper = { version = "0.1.0", path = "../gpu-compiler/gpu-compiler-bin-wrapper" }
serde = { version = "1.0", features = ["derive"] }
tempfile = "3.6.0"
anyhow = "1.0.72"
futures = "0.3"
tower-http = { version = "0.4.1", features = ["cors"] }
tower-http = { version = "0.5", features = ["cors"] }

View file

@ -31,7 +31,8 @@ async fn main() {
.with_state(shared_state);
// run it with hyper on localhost:3000
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn post_compile_spirv(State(state): State<Arc<AppState>>, Json(compile_request): Json<CompileRequest>) -> Result<Vec<u8>, StatusCode> {

View file

@ -1,20 +0,0 @@
[package]
name = "future-executor"
version = "0.1.0"
edition = "2021"
authors = ["Graphite Authors <contact@graphite.rs>"]
license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
futures = "0.3.25"
log = "0.4"
[target.wasm32-unknown-unknown.dependencies]
wasm-rs-async-executor = { version = "0.9.0", features = [
"cooperative-browser",
"debug",
"requestIdleCallback",
] }
wasm-bindgen-futures = "0.4.36"

View file

@ -1,29 +0,0 @@
use core::future::Future;
pub fn block_on<F: Future + 'static>(future: F) -> F::Output {
#[cfg(target_arch = "wasm32")]
{
use wasm_rs_async_executor::single_threaded as executor;
let val = std::sync::Arc::new(std::sync::Mutex::new(None));
let move_val = val.clone();
let result = executor::spawn(async move {
let result = executor::yield_async(future).await;
*move_val.lock().unwrap() = Some(result);
});
executor::run(Some(result.task()));
loop {
if let Some(result) = val.lock().unwrap().take() {
return result;
}
}
}
#[cfg(not(target_arch = "wasm32"))]
futures::executor::block_on(future)
}
#[cfg(target_arch = "wasm32")]
pub fn spawn<F: Future<Output = ()> + 'static>(future: F) {
wasm_bindgen_futures::spawn_local(future);
}

View file

@ -9,62 +9,61 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
std = ["dyn-any", "dyn-any/std", "alloc", "glam/std", "specta", "num-traits/std", "rustybuzz", "image"]
default = ["async", "serde", "kurbo", "log", "std", "rand_chacha", "wasm"]
std = [
"dyn-any",
"dyn-any/std",
"alloc",
"glam/std",
"specta",
"num-traits/std",
"rustybuzz",
"image",
]
default = ["serde", "kurbo", "log", "std", "rand_chacha", "wasm"]
log = ["dep:log"]
serde = ["dep:serde", "glam/serde", "bezier-rs/serde", "bezier-rs/serde", "base64"]
serde = [
"dep:serde",
"glam/serde",
"bezier-rs/serde",
"bezier-rs/serde",
"base64",
]
gpu = ["spirv-std", "glam/bytemuck", "dyn-any", "glam/libm"]
async = ["async-trait", "alloc"]
nightly = []
alloc = ["dyn-any", "bezier-rs"]
type_id_logging = []
wasm = ["web-sys"]
[dependencies]
dyn-any = { path = "../../libraries/dyn-any", features = [
"derive",
"glam",
], optional = true, default-features = false }
spirv-std = { version = "0.9", optional = true }
bytemuck = { version = "1.8", features = ["derive"] }
async-trait = { version = "0.1", optional = true }
serde = { version = "1.0", features = [
"derive",
"rc"
], optional = true, default-features = false }
log = { version = "0.4", optional = true }
rand_chacha = { version = "0.3.1", optional = true }
bezier-rs = { path = "../../libraries/bezier-rs", optional = true }
kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
"serde",
], optional = true }
spin = "0.9.2"
glam = { version = "0.24", default-features = false, features = [
dyn-any = { workspace = true, optional = true }
spirv-std = { workspace = true, optional = true }
bytemuck = { workspace = true, features = ["derive"] }
serde = { workspace = true, optional = true, features = ["derive"] }
log = { workspace = true, optional = true }
rand_chacha = { workspace = true, optional = true }
bezier-rs = { workspace = true, optional = true }
kurbo = { workspace = true, optional = true }
glam = { workspace = true, default-features = false, features = [
"scalar-math",
] }
node-macro = { path = "../node-macro" }
base64 = { version = "0.21", optional = true }
image = { version = "0.24", optional = true, default-features = false, features = [
node-macro = { workspace = true }
base64 = { workspace = true, optional = true }
image = { workspace = true, optional = true, default-features = false, features = [
"png",
] }
specta.workspace = true
specta.optional = true
specta = { workspace = true, optional = true }
rustybuzz = { version = "0.8.0", optional = true }
rustybuzz = { workspace = true, optional = true }
num-derive = { version = "0.4" }
num-traits = { version = "0.2.15", default-features = false, features = [
"i128",
] }
num-derive = { workspace = true }
num-traits = { workspace = true, default-features = false, features = ["i128"] }
wasm-bindgen = { workspace = true, optional = true }
js-sys = { version = "0.3.55", optional = true }
usvg = "0.35.0"
js-sys = { workspace = true, optional = true }
usvg = { workspace = true }
[dependencies.web-sys]
version = "0.3.4"
workspace = true
optional = true
features = ["HtmlCanvasElement"]

View file

@ -7,6 +7,7 @@ use bezier_rs::Subpath;
pub use quad::Quad;
use glam::{DAffine2, DVec2};
use usvg::TreeParsing;
mod quad;
@ -182,11 +183,38 @@ pub fn format_transform_matrix(transform: DAffine2) -> String {
result.push(')');
result
}
fn to_transform(transform: DAffine2) -> usvg::Transform {
let cols = transform.to_cols_array();
usvg::Transform::from_row(cols[0] as f32, cols[1] as f32, cols[2] as f32, cols[3] as f32, cols[4] as f32, cols[5] as f32)
}
pub trait GraphicElementRendered {
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams);
fn bounding_box(&self, transform: DAffine2) -> Option<[DVec2; 2]>;
fn add_click_targets(&self, click_targets: &mut Vec<ClickTarget>);
fn to_usvg_node(&self) -> usvg::Node {
let mut render = SvgRender::new();
let render_params = RenderParams::new(crate::vector::style::ViewMode::Normal, ImageRenderMode::BlobUrl, None, false);
self.render_svg(&mut render, &render_params);
render.format_svg(DVec2::ZERO, DVec2::ONE);
let svg = render.svg.to_string();
let opt = usvg::Options::default();
let tree = usvg::Tree::from_str(&svg, &opt).expect("Failed to parse SVG");
tree.root.clone()
}
fn to_usvg_tree(&self, resolution: glam::UVec2, viewbox: [DVec2; 2]) -> usvg::Tree {
let root_node = self.to_usvg_node();
usvg::Tree {
size: usvg::Size::from_wh(resolution.x as f32, resolution.y as f32).unwrap(),
view_box: usvg::ViewBox {
rect: usvg::NonZeroRect::from_ltrb(viewbox[0].x as f32, viewbox[0].y as f32, viewbox[1].x as f32, viewbox[1].y as f32).unwrap(),
aspect: usvg::AspectRatio::default(),
},
root: root_node.clone(),
}
}
}
impl GraphicElementRendered for GraphicGroup {
@ -212,6 +240,14 @@ impl GraphicElementRendered for GraphicGroup {
.reduce(Quad::combine_bounds)
}
fn add_click_targets(&self, _click_targets: &mut Vec<ClickTarget>) {}
fn to_usvg_node(&self) -> usvg::Node {
let root_node = usvg::Node::new(usvg::NodeKind::Group(usvg::Group::default()));
for element in self.iter() {
root_node.append(element.to_usvg_node());
}
root_node
}
}
impl GraphicElementRendered for VectorData {
@ -250,6 +286,40 @@ impl GraphicElementRendered for VectorData {
};
click_targets.extend(self.subpaths.iter().cloned().map(update_closed).map(|subpath| ClickTarget { stroke_width, subpath }))
}
fn to_usvg_node(&self) -> usvg::Node {
use bezier_rs::BezierHandles;
use usvg::tiny_skia_path::PathBuilder;
let mut builder = PathBuilder::new();
let vector_data = self;
let transform = to_transform(vector_data.transform);
for subpath in vector_data.subpaths.iter() {
let start = vector_data.transform.transform_point2(subpath[0].anchor);
builder.move_to(start.x as f32, start.y as f32);
for bezier in subpath.iter() {
bezier.apply_transformation(|pos| vector_data.transform.transform_point2(pos));
let end = bezier.end;
match bezier.handles {
BezierHandles::Linear => builder.line_to(end.x as f32, end.y as f32),
BezierHandles::Quadratic { handle } => builder.quad_to(handle.x as f32, handle.y as f32, end.x as f32, end.y as f32),
BezierHandles::Cubic { handle_start, handle_end } => {
builder.cubic_to(handle_start.x as f32, handle_start.y as f32, handle_end.x as f32, handle_end.y as f32, end.x as f32, end.y as f32)
}
}
}
if subpath.closed {
builder.close()
}
}
let path = builder.finish().unwrap();
let mut path = usvg::Path::new(path.into());
path.transform = transform;
// TODO: use proper style
path.fill = None;
path.stroke = Some(usvg::Stroke::default());
usvg::Node::new(usvg::NodeKind::Path(path))
}
}
impl GraphicElementRendered for Artboard {
@ -379,6 +449,25 @@ impl GraphicElementRendered for ImageFrame<Color> {
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
click_targets.push(ClickTarget { subpath, stroke_width: 0. });
}
fn to_usvg_node(&self) -> usvg::Node {
let image_frame = self;
if image_frame.image.width * image_frame.image.height == 0 {
return usvg::Node::new(usvg::NodeKind::Group(usvg::Group::default()));
}
let png = image_frame.image.to_png();
usvg::Node::new(usvg::NodeKind::Image(usvg::Image {
id: String::new(),
transform: to_transform(image_frame.transform),
visibility: usvg::Visibility::Visible,
view_box: usvg::ViewBox {
rect: usvg::NonZeroRect::from_xywh(0., 0., 1., 1.).unwrap(),
aspect: usvg::AspectRatio::default(),
},
rendering_mode: usvg::ImageRendering::OptimizeSpeed,
kind: usvg::ImageKind::PNG(png.into()),
}))
}
}
impl GraphicElementRendered for GraphicElementData {
@ -411,6 +500,16 @@ impl GraphicElementRendered for GraphicElementData {
GraphicElementData::Artboard(artboard) => artboard.add_click_targets(click_targets),
}
}
fn to_usvg_node(&self) -> usvg::Node {
match self {
GraphicElementData::VectorShape(vector_data) => vector_data.to_usvg_node(),
GraphicElementData::ImageFrame(image_frame) => image_frame.to_usvg_node(),
GraphicElementData::Text(text) => text.to_usvg_node(),
GraphicElementData::GraphicGroup(graphic_group) => graphic_group.to_usvg_node(),
GraphicElementData::Artboard(artboard) => artboard.to_usvg_node(),
}
}
}
/// Used to stop rust complaining about upstream traits adding display implementations to `Option<Color>`. This would not be an issue as we control that crate.
@ -436,6 +535,26 @@ impl<T: Primitive> GraphicElementRendered for T {
}
fn add_click_targets(&self, _click_targets: &mut Vec<ClickTarget>) {}
fn to_usvg_node(&self) -> usvg::Node {
let text = self;
usvg::Node::new(usvg::NodeKind::Text(usvg::Text {
id: String::new(),
transform: usvg::Transform::identity(),
rendering_mode: usvg::TextRendering::OptimizeSpeed,
positions: Vec::new(),
rotate: Vec::new(),
writing_mode: usvg::WritingMode::LeftToRight,
chunks: vec![usvg::TextChunk {
text: text.to_string(),
x: None,
y: None,
anchor: usvg::TextAnchor::Start,
spans: vec![],
text_flow: usvg::TextFlow::Linear,
}],
}))
}
}
impl GraphicElementRendered for Option<Color> {

View file

@ -46,7 +46,7 @@ mod uuid_generation {
use core::cell::Cell;
use rand_chacha::rand_core::{RngCore, SeedableRng};
use rand_chacha::ChaCha20Rng;
use spin::Mutex;
use std::sync::Mutex;
static RNG: Mutex<Option<ChaCha20Rng>> = Mutex::new(None);
thread_local! {
@ -58,14 +58,14 @@ mod uuid_generation {
}
pub fn generate_uuid() -> u64 {
let mut lock = RNG.lock();
let Ok(mut lock) = RNG.lock() else { panic!("UUID mutex poisoned") };
if lock.is_none() {
UUID_SEED.with(|seed| {
let random_seed = seed.get().unwrap_or(42);
*lock = Some(ChaCha20Rng::seed_from_u64(random_seed));
})
}
lock.as_mut().map(ChaCha20Rng::next_u64).expect("uuid mutex poisoned")
lock.as_mut().map(ChaCha20Rng::next_u64).expect("UUID mutex poisoned")
}
}

View file

@ -12,26 +12,22 @@ serde = ["graphene-core/serde", "glam/serde"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = ["async", "std", "alloc"] }
graphene-core = { workspace = true, features = ["async", "std", "alloc"] }
graph-craft = { path = "../graph-craft", features = ["serde"] }
gpu-executor = { path = "../gpu-executor" }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"rc",
"glam",
] }
num-traits = "0.2"
log = "0.4"
serde = { version = "1", features = ["derive", "rc"] }
glam = { version = "0.24" }
base64 = "0.21"
dyn-any = { workspace = true, features = ["log-bad-types", "rc", "glam"] }
num-traits = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
glam = { workspace = true }
base64 = { workspace = true }
bytemuck = { version = "1.8" }
bytemuck = { workspace = true }
nvtx = { version = "1.1.1", optional = true }
tempfile = "3"
tempfile = { workspace = true }
spirv-builder = { version = "0.9", default-features = false, features = [
"use-installed-tools",
] }
tera = { version = "1.17.1" }
anyhow = "1.0.66"
serde_json = "1.0.91"
anyhow = { workspace = true }
serde_json = { workspace = true }

View file

@ -235,7 +235,7 @@ mod test {
name: "project".to_owned(),
authors: vec!["Example <john.smith@example.com>".to_owned(), "smith.john@example.com".to_owned()],
});
let cargo_toml = cargo_toml.expect("failed to build carog toml template");
let cargo_toml = cargo_toml.expect("Failed to build cargo toml template");
let lines = cargo_toml.split('\n').collect::<Vec<_>>();
let cargo_toml = lines[..lines.len() - 2].join("\n");
let reference = r#"[package]

View file

@ -10,31 +10,20 @@ default = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = [
"async",
"std",
"alloc",
"gpu",
] }
graph-craft = { path = "../graph-craft", features = ["serde"] }
graphene-core = { workspace = true, features = ["std", "alloc", "gpu"] }
graph-craft = { workspace = true }
node-macro = { path = "../node-macro" }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"rc",
"glam",
] }
num-traits = "0.2"
log = "0.4"
serde = { version = "1", features = ["derive", "rc"] }
glam = "0.24"
base64 = "0.21"
dyn-any = { workspace = true, features = ["log-bad-types", "rc", "glam"] }
num-traits = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
glam = { workspace = true }
base64 = { workspace = true }
bytemuck = { version = "1.8" }
anyhow = "1.0.66"
spirv = "0.2.0"
futures-intrusive = "0.5.0"
futures = "0.3.25"
web-sys = { version = "0.3.4", features = [
bytemuck = { workspace = true }
anyhow = { workspace = true }
futures = { workspace = true }
web-sys = { workspace = true, features = [
"HtmlCanvasElement",
"ImageBitmapRenderingContext",
] }

View file

@ -12,17 +12,18 @@ dealloc_nodes = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = ["std"] }
dyn-any = { path = "../../libraries/dyn-any", features = ["log-bad-types", "rc", "glam"] }
num-traits = "0.2"
dyn-clone = "1.0"
log = "0.4"
serde = { version = "1", features = ["derive", "rc"], optional = true }
glam = { version = "0.24" }
base64 = "0.21"
bezier-rs = { path = "../../libraries/bezier-rs", features = ["dyn-any"] }
specta.workspace = true
bytemuck = { version = "1.8" }
anyhow = "1.0.66"
graphene-core = { workspace = true, features = ["std"] }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"rc",
"glam",
] }
num-traits = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
glam = { workspace = true }
base64 = { workspace = true }
bezier-rs = { workspace = true }
specta = { workspace = true }
bytemuck = { workspace = true }
rustc-hash = { workspace = true }

View file

@ -25,38 +25,32 @@ quantization = ["graphene-std/quantization"]
[dependencies]
log = "0.4"
bitflags = "2.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
bezier-rs = { path = "../../libraries/bezier-rs" }
glam = { version = "0.24", features = ["serde"] }
# Node graph
log = { workspace = true }
bitflags = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
bezier-rs = { workspace = true }
glam = { workspace = true }
graphene-std = { path = "../gstd" }
image = { version = "0.24", default-features = false, features = [
image = { workspace = true, default-features = false, features = [
"bmp",
"png",
] }
graph-craft = { path = "../graph-craft" }
graph-craft = { workspace = true }
wgpu-executor = { path = "../wgpu-executor", optional = true }
gpu-executor = { path = "../gpu-executor", optional = true }
interpreted-executor = { path = "../interpreted-executor" }
dyn-any = { path = "../../libraries/dyn-any" }
graphene-core = { path = "../gcore" }
future-executor = { path = "../future-executor", optional = true }
dyn-any = { workspace = true }
graphene-core = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }
futures = "0.3.28"
fern = { version = "0.6.2", features = ["colored"] }
chrono = "0.4.26"
tokio = { version = "1.28.2", features = ["macros", "rt"] }
wgpu = "0.17"
futures = { workspace = true }
fern = { workspace = true }
chrono = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt"] }
wgpu = { workspace = true }
[dependencies.document-legacy]
path = "../../document-legacy"
package = "graphite-document-legacy"
[dev-dependencies]
env_logger = "0.10"
test-case = "3.1"

View file

@ -17,7 +17,7 @@ gpu = [
"gpu-executor",
]
vulkan = ["gpu", "vulkan-executor"]
wgpu = ["gpu", "wgpu-executor"]
wgpu = ["gpu", "wgpu-executor", "dep:wgpu"]
quantization = ["autoquant"]
wasm = ["wasm-bindgen", "web-sys", "js-sys"]
imaginate = ["image/png", "base64", "js-sys", "web-sys", "wasm-bindgen-futures"]
@ -27,16 +27,15 @@ resvg = ["dep:resvg"]
wayland = []
[dependencies]
rand = { version = "0.8.5", features = [
rand = { workspace = true, features = [
"alloc",
"small_rng",
], default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
rand_chacha = { workspace = true }
autoquant = { git = "https://github.com/truedoctor/autoquant", optional = true, features = [
"fitting",
] }
graphene-core = { path = "../gcore", features = [
"async",
"std",
"serde",
"alloc",
@ -44,48 +43,44 @@ graphene-core = { path = "../gcore", features = [
dyn-any = { path = "../../libraries/dyn-any", features = ["derive"] }
graph-craft = { path = "../graph-craft", features = ["serde"] }
vulkan-executor = { path = "../vulkan-executor", optional = true }
wgpu-executor = { path = "../wgpu-executor", optional = true, version = "0.1" }
wgpu-executor = { path = "../wgpu-executor", optional = true }
gpu-executor = { path = "../gpu-executor", optional = true }
gpu-compiler-bin-wrapper = { path = "../gpu-compiler/gpu-compiler-bin-wrapper", optional = true }
compilation-client = { path = "../compilation-client", optional = true }
bytemuck = { version = "1.13" }
tempfile = "3"
image = { version = "0.24", default-features = false, features = [
bytemuck = { workspace = true }
image = { workspace = true, default-features = false, features = [
"png",
"jpeg",
] }
base64 = { version = "0.21", optional = true }
dyn-clone = "1.0"
log = "0.4"
bezier-rs = { path = "../../libraries/bezier-rs", features = ["serde"] }
glam = { version = "0.24", features = ["serde"] }
node-macro = { path = "../node-macro" }
base64 = { workspace = true, optional = true }
wgpu = { workspace = true, optional = true }
log = { workspace = true }
bezier-rs = { workspace = true, features = ["serde"] }
glam = { workspace = true, features = ["serde"] }
node-macro = { workspace = true }
rustc-hash = { workspace = true }
serde_json = "1.0.96"
reqwest = { version = "0.11.18", features = ["rustls", "rustls-tls", "json"] }
futures = "0.3.28"
serde_json = { workspace = true }
reqwest = { workspace = true }
futures = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }
js-sys = { version = "0.3.63", optional = true }
wgpu-types = "0.17"
wgpu = "0.17"
wasm-bindgen-futures = { version = "0.4.36", optional = true }
winit = "0.28.6"
url = "2.4.0"
tokio = { version = "1.29.0", optional = true, features = ["fs", "io-std"] }
js-sys = { workspace = true, optional = true }
wgpu-types = { workspace = true }
wasm-bindgen-futures = { workspace = true, optional = true }
winit = { workspace = true }
url = { workspace = true }
tokio = { workspace = true, optional = true, features = ["fs", "io-std"] }
image-compare = { version = "0.3.0", optional = true }
vello = { git = "https://github.com/linebender/vello", version = "0.0.1", optional = true }
vello_svg = { git = "https://github.com/linebender/vello", version = "0.0.1", optional = true }
resvg = { version = "0.35.0", optional = true }
vello = { workspace = true, optional = true }
vello_svg = { workspace = true, optional = true }
resvg = { workspace = true, optional = true }
[dependencies.serde]
version = "1.0"
workspace = true
optional = true
features = ["derive"]
[dependencies.web-sys]
version = "0.3.63"
workspace = true
optional = true
features = [
"Window",

View file

@ -344,7 +344,7 @@ fn render_canvas(
*/
let frame = SurfaceHandleFrame {
surface_handle,
transform: DAffine2::IDENTITY,
transform: glam::DAffine2::IDENTITY,
};
RenderOutput::CanvasFrame(frame.into())
}

View file

@ -13,20 +13,15 @@ quantization = ["graphene-std/quantization"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = ["async", "std"] }
graphene-core = { workspace = true, features = ["std"] }
graphene-std = { path = "../gstd" }
graph-craft = { path = "../graph-craft" }
gpu-executor = { path = "../gpu-executor" }
wgpu-executor = { path = "../wgpu-executor" }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"glam",
] }
num-traits = "0.2"
dyn-clone = "1.0"
log = "0.4"
serde = { version = "1", features = ["derive"], optional = true }
glam = { version = "0.24" }
once_cell = "1.18" # Remove when `core::cell::LazyCell` is stabilized (<https://doc.rust-lang.org/core/cell/struct.LazyCell.html>)
futures = "0.3.28"
typed-arena = "2.0.2"
dyn-any = { workspace = true, features = ["log-bad-types", "glam"] }
num-traits = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
glam = { workspace = true }
once_cell = "1.18" # Remove when `core::cell::LazyCell` is stabilized (<https://doc.rust-lang.org/core/cell/struct.LazyCell.html>)
futures = { workspace = true }

View file

@ -16,6 +16,6 @@ license = "Apache-2.0"
proc-macro = true
[dependencies]
syn = { version = "2.0", features = ["full"] }
proc-macro2 = "1.0"
quote = "1.0"
syn = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }

View file

@ -10,15 +10,18 @@ default = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = ["async", "std", "alloc", "gpu"] }
graph-craft = {path = "../graph-craft" }
dyn-any = { path = "../../libraries/dyn-any", features = ["log-bad-types", "rc", "glam"] }
num-traits = "0.2"
log = "0.4"
serde = { version = "1", features = ["derive", "rc"], optional = true }
glam = { version = "0.24" }
base64 = "0.21"
vulkano = { git = "https://github.com/GraphiteEditor/vulkano", branch = "fix_rust_gpu"}
bytemuck = { version = "1.13" }
anyhow = "1.0"
graphene-core = { path = "../gcore", features = ["std", "alloc", "gpu"] }
graph-craft = { path = "../graph-craft" }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"rc",
"glam",
] }
num-traits = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
glam = { workspace = true }
base64 = { workspace = true }
vulkano = { git = "https://github.com/GraphiteEditor/vulkano", branch = "fix_rust_gpu" }
bytemuck = { workspace = true }
anyhow = { workspace = true }

View file

@ -12,32 +12,21 @@ passthrough = []
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
graphene-core = { path = "../gcore", features = [
"async",
"std",
"alloc",
"gpu",
] }
graph-craft = { path = "../graph-craft" }
graphene-core = { workspace = true, features = ["std", "alloc", "gpu"] }
graph-craft = { workspace = true }
gpu-executor = { path = "../gpu-executor" }
dyn-any = { path = "../../libraries/dyn-any", features = [
"log-bad-types",
"rc",
"glam",
] }
future-executor = { path = "../future-executor" }
num-traits = "0.2"
log = "0.4"
serde = { version = "1", features = ["derive", "rc"], optional = true }
glam = { version = "0.24" }
base64 = "0.21"
bytemuck = { version = "1.8" }
anyhow = "1.0.66"
wgpu = { version = "0.17", features = ["spirv"] }
spirv = "0.2.0"
dyn-any = { workspace = true, features = ["log-bad-types", "rc", "glam"] }
num-traits = { workspace = true }
log = { workspace = true }
serde = { workspace = true, optional = true }
glam = { workspace = true }
base64 = { workspace = true }
bytemuck = { workspace = true }
anyhow = { workspace = true }
wgpu = { workspace = true, features = ["spirv"] }
spirv = { workspace = true }
futures = { workspace = true }
futures-intrusive = "0.5.0"
futures = "0.3.25"
web-sys = { version = "0.3.4", features = ["HtmlCanvasElement"] }
winit = "0.28.6"
web-sys = { workspace = true, features = ["HtmlCanvasElement"] }
winit = { workspace = true }
nvtx = { version = "1.2", optional = true }

View file

@ -51,8 +51,4 @@ impl Context {
instance: Arc::new(instance),
})
}
pub fn new_sync() -> Option<Self> {
future_executor::block_on(Self::new())
}
}

View file

@ -19,13 +19,13 @@ default = ["serde-discriminant"]
serde-discriminant = []
[dependencies]
proc-macro2 = "1"
syn = { version = "2.0", features = ["full"] }
quote = "1.0.9"
proc-macro2 = { workspace = true }
syn = { workspace = true }
quote = { workspace = true }
[dev-dependencies.editor]
path = "../editor"
package = "graphite-editor"
[dev-dependencies]
serde = "1"
serde = { workspace = true }

View file

@ -14,17 +14,14 @@ license = "Apache-2.0"
crate-type = ["cdylib", "rlib"]
[dependencies]
bezier-rs = { path = "../../../../libraries/bezier-rs", package = "bezier-rs" }
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
bezier-rs = { workspace = true }
log = { workspace = true }
serde = { workspace = true, features = ["derive"] }
wasm-bindgen = { workspace = true }
serde_json = "1.0"
serde-wasm-bindgen = "0.5"
js-sys = "0.3.55"
glam = { version = "0.24", features = ["serde"] }
[dev-dependencies]
wasm-bindgen-test = "0.3.22"
serde_json = { workspace = true }
serde-wasm-bindgen = "0.6"
js-sys = { workspace = true }
glam = { workspace = true, features = ["serde"] }
[package.metadata.wasm-pack.profile.dev]
wasm-opt = false