11use dyn_any:: StaticType ;
2- use graphene_core:: application_io:: SurfaceHandleFrame ;
32use graphene_core:: application_io:: { ApplicationError , ApplicationIo , ResourceFuture , SurfaceHandle , SurfaceId } ;
43#[ cfg( target_arch = "wasm32" ) ]
54use js_sys:: { Object , Reflect } ;
65use std:: collections:: HashMap ;
76use std:: sync:: Arc ;
87#[ cfg( target_arch = "wasm32" ) ]
98use std:: sync:: atomic:: AtomicU64 ;
9+ use std:: sync:: atomic:: Ordering ;
1010#[ cfg( feature = "tokio" ) ]
1111use tokio:: io:: AsyncReadExt ;
1212#[ cfg( target_arch = "wasm32" ) ]
@@ -17,6 +17,7 @@ use wasm_bindgen::JsValue;
1717use web_sys:: HtmlCanvasElement ;
1818#[ cfg( target_arch = "wasm32" ) ]
1919use web_sys:: window;
20+ #[ cfg( feature = "wgpu" ) ]
2021use wgpu_executor:: WgpuExecutor ;
2122
2223#[ derive( Debug ) ]
@@ -76,7 +77,7 @@ pub fn wgpu_available() -> Option<bool> {
7677 }
7778 }
7879
79- match WGPU_AVAILABLE . load ( :: std :: sync :: atomic :: Ordering :: SeqCst ) {
80+ match WGPU_AVAILABLE . load ( Ordering :: SeqCst ) {
8081 -1 => None ,
8182 0 => Some ( false ) ,
8283 _ => Some ( true ) ,
@@ -85,7 +86,7 @@ pub fn wgpu_available() -> Option<bool> {
8586
8687impl WasmApplicationIo {
8788 pub async fn new ( ) -> Self {
88- #[ cfg( target_arch = "wasm32" ) ]
89+ #[ cfg( all ( feature = "wgpu" , target_arch = "wasm32" ) ) ]
8990 let executor = if let Some ( gpu) = web_sys:: window ( ) . map ( |w| w. navigator ( ) . gpu ( ) ) {
9091 let request_adapter = || {
9192 let request_adapter = js_sys:: Reflect :: get ( & gpu, & wasm_bindgen:: JsValue :: from_str ( "requestAdapter" ) ) . ok ( ) ?;
@@ -101,9 +102,14 @@ impl WasmApplicationIo {
101102 None
102103 } ;
103104
104- #[ cfg( not( target_arch = "wasm32" ) ) ]
105+ #[ cfg( all ( feature = "wgpu" , not( target_arch = "wasm32" ) ) ) ]
105106 let executor = WgpuExecutor :: new ( ) . await ;
106- WGPU_AVAILABLE . store ( executor. is_some ( ) as i8 , :: std:: sync:: atomic:: Ordering :: SeqCst ) ;
107+
108+ #[ cfg( not( feature = "wgpu" ) ) ]
109+ let wgpu_available = false ;
110+ #[ cfg( feature = "wgpu" ) ]
111+ let wgpu_available = executor. is_some ( ) ;
112+ WGPU_AVAILABLE . store ( wgpu_available as i8 , Ordering :: SeqCst ) ;
107113
108114 let mut io = Self {
109115 #[ cfg( target_arch = "wasm32" ) ]
@@ -121,9 +127,14 @@ impl WasmApplicationIo {
121127 }
122128
123129 pub async fn new_offscreen ( ) -> Self {
130+ #[ cfg( feature = "wgpu" ) ]
124131 let executor = WgpuExecutor :: new ( ) . await ;
125132
126- WGPU_AVAILABLE . store ( executor. is_some ( ) as i8 , :: std:: sync:: atomic:: Ordering :: SeqCst ) ;
133+ #[ cfg( not( feature = "wgpu" ) ) ]
134+ let wgpu_available = false ;
135+ #[ cfg( feature = "wgpu" ) ]
136+ let wgpu_available = executor. is_some ( ) ;
137+ WGPU_AVAILABLE . store ( wgpu_available as i8 , Ordering :: SeqCst ) ;
127138
128139 // Always enable wgpu when running with Tauri
129140 let mut io = Self {
@@ -175,7 +186,7 @@ impl ApplicationIo for WasmApplicationIo {
175186 let document = window ( ) . expect ( "should have a window in this context" ) . document ( ) . expect ( "window should have a document" ) ;
176187
177188 let canvas: HtmlCanvasElement = document. create_element ( "canvas" ) ?. dyn_into :: < HtmlCanvasElement > ( ) ?;
178- let id = self . ids . fetch_add ( 1 , std :: sync :: atomic :: Ordering :: SeqCst ) ;
189+ let id = self . ids . fetch_add ( 1 , Ordering :: SeqCst ) ;
179190 // store the canvas in the global scope so it doesn't get garbage collected
180191 let window = window ( ) . expect ( "should have a window in this context" ) ;
181192 let window = Object :: from ( window) ;
@@ -299,8 +310,10 @@ impl ApplicationIo for WasmApplicationIo {
299310 }
300311}
301312
313+ #[ cfg( feature = "wgpu" ) ]
302314pub type WasmSurfaceHandle = SurfaceHandle < wgpu_executor:: Window > ;
303- pub type WasmSurfaceHandleFrame = SurfaceHandleFrame < wgpu_executor:: Window > ;
315+ #[ cfg( feature = "wgpu" ) ]
316+ pub type WasmSurfaceHandleFrame = graphene_core:: application_io:: SurfaceHandleFrame < wgpu_executor:: Window > ;
304317
305318#[ derive( Clone , Debug , PartialEq , Hash , specta:: Type ) ]
306319#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
@@ -330,6 +343,6 @@ impl Default for EditorPreferences {
330343 }
331344}
332345
333- unsafe impl dyn_any :: StaticType for EditorPreferences {
346+ unsafe impl StaticType for EditorPreferences {
334347 type Static = EditorPreferences ;
335348}
0 commit comments