diff options
author | Taym Haddadi <haddadi.taym@gmail.com> | 2024-09-06 23:58:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 21:58:13 +0000 |
commit | 152e62022a8c69d28c217b0fce651fd2d02dc08f (patch) | |
tree | 5e83c0cd1a49cfa8b163891427b6044d083de258 /components/script | |
parent | bc04f94a301b1575a1bca90e145778d3596e7b1b (diff) | |
download | servo-152e62022a8c69d28c217b0fce651fd2d02dc08f.tar.gz servo-152e62022a8c69d28c217b0fce651fd2d02dc08f.zip |
Move convert_label to Into implementation (#33348)
Signed-off-by: Taym <haddadi.taym@gmail.com>
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/gpubindgroup.rs | 3 | ||||
-rw-r--r-- | components/script/dom/gpubindgrouplayout.rs | 4 | ||||
-rw-r--r-- | components/script/dom/gpubuffer.rs | 3 | ||||
-rw-r--r-- | components/script/dom/gpucommandencoder.rs | 9 | ||||
-rw-r--r-- | components/script/dom/gpucomputepipeline.rs | 3 | ||||
-rw-r--r-- | components/script/dom/gpuconvert.rs | 13 | ||||
-rw-r--r-- | components/script/dom/gpudevice.rs | 3 | ||||
-rw-r--r-- | components/script/dom/gpupipelinelayout.rs | 3 | ||||
-rw-r--r-- | components/script/dom/gpurenderbundleencoder.rs | 5 | ||||
-rw-r--r-- | components/script/dom/gpusampler.rs | 3 | ||||
-rw-r--r-- | components/script/dom/gputexture.rs | 5 |
11 files changed, 23 insertions, 31 deletions
diff --git a/components/script/dom/gpubindgroup.rs b/components/script/dom/gpubindgroup.rs index 2aae7174265..9c7e248853a 100644 --- a/components/script/dom/gpubindgroup.rs +++ b/components/script/dom/gpubindgroup.rs @@ -17,7 +17,6 @@ use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpudevice::GPUDevice; #[dom_struct] @@ -86,7 +85,7 @@ impl GPUBindGroup { .collect::<Vec<_>>(); let desc = BindGroupDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), layout: descriptor.layout.id().0, entries: Cow::Owned(entries), }; diff --git a/components/script/dom/gpubindgrouplayout.rs b/components/script/dom/gpubindgrouplayout.rs index 875eff8e3fc..18a351079fb 100644 --- a/components/script/dom/gpubindgrouplayout.rs +++ b/components/script/dom/gpubindgrouplayout.rs @@ -17,7 +17,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; -use crate::dom::gpuconvert::{convert_bind_group_layout_entry, convert_label}; +use crate::dom::gpuconvert::convert_bind_group_layout_entry; use crate::dom::gpudevice::GPUDevice; #[dom_struct] @@ -80,7 +80,7 @@ impl GPUBindGroupLayout { let desc = match entries { Ok(entries) => Some(BindGroupLayoutDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), entries: Cow::Owned(entries), }), Err(error) => { diff --git a/components/script/dom/gpubuffer.rs b/components/script/dom/gpubuffer.rs index 3b5631bce7c..43cdabee98e 100644 --- a/components/script/dom/gpubuffer.rs +++ b/components/script/dom/gpubuffer.rs @@ -16,7 +16,6 @@ use super::bindings::buffer_source::DataBlock; use super::bindings::codegen::Bindings::WebGPUBinding::{ GPUBufferDescriptor, GPUBufferMapState, GPUFlagsConstant, GPUMapModeFlags, }; -use super::gpuconvert::convert_label; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ GPUBufferMethods, GPUMapModeConstants, GPUSize64, @@ -138,7 +137,7 @@ impl GPUBuffer { descriptor: &GPUBufferDescriptor, ) -> Fallible<DomRoot<GPUBuffer>> { let desc = wgt::BufferDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), size: descriptor.size as wgt::BufferAddress, usage: wgt::BufferUsages::from_bits_retain(descriptor.usage), mapped_at_creation: descriptor.mappedAtCreation, diff --git a/components/script/dom/gpucommandencoder.rs b/components/script/dom/gpucommandencoder.rs index 6b930932bb7..16754b721df 100644 --- a/components/script/dom/gpucommandencoder.rs +++ b/components/script/dom/gpucommandencoder.rs @@ -10,7 +10,6 @@ use webgpu::{ }; use super::bindings::error::Fallible; -use super::gpuconvert::convert_label; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ GPUCommandBufferDescriptor, GPUCommandEncoderDescriptor, GPUCommandEncoderMethods, @@ -97,7 +96,7 @@ impl GPUCommandEncoder { device_id: device.id().0, command_encoder_id, desc: wgt::CommandEncoderDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), }, }) .expect("Failed to create WebGPU command encoder"); @@ -138,7 +137,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { if let Err(e) = self.channel.0.send(WebGPURequest::BeginComputePass { command_encoder_id: self.id().0, compute_pass_id, - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), device_id: self.device.id().0, }) { warn!("Failed to send WebGPURequest::BeginComputePass {e:?}"); @@ -206,7 +205,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { if let Err(e) = self.channel.0.send(WebGPURequest::BeginRenderPass { command_encoder_id: self.id().0, render_pass_id, - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), depth_stencil_attachment, color_attachments, device_id: self.device.id().0, @@ -313,7 +312,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { command_encoder_id: self.encoder.0, device_id: self.device.id().0, desc: wgt::CommandBufferDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), }, }) .expect("Failed to send Finish"); diff --git a/components/script/dom/gpucomputepipeline.rs b/components/script/dom/gpucomputepipeline.rs index bf58302da52..6c69c07900a 100644 --- a/components/script/dom/gpucomputepipeline.rs +++ b/components/script/dom/gpucomputepipeline.rs @@ -17,7 +17,6 @@ use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpudevice::GPUDevice; #[dom_struct] @@ -83,7 +82,7 @@ impl GPUComputePipeline { let (layout, implicit_ids, _) = device.get_pipeline_layout_data(&descriptor.parent.layout); let desc = ComputePipelineDescriptor { - label: convert_label(&descriptor.parent.parent), + label: (&descriptor.parent.parent).into(), layout, stage: (&descriptor.compute).into(), cache: None, diff --git a/components/script/dom/gpuconvert.rs b/components/script/dom/gpuconvert.rs index 1eb7c9fb977..2c3b05f5cfa 100644 --- a/components/script/dom/gpuconvert.rs +++ b/components/script/dom/gpuconvert.rs @@ -497,14 +497,15 @@ impl TryFrom<&GPUImageCopyTexture> for wgpu_com::ImageCopyTexture { } } -pub fn convert_label<'a>(parent: &GPUObjectDescriptorBase) -> Option<Cow<'a, str>> { - if parent.label.is_empty() { - None - } else { - Some(Cow::Owned(parent.label.to_string())) +impl<'a> Into<Option<Cow<'a, str>>> for &GPUObjectDescriptorBase { + fn into(self) -> Option<Cow<'a, str>> { + if self.label.is_empty() { + None + } else { + Some(Cow::Owned(self.label.to_string())) + } } } - pub fn convert_bind_group_layout_entry( bgle: &GPUBindGroupLayoutEntry, device: &GPUDevice, diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index 33daf8217b9..67b806b8550 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -52,7 +52,6 @@ use crate::dom::gpubindgrouplayout::GPUBindGroupLayout; use crate::dom::gpubuffer::GPUBuffer; use crate::dom::gpucommandencoder::GPUCommandEncoder; use crate::dom::gpucomputepipeline::GPUComputePipeline; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpupipelinelayout::GPUPipelineLayout; use crate::dom::gpuqueue::GPUQueue; use crate::dom::gpurenderbundleencoder::GPURenderBundleEncoder; @@ -246,7 +245,7 @@ impl GPUDevice { let (layout, implicit_ids, _) = self.get_pipeline_layout_data(&descriptor.parent.layout); let desc = wgpu_pipe::RenderPipelineDescriptor { - label: convert_label(&descriptor.parent.parent), + label: (&descriptor.parent.parent).into(), layout, cache: None, vertex: wgpu_pipe::VertexState { diff --git a/components/script/dom/gpupipelinelayout.rs b/components/script/dom/gpupipelinelayout.rs index 00d7e4a0cec..e851458e637 100644 --- a/components/script/dom/gpupipelinelayout.rs +++ b/components/script/dom/gpupipelinelayout.rs @@ -16,7 +16,6 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpudevice::GPUDevice; #[dom_struct] @@ -88,7 +87,7 @@ impl GPUPipelineLayout { .collect::<Vec<_>>(); let desc = PipelineLayoutDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), bind_group_layouts: Cow::Owned(bgls.iter().map(|l| l.0).collect::<Vec<_>>()), push_constant_ranges: Cow::Owned(vec![]), }; diff --git a/components/script/dom/gpurenderbundleencoder.rs b/components/script/dom/gpurenderbundleencoder.rs index 483e3e5ef32..b32a7ac17a9 100644 --- a/components/script/dom/gpurenderbundleencoder.rs +++ b/components/script/dom/gpurenderbundleencoder.rs @@ -22,7 +22,6 @@ use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; use crate::dom::gpubindgroup::GPUBindGroup; use crate::dom::gpubuffer::GPUBuffer; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpudevice::GPUDevice; use crate::dom::gpurenderbundle::GPURenderBundle; use crate::dom::gpurenderpipeline::GPURenderPipeline; @@ -82,7 +81,7 @@ impl GPURenderBundleEncoder { descriptor: &GPURenderBundleEncoderDescriptor, ) -> Fallible<DomRoot<GPURenderBundleEncoder>> { let desc = RenderBundleEncoderDescriptor { - label: convert_label(&descriptor.parent.parent), + label: (&descriptor.parent.parent).into(), color_formats: Cow::Owned( descriptor .parent @@ -253,7 +252,7 @@ impl GPURenderBundleEncoderMethods for GPURenderBundleEncoder { /// <https://gpuweb.github.io/gpuweb/#dom-gpurenderbundleencoder-finish> fn Finish(&self, descriptor: &GPURenderBundleDescriptor) -> DomRoot<GPURenderBundle> { let desc = wgt::RenderBundleDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), }; let encoder = self.render_bundle_encoder.borrow_mut().take().unwrap(); let render_bundle_id = self diff --git a/components/script/dom/gpusampler.rs b/components/script/dom/gpusampler.rs index 874d907e069..baf987aa467 100644 --- a/components/script/dom/gpusampler.rs +++ b/components/script/dom/gpusampler.rs @@ -14,7 +14,6 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpudevice::GPUDevice; #[dom_struct] @@ -83,7 +82,7 @@ impl GPUSampler { .create_sampler_id(device.id().0.backend()); let compare_enable = descriptor.compare.is_some(); let desc = SamplerDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), address_modes: [ descriptor.addressModeU.into(), descriptor.addressModeV.into(), diff --git a/components/script/dom/gputexture.rs b/components/script/dom/gputexture.rs index 7f0d64e9336..df2e5ca83c8 100644 --- a/components/script/dom/gputexture.rs +++ b/components/script/dom/gputexture.rs @@ -19,7 +19,6 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::{Dom, DomRoot}; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; -use crate::dom::gpuconvert::convert_label; use crate::dom::gpudevice::GPUDevice; use crate::dom::gputextureview::GPUTextureView; @@ -136,7 +135,7 @@ impl GPUTexture { ) -> Fallible<DomRoot<GPUTexture>> { let size = (&descriptor.size).try_into()?; let desc = wgt::TextureDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), size, mip_level_count: descriptor.mipLevelCount, sample_count: descriptor.sampleCount, @@ -203,7 +202,7 @@ impl GPUTextureMethods for GPUTexture { !matches!(descriptor.arrayLayerCount, Some(0)) { Some(resource::TextureViewDescriptor { - label: convert_label(&descriptor.parent), + label: (&descriptor.parent).into(), format: descriptor .format .map(|f| self.device.validate_texture_format_required_features(&f)) |