Skip to content

Commit 9c4ab34

Browse files
authored
Extract gsvg_renderer from gcore, remove gcore/vello feature (#2760)
Extract `gsvg_renderer` from `gcore`, remove `gcore/vello` feature
1 parent ffc6c55 commit 9c4ab34

26 files changed

+546
-368
lines changed

Cargo.lock

Lines changed: 19 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"node-graph/gpath-bool",
1111
"node-graph/graph-craft",
1212
"node-graph/graphene-cli",
13+
"node-graph/gsvg-renderer",
1314
"node-graph/interpreted-executor",
1415
"node-graph/node-macro",
1516
"node-graph/preprocessor",
@@ -27,6 +28,7 @@ default-members = [
2728
"node-graph/gpath-bool",
2829
"node-graph/graph-craft",
2930
"node-graph/graphene-cli",
31+
"node-graph/gsvg-renderer",
3032
"node-graph/interpreted-executor",
3133
"node-graph/node-macro",
3234
]
@@ -44,6 +46,7 @@ graphene-core = { path = "node-graph/gcore" }
4446
graphene-path-bool = { path = "node-graph/gpath-bool" }
4547
graph-craft = { path = "node-graph/graph-craft" }
4648
graphene-std = { path = "node-graph/gstd" }
49+
graphene-svg-renderer = { path = "node-graph/gsvg-renderer" }
4750
interpreted-executor = { path = "node-graph/interpreted-executor" }
4851
node-macro = { path = "node-graph/node-macro" }
4952
wgpu-executor = { path = "node-graph/wgpu-executor" }

node-graph/gcore/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ default = ["serde"]
1111
nightly = []
1212
type_id_logging = []
1313
wgpu = ["dep:wgpu"]
14-
vello = ["dep:vello", "bezier-rs/kurbo", "wgpu"]
1514
dealloc_nodes = []
1615

1716
[dependencies]
@@ -23,7 +22,6 @@ bytemuck = { workspace = true }
2322
node-macro = { workspace = true }
2423
num-derive = { workspace = true }
2524
num-traits = { workspace = true }
26-
usvg = { workspace = true }
2725
rand = { workspace = true }
2826
glam = { workspace = true }
2927
serde_json = { workspace = true }
@@ -44,7 +42,6 @@ base64 = { workspace = true }
4442

4543
# Optional workspace dependencies
4644
serde = { workspace = true, optional = true }
47-
vello = { workspace = true, optional = true }
4845
wgpu = { workspace = true, optional = true }
4946

5047
[dev-dependencies]

node-graph/gcore/src/blending.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -238,34 +238,3 @@ impl std::fmt::Display for BlendMode {
238238
}
239239
}
240240
}
241-
242-
#[cfg(feature = "vello")]
243-
impl From<BlendMode> for vello::peniko::Mix {
244-
fn from(val: BlendMode) -> Self {
245-
match val {
246-
// Normal group
247-
BlendMode::Normal => vello::peniko::Mix::Normal,
248-
// Darken group
249-
BlendMode::Darken => vello::peniko::Mix::Darken,
250-
BlendMode::Multiply => vello::peniko::Mix::Multiply,
251-
BlendMode::ColorBurn => vello::peniko::Mix::ColorBurn,
252-
// Lighten group
253-
BlendMode::Lighten => vello::peniko::Mix::Lighten,
254-
BlendMode::Screen => vello::peniko::Mix::Screen,
255-
BlendMode::ColorDodge => vello::peniko::Mix::ColorDodge,
256-
// Contrast group
257-
BlendMode::Overlay => vello::peniko::Mix::Overlay,
258-
BlendMode::SoftLight => vello::peniko::Mix::SoftLight,
259-
BlendMode::HardLight => vello::peniko::Mix::HardLight,
260-
// Inversion group
261-
BlendMode::Difference => vello::peniko::Mix::Difference,
262-
BlendMode::Exclusion => vello::peniko::Mix::Exclusion,
263-
// Component group
264-
BlendMode::Hue => vello::peniko::Mix::Hue,
265-
BlendMode::Saturation => vello::peniko::Mix::Saturation,
266-
BlendMode::Color => vello::peniko::Mix::Color,
267-
BlendMode::Luminosity => vello::peniko::Mix::Luminosity,
268-
_ => todo!(),
269-
}
270-
}
271-
}

node-graph/gcore/src/bounds.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::Color;
2+
use glam::{DAffine2, DVec2};
3+
4+
pub trait BoundingBox {
5+
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]>;
6+
}
7+
8+
macro_rules! none_impl {
9+
($t:path) => {
10+
impl BoundingBox for $t {
11+
fn bounding_box(&self, _transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
12+
None
13+
}
14+
}
15+
};
16+
}
17+
18+
none_impl!(String);
19+
none_impl!(bool);
20+
none_impl!(f32);
21+
none_impl!(f64);
22+
none_impl!(DVec2);
23+
none_impl!(Option<Color>);
24+
none_impl!(Vec<Color>);

node-graph/gcore/src/graphic_element.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::blending::AlphaBlending;
2+
use crate::bounds::BoundingBox;
23
use crate::instances::{Instance, Instances};
4+
use crate::math::quad::Quad;
35
use crate::raster::image::Image;
46
use crate::raster_types::{CPU, GPU, Raster, RasterDataTable};
57
use crate::transform::TransformMut;
68
use crate::uuid::NodeId;
79
use crate::vector::{VectorData, VectorDataTable};
810
use crate::{CloneVarArgs, Color, Context, Ctx, ExtractAll, OwnedContextImpl};
911
use dyn_any::DynAny;
10-
use glam::{DAffine2, IVec2};
12+
use glam::{DAffine2, DVec2, IVec2};
1113
use std::hash::Hash;
1214

