diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-02-11 11:23:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 11:23:59 -0500 |
commit | 419954474b6d14f06d0dfb2d6696a128e3f5df15 (patch) | |
tree | 5cf6d8839db7dbddd37dc5b43a8e9d896553e888 /components/script/dom/gpushadermodule.rs | |
parent | 55058b28755646d3305bd58a725205311ac9607d (diff) | |
parent | a8621c4ed9d87f6d168fd9b70e0cf501a4033632 (diff) | |
download | servo-419954474b6d14f06d0dfb2d6696a128e3f5df15.tar.gz servo-419954474b6d14f06d0dfb2d6696a128e3f5df15.zip |
Auto merge of #25677 - szeged:wgpu_shader_module, r=jdm
Initial implementation of GPUShaderModule
Added WebIDL bindings for `GPUShaderModule`.
Implemented the `createShaderModule` function of `GPUDevice`.
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes addresses a part of #24706
<!-- Either: -->
cc @kvark @jdm @zakorgy
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components/script/dom/gpushadermodule.rs')
-rw-r--r-- | components/script/dom/gpushadermodule.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/components/script/dom/gpushadermodule.rs b/components/script/dom/gpushadermodule.rs new file mode 100644 index 00000000000..215a0efc100 --- /dev/null +++ b/components/script/dom/gpushadermodule.rs @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use crate::dom::bindings::cell::DomRefCell; +use crate::dom::bindings::codegen::Bindings::GPUShaderModuleBinding::{ + self, GPUShaderModuleMethods, +}; +use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::root::DomRoot; +use crate::dom::bindings::str::DOMString; +use crate::dom::globalscope::GlobalScope; +use dom_struct::dom_struct; +use webgpu::WebGPUShaderModule; + +#[dom_struct] +pub struct GPUShaderModule { + reflector_: Reflector, + label: DomRefCell<Option<DOMString>>, + shader_module: WebGPUShaderModule, +} + +impl GPUShaderModule { + fn new_inherited(shader_module: WebGPUShaderModule) -> GPUShaderModule { + Self { + reflector_: Reflector::new(), + label: DomRefCell::new(None), + shader_module, + } + } + + pub fn new( + global: &GlobalScope, + shader_module: WebGPUShaderModule, + ) -> DomRoot<GPUShaderModule> { + reflect_dom_object( + Box::new(GPUShaderModule::new_inherited(shader_module)), + global, + GPUShaderModuleBinding::Wrap, + ) + } +} + +impl GPUShaderModuleMethods for GPUShaderModule { + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn GetLabel(&self) -> Option<DOMString> { + self.label.borrow().clone() + } + + /// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label + fn SetLabel(&self, value: Option<DOMString>) { + *self.label.borrow_mut() = value; + } +} |