mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 07:48:11 +08:00
Manually check if web gpu support is available (#1372)
* Manually check if web gpu support is available * Add web-sys features * Disable use of unstable apis for non wasm targets
This commit is contained in:
@@ -77,6 +77,8 @@ features = [
|
|||||||
"CanvasRenderingContext2d",
|
"CanvasRenderingContext2d",
|
||||||
"ImageData",
|
"ImageData",
|
||||||
"Document",
|
"Document",
|
||||||
|
"Navigator",
|
||||||
|
"Gpu",
|
||||||
"HtmlCanvasElement",
|
"HtmlCanvasElement",
|
||||||
"ImageBitmapRenderingContext",
|
"ImageBitmapRenderingContext",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -40,11 +40,25 @@ pub struct WasmApplicationIo {
|
|||||||
|
|
||||||
impl WasmApplicationIo {
|
impl WasmApplicationIo {
|
||||||
pub async fn new() -> Self {
|
pub async fn new() -> Self {
|
||||||
|
#[cfg(all(feature = "wgpu", target_arch = "wasm32"))]
|
||||||
|
let executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) {
|
||||||
|
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).unwrap();
|
||||||
|
let function = js_sys::Function::try_from(&request_adapter).unwrap();
|
||||||
|
let result = function.call0(&gpu);
|
||||||
|
match result {
|
||||||
|
Err(_) => None,
|
||||||
|
Ok(_) => WgpuExecutor::new().await,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
#[cfg(all(feature = "wgpu", not(target_arch = "wasm32")))]
|
||||||
|
let executor = None;
|
||||||
let mut io = Self {
|
let mut io = Self {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
ids: RefCell::new(0),
|
ids: RefCell::new(0),
|
||||||
#[cfg(feature = "wgpu")]
|
#[cfg(feature = "wgpu")]
|
||||||
gpu_executor: WgpuExecutor::new().await,
|
gpu_executor: executor,
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
windows: RefCell::new(Vec::new()),
|
windows: RefCell::new(Vec::new()),
|
||||||
resources: HashMap::new(),
|
resources: HashMap::new(),
|
||||||
|
|||||||
Reference in New Issue
Block a user