mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 23:38:06 +08:00
* Generate stable node ids * checkpoint * Implement borrow tree * Add eval function on borrow tree * Refactor Node trait to fix lifetime issues * Compiler infinite loop * Impl compose pair * Transition to double lifetime on trait * Change node trait to use a generic arg for the input * Start adapting node_macro * Migrate more nodes to new macro * Fix raster tests * Port vector nodes * Make Node trait object safe * Fix FlatMapResultNode * Translate most of gstd * Fix DowncastBothNode * Refactor node trait once again to allow for HRTB for type erased nodes * Start working on type erased nodes * Try getting DowncastBothNode to work * Introduce Upcasting node + work on BorrowTree * Make enough 'static to get the code to compile * Transition DynamicExecutor to use borrow tree * Make Compose Node use HRTB's * Fix MapResultNode * Disable blur test * Add workaround for Composing type erased nodes * Convert more nodes in the node_registry * Convert more of the node_registry * Add update tree fn and hook up to frontend * Fix blur node * Implement CacheNode * Make frontend use graph compiler * Fix document_node_types type declaration for most nodes * Remove unused imports * Move comment down * Reuse nodes via borrow tree * Deprecate trait based value in favor of TaggedValue * Remove unsafe code in buffer creation * Fix blur node * Fix stable node id generation * Fix types for Image adjustment document nodes * Fix Imaginate Node * Remove unused imports * Remove log * Fix off by one error * Remove macro generated imaginate node entry * Create parameterized add node * Fix test case * Remove link from layer_panel.rs * Fix formatting
118 lines
3.2 KiB
Rust
118 lines
3.2 KiB
Rust
#[macro_use]
|
|
extern crate log;
|
|
|
|
pub mod executor;
|
|
pub mod node_registry;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
|
|
use dyn_any::IntoDynAny;
|
|
|
|
/*
|
|
#[test]
|
|
fn borrow_stack() {
|
|
let stack = borrow_stack::FixedSizeStack::new(256);
|
|
unsafe {
|
|
let dynanynode: DynAnyNode<ValueNode<u32>, (), _, _> = DynAnyNode::new(ValueNode(2_u32));
|
|
stack.push(dynanynode.into_box());
|
|
}
|
|
stack.push_fn(|nodes| {
|
|
let pre_node = nodes.get(0).unwrap();
|
|
let downcast: DowncastNode<&TypeErasedNode, &u32> = DowncastNode::new(pre_node);
|
|
let dynanynode: DynAnyNode<ConsNode<_, Any<'_>>, u32, _, _> = DynAnyNode::new(ConsNode(downcast, PhantomData));
|
|
dynanynode.into_box()
|
|
});
|
|
stack.push_fn(|_| {
|
|
let dynanynode: DynAnyNode<_, (u32, &u32), _, _> = DynAnyNode::new(AddNode);
|
|
dynanynode.into_box()
|
|
});
|
|
stack.push_fn(|nodes| {
|
|
let compose_node = nodes[1].after(&nodes[2]);
|
|
TypeErasedNode(Box::pin(compose_node))
|
|
});
|
|
|
|
let result = unsafe { &stack.get()[0] }.eval_ref(().into_dyn());
|
|
assert_eq!(*downcast::<&u32>(result).unwrap(), &2_u32);
|
|
let result = unsafe { &stack.get()[1] }.eval_ref(4_u32.into_dyn());
|
|
assert_eq!(*downcast::<(u32, &u32)>(result).unwrap(), (4_u32, &2_u32));
|
|
let result = unsafe { &stack.get()[1] }.eval_ref(4_u32.into_dyn());
|
|
let add = unsafe { &stack.get()[2] }.eval_ref(result);
|
|
assert_eq!(*downcast::<u32>(add).unwrap(), 6_u32);
|
|
let add = unsafe { &stack.get()[3] }.eval_ref(4_u32.into_dyn());
|
|
assert_eq!(*downcast::<u32>(add).unwrap(), 6_u32);
|
|
}*/
|
|
|
|
#[test]
|
|
fn execute_add() {
|
|
use graph_craft::document::*;
|
|
use graph_craft::proto::*;
|
|
use graph_craft::*;
|
|
|
|
fn add_network() -> NodeNetwork {
|
|
NodeNetwork {
|
|
inputs: vec![0, 0],
|
|
output: 1,
|
|
nodes: [
|
|
(
|
|
0,
|
|
DocumentNode {
|
|
name: "Cons".into(),
|
|
inputs: vec![NodeInput::Network, NodeInput::Network],
|
|
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::structural::ConsNode<_, _>", &[concrete!("u32"), concrete!("u32")])),
|
|
metadata: DocumentNodeMetadata::default(),
|
|
},
|
|
),
|
|
(
|
|
1,
|
|
DocumentNode {
|
|
name: "Add".into(),
|
|
inputs: vec![NodeInput::Node(0)],
|
|
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::AddNode", &[concrete!("(u32, u32)")])),
|
|
metadata: DocumentNodeMetadata::default(),
|
|
},
|
|
),
|
|
]
|
|
.into_iter()
|
|
.collect(),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
let network = NodeNetwork {
|
|
inputs: vec![0],
|
|
output: 0,
|
|
nodes: [(
|
|
0,
|
|
DocumentNode {
|
|
name: "Inc".into(),
|
|
inputs: vec![
|
|
NodeInput::Network,
|
|
NodeInput::Value {
|
|
tagged_value: value::TaggedValue::U32(1),
|
|
exposed: false,
|
|
},
|
|
],
|
|
implementation: DocumentNodeImplementation::Network(add_network()),
|
|
metadata: DocumentNodeMetadata::default(),
|
|
},
|
|
)]
|
|
.into_iter()
|
|
.collect(),
|
|
..Default::default()
|
|
};
|
|
|
|
use crate::executor::DynamicExecutor;
|
|
use graph_craft::executor::{Compiler, Executor};
|
|
|
|
let compiler = Compiler {};
|
|
let protograph = compiler.compile(network, true);
|
|
|
|
let exec = DynamicExecutor::new(protograph);
|
|
|
|
let result = exec.execute(32_u32.into_dyn()).unwrap();
|
|
let val = *dyn_any::downcast::<u32>(result).unwrap();
|
|
assert_eq!(val, 33_u32);
|
|
}
|
|
}
|