1use std::rc::Rc;
6use std::sync::Arc;
7
8use js::context::JSContext;
9use script_bindings::DomTypes;
10use script_bindings::codegen::GenericBindings::WebGPUBinding::GPUTextureFormat;
11use script_bindings::error::Fallible;
12use servo_base::generic_channel::GenericCallback;
13use webgpu_traits::{
14 Mapping, WebGPU, WebGPUAdapterResponse, WebGPUDevice, WebGPUDeviceResponse,
15 WebGPUExternalTexture, WebGPUQuerySet, WebGPUSampler, WebGPUShaderModule, WebGPUTexture,
16 WebGPUTextureView,
17};
18use wgpu_core::resource::BufferAccessError;
19use wgpu_types::TextureFormat;
20
21use crate::gpu::GPU;
22use crate::gpuadapter::GPUAdapter;
23use crate::gpubuffer::GPUBuffer;
24use crate::identityhub::IdentityHub;
25
26pub trait WebGPUPromiseTrait<D: DomTypes> {
28 fn callback_promise_adapter(
29 self: &Rc<Self>,
30 d: &GPUAdapter<D>,
31 ) -> GenericCallback<WebGPUDeviceResponse>;
32
33 fn callback_promise_gpubuffer(
34 self: &Rc<Self>,
35 d: &GPUBuffer<D>,
36 ) -> GenericCallback<Result<Mapping, BufferAccessError>>;
37
38 fn callback_promise_gpu(self: &Rc<Self>, d: &GPU<D>) -> GenericCallback<WebGPUAdapterResponse>;
39}
40
41pub trait WebGPUGlobalTrait {
42 fn global_wgpu_id_hub(&self) -> Arc<IdentityHub>;
43}
44
45pub trait GPUDeviceTrait<D: DomTypes> {
46 fn is_lost(&self) -> bool;
47 fn id(&self) -> WebGPUDevice;
48 fn channel(&self) -> WebGPU;
49 fn dispatch_error(&self, error: webgpu_traits::Error);
50 fn validate_texture_format_required_features(
51 &self,
52 gpu_texture_format: &GPUTextureFormat,
53 ) -> Fallible<TextureFormat>;
54}
55
56pub trait GPUTextureTrait {
57 fn id(&self) -> WebGPUTexture;
58 fn get_default_view(&self, cx: &mut JSContext) -> WebGPUTextureView;
59}
60
61pub trait GPUTextureViewTrait {
62 fn id(&self) -> WebGPUTextureView;
63}
64
65pub trait GPUSamplerTrait {
66 fn id(&self) -> WebGPUSampler;
67}
68
69pub trait GPUExternalTextureTrait {
70 fn id(&self) -> WebGPUExternalTexture;
71}
72
73pub trait GPUQuerySetTrait {
74 fn id(&self) -> WebGPUQuerySet;
75}
76
77pub trait GPUShaderModuleTrait {
78 fn id(&self) -> WebGPUShaderModule;
79}