@@ -8,15 +8,15 @@ use graph_craft::proto::GraphErrors;
88use graph_craft:: wasm_application_io:: EditorPreferences ;
99use graph_craft:: { ProtoNodeIdentifier , concrete} ;
1010use graphene_std:: Context ;
11- use graphene_std:: application_io:: { NodeGraphUpdateMessage , NodeGraphUpdateSender , RenderConfig } ;
11+ use graphene_std:: application_io:: { ImageTexture , NodeGraphUpdateMessage , NodeGraphUpdateSender , RenderConfig } ;
1212use graphene_std:: instances:: Instance ;
1313use graphene_std:: memo:: IORecord ;
1414use graphene_std:: renderer:: { GraphicElementRendered , RenderParams , SvgRender } ;
1515use graphene_std:: renderer:: { RenderSvgSegmentList , SvgSegment } ;
1616use graphene_std:: text:: FontCache ;
1717use graphene_std:: vector:: style:: ViewMode ;
1818use graphene_std:: vector:: { VectorData , VectorDataTable } ;
19- use graphene_std:: wasm_application_io:: { WasmApplicationIo , WasmEditorApi } ;
19+ use graphene_std:: wasm_application_io:: { RenderOutputType , WasmApplicationIo , WasmEditorApi } ;
2020use interpreted_executor:: dynamic_executor:: { DynamicExecutor , IntrospectError , ResolvedDocumentNodeTypesDelta } ;
2121use interpreted_executor:: util:: wrap_network_in_scope;
2222use once_cell:: sync:: Lazy ;
@@ -131,12 +131,12 @@ impl NodeRuntime {
131131 }
132132 }
133133
134- pub async fn run ( & mut self ) {
134+ pub async fn run ( & mut self ) -> Option < ImageTexture > {
135135 if self . editor_api . application_io . is_none ( ) {
136136 self . editor_api = WasmEditorApi {
137- #[ cfg( not( test) ) ]
137+ #[ cfg( all ( not( test) , target_arch = "wasm32" ) ) ]
138138 application_io : Some ( WasmApplicationIo :: new ( ) . await . into ( ) ) ,
139- #[ cfg( test) ]
139+ #[ cfg( any ( test, not ( target_arch = "wasm32" ) ) ) ]
140140 application_io : Some ( WasmApplicationIo :: new_offscreen ( ) . await . into ( ) ) ,
141141 font_cache : self . editor_api . font_cache . clone ( ) ,
142142 node_graph_message_sender : Box :: new ( self . sender . clone ( ) ) ,
@@ -213,6 +213,16 @@ impl NodeRuntime {
213213 // Resolve the result from the inspection by accessing the monitor node
214214 let inspect_result = self . inspect_state . and_then ( |state| state. access ( & self . executor ) ) ;
215215
216+ let texture = if let Ok ( TaggedValue :: RenderOutput ( RenderOutput {
217+ data : RenderOutputType :: Texture ( texture) ,
218+ ..
219+ } ) ) = & result
220+ {
221+ // We can early return becaus we know that there is at most one execution request and it will always be handled last
222+ Some ( texture. clone ( ) )
223+ } else {
224+ None
225+ } ;
216226 self . sender . send_execution_response ( ExecutionResponse {
217227 execution_id,
218228 result,
@@ -221,9 +231,11 @@ impl NodeRuntime {
221231 vector_modify : self . vector_modify . clone ( ) ,
222232 inspect_result,
223233 } ) ;
234+ return texture;
224235 }
225236 }
226237 }
238+ None
227239 }
228240
229241 async fn update_network ( & mut self , mut graph : NodeNetwork ) -> Result < ResolvedDocumentNodeTypesDelta , String > {
@@ -382,18 +394,30 @@ pub async fn introspect_node(path: &[NodeId]) -> Result<Arc<dyn std::any::Any +
382394 Err ( IntrospectError :: RuntimeNotReady )
383395}
384396
385- pub async fn run_node_graph ( ) -> bool {
386- let Some ( mut runtime) = NODE_RUNTIME . try_lock ( ) else { return false } ;
397+ pub async fn run_node_graph ( ) -> ( bool , Option < ImageTexture > ) {
398+ let Some ( mut runtime) = NODE_RUNTIME . try_lock ( ) else { return ( false , None ) } ;
387399 if let Some ( ref mut runtime) = runtime. as_mut ( ) {
388- runtime. run ( ) . await ;
400+ return ( true , runtime. run ( ) . await ) ;
389401 }
390- true
402+ ( false , None )
391403}
392404
393405pub async fn replace_node_runtime ( runtime : NodeRuntime ) -> Option < NodeRuntime > {
394406 let mut node_runtime = NODE_RUNTIME . lock ( ) ;
395407 node_runtime. replace ( runtime)
396408}
409+ pub async fn replace_application_io ( application_io : WasmApplicationIo ) {
410+ let mut node_runtime = NODE_RUNTIME . lock ( ) ;
411+ if let Some ( node_runtime) = & mut * node_runtime {
412+ node_runtime. editor_api = WasmEditorApi {
413+ font_cache : node_runtime. editor_api . font_cache . clone ( ) ,
414+ application_io : Some ( application_io. into ( ) ) ,
415+ node_graph_message_sender : Box :: new ( node_runtime. sender . clone ( ) ) ,
416+ editor_preferences : Box :: new ( node_runtime. editor_preferences . clone ( ) ) ,
417+ }
418+ . into ( ) ;
419+ }
420+ }
397421
398422/// Which node is inspected and which monitor node is used (if any) for the current execution
399423#[ derive( Debug , Clone , Copy ) ]
0 commit comments