Skip to content

Commit 990d5b3

Browse files
Firestar99Keavon
andauthored
Bulk gcore cleanup, replace core and alloc with std (#2735)
* gcore: replace `core` and `alloc` paths with `std` * node-graph: remove unnecessary path prefix * gcore: remove most `#[cfg(target_arch = "spirv")]`, keep some potentially useful ones --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent 301368a commit 990d5b3

46 files changed

Lines changed: 287 additions & 313 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

node-graph/gcore/src/application_io.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
use crate::text::FontCache;
22
use crate::transform::Footprint;
33
use crate::vector::style::ViewMode;
4-
use alloc::sync::Arc;
5-
use core::fmt::Debug;
6-
use core::future::Future;
7-
use core::hash::{Hash, Hasher};
8-
use core::pin::Pin;
9-
use core::ptr::addr_of;
10-
use core::time::Duration;
114
use dyn_any::{DynAny, StaticType, StaticTypeSized};
125
use glam::{DAffine2, UVec2};
6+
use std::fmt::Debug;
7+
use std::future::Future;
8+
use std::hash::{Hash, Hasher};
9+
use std::pin::Pin;
10+
use std::ptr::addr_of;
11+
use std::sync::Arc;
12+
use std::time::Duration;
1313

1414
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1515
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1616
pub struct SurfaceId(pub u64);
1717

18-
impl core::fmt::Display for SurfaceId {
19-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
18+
impl std::fmt::Display for SurfaceId {
19+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2020
f.write_fmt(format_args!("{}", self.0))
2121
}
2222
}
@@ -298,7 +298,7 @@ impl<Io> PartialEq for EditorApi<Io> {
298298
}
299299

300300
impl<T> Debug for EditorApi<T> {
301-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
301+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
302302
f.debug_struct("EditorApi").field("font_cache", &self.font_cache).finish()
303303
}
304304
}

node-graph/gcore/src/context.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::transform::Footprint;
2-
use core::any::Any;
3-
use core::borrow::Borrow;
4-
use core::panic::Location;
2+
use std::any::Any;
3+
use std::borrow::Borrow;
4+
use std::panic::Location;
55
use std::sync::Arc;
66

77
pub trait Ctx: Clone + Send {}
@@ -240,7 +240,7 @@ type DynBox = Box<dyn Any + Send + Sync>;
240240

