1use std::rc::Rc;
6use std::sync::Arc;
7
8use script_webgpu::traits::{WebGPUGlobalTrait, WebGPUPromiseTrait};
9use webgpu_traits::Mapping;
10use wgpu_core::resource::BufferAccessError;
11
12use crate::dom::bindings::reflector::DomGlobal;
13use crate::dom::gpu::GPU;
14use crate::dom::types::{GPUAdapter, GPUBuffer};
15use crate::dom::{GlobalScope, Promise};
16use crate::routed_promise::callback_promise;
17
18pub(crate) mod gpu_promise_listener;
19pub(crate) mod gpu {
20 #[expect(clippy::upper_case_acronyms)]
21 pub(crate) type GPU = script_webgpu::gpu::GPU<crate::DomTypeHolder>;
22}
23pub(crate) mod gpuadapter_promise_listener;
24pub(crate) mod gpuadapter {
25 pub(crate) type GPUAdapter = script_webgpu::gpuadapter::GPUAdapter<crate::DomTypeHolder>;
26}
27pub(crate) mod gpuadapterinfo {
28 pub(crate) type GPUAdapterInfo =
29 script_webgpu::gpuadapterinfo::GPUAdapterInfo<crate::DomTypeHolder>;
30}
31pub(crate) mod gpubindgroup {
32 pub(crate) type GPUBindGroup = script_webgpu::gpubindgroup::GPUBindGroup<crate::DomTypeHolder>;
33}
34pub(crate) mod gpubindgrouplayout {
35 pub(crate) type GPUBindGroupLayout =
36 script_webgpu::gpubindgrouplayout::GPUBindGroupLayout<crate::DomTypeHolder>;
37}
38pub(crate) mod gpubuffer_promise_listener;
39pub(crate) mod gpubuffer {
40 pub(crate) type GPUBuffer = script_webgpu::gpubuffer::GPUBuffer<crate::DomTypeHolder>;
41}
42pub(crate) mod gpubufferusage {
43 pub(crate) type GPUBufferUsage =
44 script_webgpu::gpubufferusage::GPUBufferUsage<crate::DomTypeHolder>;
45}
46pub(crate) mod gpucanvascontext;
47pub(crate) mod gpucolorwrite {
48 pub(crate) type GPUColorWrite =
49 script_webgpu::gpucolorwrite::GPUColorWrite<crate::DomTypeHolder>;
50}
51pub(crate) mod gpucommandbuffer {
52 pub(crate) type GPUCommandBuffer =
53 script_webgpu::gpucommandbuffer::GPUCommandBuffer<crate::DomTypeHolder>;
54}
55pub(crate) mod gpucommandencoder;
56pub(crate) mod gpucompilationinfo {
57 pub(crate) type GPUCompilationInfo =
58 script_webgpu::gpucompilationinfo::GPUCompilationInfo<crate::DomTypeHolder>;
59}
60pub(crate) mod gpucompilationmessage {
61 pub(crate) type GPUCompilationMessage =
62 script_webgpu::gpucompilationmessage::GPUCompilationMessage<crate::DomTypeHolder>;
63}
64pub(crate) mod gpucomputepassencoder;
65pub(crate) mod gpucomputepipeline;
66pub(crate) mod gpudevice;
67pub(crate) mod gpudevicelostinfo {
68 pub(crate) type GPUDeviceLostInfo =
69 script_webgpu::gpudevicelostinfo::GPUDeviceLostInfo<crate::DomTypeHolder>;
70}
71pub(crate) mod gpuerror;
72pub(crate) mod gpuexternaltexture;
73pub(crate) mod gpuinternalerror;
74pub(crate) mod gpumapmode {
75 pub(crate) type GPUMapMode = script_webgpu::gpumapmode::GPUMapMode<crate::DomTypeHolder>;
76}
77pub(crate) mod gpuoutofmemoryerror;
78pub(crate) mod gpupipelineerror;
79#[expect(dead_code)]
80pub(crate) mod gpupipelinelayout;
81pub(crate) mod gpuqueryset;
82pub(crate) mod gpuqueue;
83pub(crate) mod gpurenderbundle {
84 pub(crate) type GPURenderBundle =
85 script_webgpu::gpurenderbundle::GPURenderBundle<crate::DomTypeHolder>;
86}
87pub(crate) mod gpurenderbundleencoder;
88pub(crate) mod gpurenderpassencoder;
89pub(crate) mod gpurenderpipeline;
90pub(crate) mod gpusampler;
91pub(crate) mod gpushadermodule;
92pub(crate) mod gpushaderstage {
93 pub(crate) type GPUShaderStage =
94 script_webgpu::gpushaderstage::GPUShaderStage<crate::DomTypeHolder>;
95}
96pub(crate) mod gpusupportedfeatures {
97 pub(crate) type GPUSupportedFeatures =
98 script_webgpu::gpusupportedfeatures::GPUSupportedFeatures<crate::DomTypeHolder>;
99}
100pub(crate) mod gpusupportedlimits {
101 pub(crate) type GPUSupportedLimits =
102 script_webgpu::gpusupportedlimits::GPUSupportedLimits<crate::DomTypeHolder>;
103}
104pub(crate) mod gputexture;
105pub(crate) mod gputextureusage {
106 pub(crate) type GPUTextureUsage =
107 script_webgpu::gputextureusage::GPUTextureUsage<crate::DomTypeHolder>;
108}
109pub(crate) mod gputextureview;
110pub(crate) mod gpuuncapturederrorevent;
111pub(crate) mod gpuvalidationerror;
112pub(crate) mod identityhub {
113 pub(crate) type IdentityHub = script_webgpu::identityhub::IdentityHub;
114}
115pub(crate) mod wgsllanguagefeatures {
116 pub(crate) type WGSLLanguageFeatures =
117 script_webgpu::wgsllanguagefeatures::WGSLLanguageFeatures<crate::DomTypeHolder>;
118}
119
120impl WebGPUPromiseTrait<crate::DomTypeHolder> for Promise {
121 fn callback_promise_adapter(
122 self: &Rc<Self>,
123 d: &GPUAdapter,
124 ) -> servo_base::generic_channel::GenericCallback<webgpu_traits::WebGPUDeviceResponse> {
125 let task_manager = <GPUAdapter as DomGlobal>::global(d).task_manager();
126 callback_promise(self, d, task_manager.dom_manipulation_task_source())
127 }
128
129 fn callback_promise_gpubuffer(
130 self: &Rc<Self>,
131 d: &GPUBuffer,
132 ) -> servo_base::generic_channel::GenericCallback<Result<Mapping, BufferAccessError>> {
133 let task_manager = <GPUBuffer as DomGlobal>::global(d).task_manager();
134 callback_promise(self, d, task_manager.dom_manipulation_task_source())
135 }
136
137 fn callback_promise_gpu(
138 self: &Rc<Self>,
139 d: &GPU,
140 ) -> servo_base::generic_channel::GenericCallback<webgpu_traits::WebGPUAdapterResponse> {
141 let task_manager = <GPU as DomGlobal>::global(d).task_manager();
142 callback_promise(self, d, task_manager.dom_manipulation_task_source())
143 }
144}
145
146impl WebGPUGlobalTrait for GlobalScope {
147 fn global_wgpu_id_hub(&self) -> Arc<script_webgpu::identityhub::IdentityHub> {
148 self.wgpu_id_hub()
149 }
150}