13-
pub mod renderer;
14-
1515
// TODO: Eventually remove this migration document upgrade code
1616
pub fn migrate_graphic_group<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<GraphicGroupTable, D::Error> {
1717
use serde::Deserialize;
@@ -182,6 +182,25 @@ impl GraphicElement {
182182
}
183183
}
184184

185+
impl BoundingBox for GraphicElement {
186+
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
187+
match self {
188+
GraphicElement::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
189+
GraphicElement::RasterDataCPU(raster) => raster.bounding_box(transform, include_stroke),
190+
GraphicElement::RasterDataGPU(raster) => raster.bounding_box(transform, include_stroke),
191+
GraphicElement::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
192+
}
193+
}
194+
}
195+
196+
impl BoundingBox for GraphicGroupTable {
197+
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
198+
self.instance_ref_iter()
199+
.filter_map(|element| element.instance.bounding_box(transform * *element.transform, include_stroke))
200+
.reduce(Quad::combine_bounds)
201+
}
202+
}
203+
185204
impl<'de> serde::Deserialize<'de> for Raster<CPU> {
186205
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
187206
where
@@ -247,6 +266,20 @@ impl Artboard {
247266
}
248267
}
249268

269+
impl BoundingBox for Artboard {
270+
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
271+
let artboard_bounds = (transform * Quad::from_box([self.location.as_dvec2(), self.location.as_dvec2() + self.dimensions.as_dvec2()])).bounding_box();
272+
if self.clip {
273+
Some(artboard_bounds)
274+
} else {
275+
[self.graphic_group.bounding_box(transform, include_stroke), Some(artboard_bounds)]
276+
.into_iter()
277+
.flatten()
278+
.reduce(Quad::combine_bounds)
279+
}
280+
}
281+
}
282+
250283
// TODO: Eventually remove this migration document upgrade code
251284
pub fn migrate_artboard_group<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<ArtboardGroupTable, D::Error> {
252285
use serde::Deserialize;
@@ -282,6 +315,14 @@ pub fn migrate_artboard_group<'de, D: serde::Deserializer<'de>>(deserializer: D)
282315

283316
pub type ArtboardGroupTable = Instances<Artboard>;
284317

318+
impl BoundingBox for ArtboardGroupTable {
319+
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
320+
self.instance_ref_iter()
321+
.filter_map(|instance| instance.instance.bounding_box(transform, include_stroke))
322+
.reduce(Quad::combine_bounds)
323+
}
324+
}
325+
285326
#[node_macro::node(category(""))]
286327
async fn layer<I: 'n + Send + Clone>(
287328
_: impl Ctx,
@@ -506,3 +547,7 @@ impl From<GraphicGroupTable> for GraphicElement {
506547
GraphicElement::GraphicGroup(graphic_group)
507548
}
508549
}
550+
551+
pub trait ToGraphicElement {
552+
fn to_graphic_element(&self) -> GraphicElement;
553+
}

node-graph/gcore/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate log;
44
pub mod animation;
55
pub mod blending;
66
pub mod blending_nodes;
7+
pub mod bounds;
78
pub mod color;
89
pub mod consts;
910
pub mod context;

node-graph/gcore/src/raster_types.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use crate::Color;
2+
use crate::bounds::BoundingBox;
23
use crate::instances::Instances;
4+
use crate::math::quad::Quad;
35
use crate::raster::Image;
46
use core::ops::Deref;
57
use dyn_any::DynAny;
8+
use glam::{DAffine2, DVec2};
69
#[cfg(feature = "wgpu")]
710
use std::sync::Arc;
811

@@ -11,18 +14,18 @@ pub struct CPU;
1114
#[derive(Clone, Debug, Hash, PartialEq, Eq, Copy)]
1215
pub struct GPU;
1316

14-
trait Storage {}
17+
trait Storage: 'static {}
1518
impl Storage for CPU {}
1619
impl Storage for GPU {}
1720

1821
#[derive(Clone, Debug, Hash, PartialEq)]
1922
#[allow(private_bounds)]
20-
pub struct Raster<T: 'static + Storage> {
23+
pub struct Raster<T: Storage> {
2124
data: RasterStorage,
2225
storage: T,
2326
}
2427

25-
unsafe impl<T: 'static + Storage> dyn_any::StaticType for Raster<T> {
28+
unsafe impl<T: Storage> dyn_any::StaticType for Raster<T> {
2629
type Static = Raster<T>;
2730
}
2831
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
@@ -100,3 +103,14 @@ impl Deref for Raster<GPU> {
100103
}
101104
}
102105
pub type RasterDataTable<Storage> = Instances<Raster<Storage>>;
106+
107+
impl<S: Storage> BoundingBox for RasterDataTable<S> {
108+
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
109+
self.instance_ref_iter()
110+
.flat_map(|instance| {
111+
let transform = transform * *instance.transform;
112+
(transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())
113+
})
114+
.reduce(Quad::combine_bounds)
115+
}
116+
}

node-graph/gcore/src/vector/click_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::math::math_ext::QuadExt;
2-
use crate::renderer::Quad;
2+
use crate::math::quad::Quad;
33
use crate::vector::PointId;
44
use bezier_rs::Subpath;
55
use glam::{DAffine2, DMat2, DVec2};

0 commit comments

Comments
 (0)