241241
#[derive(dyn_any::DynAny)]
242242
pub struct OwnedContextImpl {
243-
footprint: Option<crate::transform::Footprint>,
243+
footprint: Option<Footprint>,
244244
varargs: Option<Arc<[DynBox]>>,
245245
parent: Option<Arc<dyn ExtractVarArgs + Sync + Send>>,
246246
// This could be converted into a single enum to save extra bytes
@@ -249,8 +249,8 @@ pub struct OwnedContextImpl {
249249
animation_time: Option<f64>,
250250
}
251251

252-
impl core::fmt::Debug for OwnedContextImpl {
253-
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
252+
impl std::fmt::Debug for OwnedContextImpl {
253+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
254254
f.debug_struct("OwnedContextImpl")
255255
.field("footprint", &self.footprint)
256256
.field("varargs", &self.varargs)
@@ -269,8 +269,8 @@ impl Default for OwnedContextImpl {
269269
}
270270
}
271271

272-
impl core::hash::Hash for OwnedContextImpl {
273-
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
272+
impl std::hash::Hash for OwnedContextImpl {
273+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
274274
self.footprint.hash(state);
275275
self.varargs.as_ref().map(|x| Arc::as_ptr(x).addr()).hash(state);
276276
self.parent.as_ref().map(|x| Arc::as_ptr(x).addr()).hash(state);
@@ -348,7 +348,7 @@ impl OwnedContextImpl {
348348

349349
#[derive(Default, Clone, Copy, dyn_any::DynAny)]
350350
pub struct ContextImpl<'a> {
351-
pub(crate) footprint: Option<&'a crate::transform::Footprint>,
351+
pub(crate) footprint: Option<&'a Footprint>,
352352
varargs: Option<&'a [DynRef<'a>]>,
353353
// This could be converted into a single enum to save extra bytes
354354
index: Option<usize>,

node-graph/gcore/src/generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::Node;
2-
use core::marker::PhantomData;
2+
use std::marker::PhantomData;
33
#[derive(Clone)]
44
pub struct FnNode<T: Fn(I) -> O, I, O>(T, PhantomData<(I, O)>);
55

node-graph/gcore/src/graphic_element.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ impl Default for AlphaBlending {
2626
Self::new()
2727
}
2828
}
29-
impl core::hash::Hash for AlphaBlending {
30-
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
29+
impl Hash for AlphaBlending {
30+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
3131
self.opacity.to_bits().hash(state);
3232
self.fill.to_bits().hash(state);
3333
self.blend_mode.hash(state);

node-graph/gcore/src/graphic_element/renderer.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl FreePoint {
3939

4040
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
4141
pub enum ClickTargetType {
42-
Subpath(bezier_rs::Subpath<PointId>),
42+
Subpath(Subpath<PointId>),
4343
FreePoint(FreePoint),
4444
}
4545

@@ -75,7 +75,7 @@ impl MaskType {
7575
}
7676

7777
impl ClickTarget {
78-
pub fn new_with_subpath(subpath: bezier_rs::Subpath<PointId>, stroke_width: f64) -> Self {
78+
pub fn new_with_subpath(subpath: Subpath<PointId>, stroke_width: f64) -> Self {
7979
let bounding_box = subpath.loose_bounding_box();
8080
Self {
8181
target_type: ClickTargetType::Subpath(subpath),
@@ -300,7 +300,7 @@ impl Default for SvgRender {
300300
#[derive(Clone, Debug, Default)]
301301
pub struct RenderContext {
302302
#[cfg(feature = "wgpu")]
303-
pub resource_overrides: std::collections::HashMap<u64, alloc::sync::Arc<wgpu::Texture>>,
303+
pub resource_overrides: HashMap<u64, std::sync::Arc<wgpu::Texture>>,
304304
}
305305

306306
/// Static state used whilst rendering
@@ -468,7 +468,7 @@ impl GraphicElementRendered for GraphicGroupTable {
468468
peniko::BlendMode::new(blend_mode, peniko::Compose::SrcOver),
469469
opacity,
470470
kurbo::Affine::IDENTITY,
471-
&vello::kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y),
471+
&kurbo::Rect::new(bounds[0].x, bounds[0].y, bounds[1].x, bounds[1].y),
472472
);
473473
layer = true;
474474
}
@@ -756,9 +756,9 @@ impl GraphicElementRendered for VectorDataTable {
756756
let outline_stroke = kurbo::Stroke {
757757
width: LAYER_OUTLINE_STROKE_WEIGHT,
758758
miter_limit: 4.,
759-
join: kurbo::Join::Miter,
760-
start_cap: kurbo::Cap::Butt,
761-
end_cap: kurbo::Cap::Butt,
759+
join: Join::Miter,
760+
start_cap: Cap::Butt,
761+
end_cap: Cap::Butt,
762762
dash_pattern: Default::default(),
763763
dash_offset: 0.,
764764
};
@@ -913,7 +913,7 @@ impl GraphicElementRendered for VectorDataTable {
913913
if let Some(element_id) = element_id {
914914
let stroke_width = instance.style.stroke().as_ref().map_or(0., Stroke::weight);
915915
let filled = instance.style.fill() != &Fill::None;
916-
let fill = |mut subpath: bezier_rs::Subpath<_>| {
916+
let fill = |mut subpath: Subpath<_>| {
917917
if filled {
918918
subpath.set_closed(true);
919919
}
@@ -953,7 +953,7 @@ impl GraphicElementRendered for VectorDataTable {
953953
for instance in self.instance_ref_iter() {
954954
let stroke_width = instance.instance.style.stroke().as_ref().map_or(0., Stroke::weight);
955955
let filled = instance.instance.style.fill() != &Fill::None;
956-
let fill = |mut subpath: bezier_rs::Subpath<_>| {
956+
let fill = |mut subpath: Subpath<_>| {
957957
if filled {
958958
subpath.set_closed(true);
959959
}
@@ -1186,10 +1186,10 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
11861186
if image.data.is_empty() {
11871187
return;
11881188
}
1189-
let image = vello::peniko::Image::new(image.to_flat_u8().0.into(), peniko::Format::Rgba8, image.width, image.height).with_extend(peniko::Extend::Repeat);
1189+
let image = peniko::Image::new(image.to_flat_u8().0.into(), peniko::Format::Rgba8, image.width, image.height).with_extend(peniko::Extend::Repeat);
11901190
let transform = transform * *instance.transform * DAffine2::from_scale(1. / DVec2::new(image.width as f64, image.height as f64));
11911191

1192-
scene.draw_image(&image, vello::kurbo::Affine::new(transform.to_cols_array()));
1192+
scene.draw_image(&image, kurbo::Affine::new(transform.to_cols_array()));
11931193
}
11941194
}
11951195

@@ -1385,7 +1385,7 @@ impl GraphicElementRendered for GraphicElement {
13851385
}
13861386

13871387
/// 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.
1388-
trait Primitive: core::fmt::Display {}
1388+
trait Primitive: std::fmt::Display {}
13891389
impl Primitive for String {}
13901390
impl Primitive for bool {}
13911391
impl Primitive for f32 {}

node-graph/gcore/src/graphic_element/renderer/quad.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Quad {
143143
}
144144
}
145145

146-
impl core::ops::Mul<Quad> for DAffine2 {
146+
impl std::ops::Mul<Quad> for DAffine2 {
147147
type Output = Quad;
148148

149149
fn mul(self, rhs: Quad) -> Self::Output {

node-graph/gcore/src/graphic_element/renderer/rect.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ impl Rect {
9797
}
9898
}
9999

100-
impl core::ops::Mul<Rect> for DAffine2 {
101-
type Output = super::Quad;
100+
impl std::ops::Mul<Rect> for DAffine2 {
101+
type Output = Quad;
102102

103103
fn mul(self, rhs: Rect) -> Self::Output {
104-
self * super::Quad::from_box(rhs.0)
104+
self * Quad::from_box(rhs.0)
105105
}
106106
}
107107

108-
impl core::ops::Index<usize> for Rect {
108+
impl std::ops::Index<usize> for Rect {
109109
type Output = DVec2;
110110
fn index(&self, index: usize) -> &Self::Output {
111111
&self.0[index]
112112
}
113113
}
114-
impl core::ops::IndexMut<usize> for Rect {
114+
impl std::ops::IndexMut<usize> for Rect {
115115
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
116116
&mut self.0[index]
117117
}

node-graph/gcore/src/instances.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ impl<T> Default for Instances<T> {
128128
}
129129
}
130130

131-
impl<T: Hash> core::hash::Hash for Instances<T> {
132-
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
131+
impl<T: Hash> Hash for Instances<T> {
132+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
133133
for instance in &self.instance {
134134
instance.hash(state);
135135
}

node-graph/gcore/src/lib.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
extern crate alloc;
2-
31
#[macro_use]
42
extern crate log;
5-
pub use crate as graphene_core;
6-
pub use num_traits;
73

4+
pub use crate as graphene_core;
85
pub use ctor;
6+
pub use num_traits;
97

108
pub mod animation;
119
pub mod consts;
@@ -35,12 +33,12 @@ pub mod application_io;
3533
pub mod registry;
3634

3735
pub use context::*;
38-
use core::any::TypeId;
39-
use core::future::Future;
40-
use core::pin::Pin;
4136
pub use dyn_any::{StaticTypeSized, WasmNotSend, WasmNotSync};
4237
pub use memo::MemoHash;
4338
pub use raster::Color;
39+
use std::any::TypeId;
40+
use std::future::Future;
41+
use std::pin::Pin;
4442
pub use types::Cow;
4543

4644
// pub trait Node: for<'n> NodeIO<'n> {
@@ -54,11 +52,11 @@ pub trait Node<'i, Input> {
5452
fn reset(&self) {}
5553
/// Returns the name of the node for diagnostic purposes.
5654
fn node_name(&self) -> &'static str {
57-
core::any::type_name::<Self>()
55+
std::any::type_name::<Self>()
5856
}
5957
/// Serialize the node which is used for the `introspect` function which can retrieve values from monitor nodes.
60-
fn serialize(&self) -> Option<std::sync::Arc<dyn core::any::Any + Send + Sync>> {
61-
log::warn!("Node::serialize not implemented for {}", core::any::type_name::<Self>());
58+
fn serialize(&self) -> Option<std::sync::Arc<dyn std::any::Any + Send + Sync>> {
59+
log::warn!("Node::serialize not implemented for {}", std::any::type_name::<Self>());
6260
None
6361
}
6462
}
@@ -75,13 +73,13 @@ where
7573
TypeId::of::<Input::Static>()
7674
}
7775
fn input_type_name(&self) -> &'static str {
78-
core::any::type_name::<Input>()
76+
std::any::type_name::<Input>()
7977
}
80-
fn output_type(&self) -> core::any::TypeId {
78+
fn output_type(&self) -> TypeId {
8179
TypeId::of::<<Self::Output as StaticTypeSized>::Static>()
8280
}
8381
fn output_type_name(&self) -> &'static str {
84-
core::any::type_name::<Self::Output>()
82+
std::any::type_name::<Self::Output>()
8583
}
8684
fn to_node_io(&self, inputs: Vec<Type>) -> NodeIOTypes {
8785
NodeIOTypes {
@@ -122,7 +120,7 @@ impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for Box<
122120
(**self).eval(input)
123121
}
124122
}
125-
impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for alloc::sync::Arc<N> {
123+
impl<'i, I: 'i, O: 'i, N: Node<'i, I, Output = O> + ?Sized> Node<'i, I> for std::sync::Arc<N> {
126124
type Output = O;
127125
fn eval(&'i self, input: I) -> O {
128126
(**self).eval(input)
@@ -148,7 +146,7 @@ pub type WasmSurfaceHandle = application_io::SurfaceHandle<web_sys::HtmlCanvasEl
148146
#[cfg(feature = "wasm")]
149147
pub type WasmSurfaceHandleFrame = application_io::SurfaceHandleFrame<web_sys::HtmlCanvasElement>;
150148

151-
pub trait InputAccessorSource<'a, T>: InputAccessorSourceIdentifier + core::fmt::Debug {
149+
pub trait InputAccessorSource<'a, T>: InputAccessorSourceIdentifier + std::fmt::Debug {
152150
fn get_input(&'a self, index: usize) -> Option<&'a T>;
153151
fn set_input(&'a mut self, index: usize, value: T);
154152
}

node-graph/gcore/src/logic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ use crate::{Color, Context, Ctx};
33
use glam::{DAffine2, DVec2};
44

55
#[node_macro::node(category("Debug"))]
6-
fn log_to_console<T: core::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f64, u32, u64, DVec2, VectorDataTable, DAffine2, Color, Option<Color>)] value: T) -> T {
7-
#[cfg(not(target_arch = "spirv"))]
6+
fn log_to_console<T: std::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f64, u32, u64, DVec2, VectorDataTable, DAffine2, Color, Option<Color>)] value: T) -> T {
87
// KEEP THIS `debug!()` - It acts as the output for the debug node itself
98
log::debug!("{:#?}", value);
109
value
1110
}
1211

1312
#[node_macro::node(category("Text"))]
14-
fn to_string<T: core::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f64, u32, u64, DVec2, VectorDataTable, DAffine2)] value: T) -> String {
13+
fn to_string<T: std::fmt::Debug>(_: impl Ctx, #[implementations(String, bool, f64, u32, u64, DVec2, VectorDataTable, DAffine2)] value: T) -> String {
1514
format!("{:?}", value)
1615
}
1716

0 commit comments

Comments
 (0)