mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-03 21:08:18 +00:00
Store Input for Monitor Nodes (#1454)
* Add input storage to monitor_node * Return input via serialize function
This commit is contained in:
parent
58660f5548
commit
81519601ae
5 changed files with 51 additions and 32 deletions
|
@ -45,32 +45,48 @@ impl<T, CachedNode> MemoNode<T, CachedNode> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IORecord<I, O> {
|
||||
pub input: I,
|
||||
pub output: O,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
/// Caches the output of the last graph evaluation for introspection
|
||||
#[derive(Default)]
|
||||
pub struct MonitorNode<T> {
|
||||
output: Cell<Option<Arc<T>>>,
|
||||
pub struct MonitorNode<I, T, N> {
|
||||
io: Cell<Option<Arc<IORecord<I, T>>>>,
|
||||
node: N,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<'i, T: 'static + Clone> Node<'i, T> for MonitorNode<T> {
|
||||
type Output = T;
|
||||
fn eval(&'i self, input: T) -> Self::Output {
|
||||
self.output.set(Some(Arc::new(input.clone())));
|
||||
input
|
||||
impl<'i, 'a: 'i, T, I, N> Node<'i, I> for MonitorNode<I, T, N>
|
||||
where
|
||||
I: Clone + 'static,
|
||||
<N as Node<'i, I>>::Output: Future<Output = T>,
|
||||
T: Clone + 'static,
|
||||
N: Node<'i, I>,
|
||||
{
|
||||
type Output = Pin<Box<dyn Future<Output = T> + 'i>>;
|
||||
fn eval(&'i self, input: I) -> Self::Output {
|
||||
Box::pin(async move {
|
||||
let output = self.node.eval(input.clone()).await;
|
||||
self.io.set(Some(Arc::new(IORecord { input, output: output.clone() })));
|
||||
output
|
||||
})
|
||||
}
|
||||
|
||||
fn serialize(&self) -> Option<Arc<dyn core::any::Any>> {
|
||||
let out = self.output.take();
|
||||
self.output.set(out.clone());
|
||||
(out).as_ref().map(|output| output.clone() as Arc<dyn core::any::Any>)
|
||||
let io = self.io.take();
|
||||
self.io.set(io.clone());
|
||||
(io).as_ref().map(|output| output.clone() as Arc<dyn core::any::Any>)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<T> MonitorNode<T> {
|
||||
pub const fn new() -> MonitorNode<T> {
|
||||
MonitorNode { output: Cell::new(None) }
|
||||
impl<I, T, N> MonitorNode<I, T, N> {
|
||||
pub const fn new(node: N) -> MonitorNode<I, T, N> {
|
||||
MonitorNode { io: Cell::new(None), node }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ pub mod node_registry;
|
|||
mod tests {
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graphene_core::*;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use futures::executor::block_on;
|
||||
|
||||
|
@ -95,7 +94,7 @@ mod tests {
|
|||
0,
|
||||
DocumentNode {
|
||||
name: "id".into(),
|
||||
inputs: vec![NodeInput::ShortCircut(concrete!(u32))],
|
||||
inputs: vec![NodeInput::Network(concrete!(u32))],
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdNode")),
|
||||
..Default::default()
|
||||
},
|
||||
|
|
|
@ -327,9 +327,9 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
|
|||
),
|
||||
)],
|
||||
register_node!(graphene_std::raster::EmptyImageNode<_, _>, input: DAffine2, params: [Color]),
|
||||
register_node!(graphene_core::memo::MonitorNode<_>, input: ImageFrame<Color>, params: []),
|
||||
register_node!(graphene_core::memo::MonitorNode<_>, input: VectorData, params: []),
|
||||
register_node!(graphene_core::memo::MonitorNode<_>, input: graphene_core::GraphicElementData, params: []),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Footprint, output: ImageFrame<Color>, fn_params: [Footprint => ImageFrame<Color>]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Footprint, output: VectorData, fn_params: [Footprint => VectorData]),
|
||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Footprint, output: graphene_core::GraphicElementData, fn_params: [Footprint => graphene_core::GraphicElementData]),
|
||||
async_node!(graphene_std::wasm_application_io::LoadResourceNode<_>, input: WasmEditorApi, output: Arc<[u8]>, params: [String]),
|
||||
register_node!(graphene_std::wasm_application_io::DecodeImageNode, input: Arc<[u8]>, params: []),
|
||||
async_node!(graphene_std::wasm_application_io::CreateSurfaceNode, input: WasmEditorApi, output: Arc<SurfaceHandle<<graphene_std::wasm_application_io::WasmApplicationIo as graphene_core::application_io::ApplicationIo>::Surface>>, params: []),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue