mirror of
https://github.com/servo/servo.git
synced 2025-06-19 14:48:59 +01:00
Remove code duplication from IdentityHub
Outsourced the backend selection to a function.
This commit is contained in:
parent
8e0d037ee8
commit
0842e53d8d
1 changed files with 18 additions and 44 deletions
|
@ -82,6 +82,20 @@ impl Identities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn select(&mut self, backend: Backend) -> &mut IdentityHub {
|
||||||
|
match backend {
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
|
Backend::Vulkan => &mut self.vk_hub,
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
Backend::Dx12 => &mut self.dx12_hub,
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
Backend::Dx11 => &mut self.dx11_hub,
|
||||||
|
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
||||||
|
Backend::Metal => &mut self.metal_hub,
|
||||||
|
_ => &mut self.dummy_hub,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn hubs(&mut self) -> Vec<&mut IdentityHub> {
|
fn hubs(&mut self) -> Vec<&mut IdentityHub> {
|
||||||
vec![
|
vec![
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
|
@ -97,17 +111,7 @@ impl Identities {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_device_id(&mut self, backend: Backend) -> DeviceId {
|
pub fn create_device_id(&mut self, backend: Backend) -> DeviceId {
|
||||||
match backend {
|
self.select(backend).create_device_id()
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
||||||
Backend::Vulkan => self.vk_hub.create_device_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx12 => self.dx12_hub.create_device_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx11 => self.dx11_hub.create_device_id(),
|
|
||||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
|
||||||
Backend::Metal => self.metal_hub.create_device_id(),
|
|
||||||
_ => self.dummy_hub.create_device_id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_adapter_ids(&mut self) -> SmallVec<[AdapterId; 4]> {
|
pub fn create_adapter_ids(&mut self) -> SmallVec<[AdapterId; 4]> {
|
||||||
|
@ -119,44 +123,14 @@ impl Identities {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_buffer_id(&mut self, backend: Backend) -> BufferId {
|
pub fn create_buffer_id(&mut self, backend: Backend) -> BufferId {
|
||||||
match backend {
|
self.select(backend).create_buffer_id()
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
||||||
Backend::Vulkan => self.vk_hub.create_buffer_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx12 => self.dx12_hub.create_buffer_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx11 => self.dx11_hub.create_buffer_id(),
|
|
||||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
|
||||||
Backend::Metal => self.metal_hub.create_buffer_id(),
|
|
||||||
_ => self.dummy_hub.create_buffer_id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_bind_group_layout_id(&mut self, backend: Backend) -> BindGroupLayoutId {
|
pub fn create_bind_group_layout_id(&mut self, backend: Backend) -> BindGroupLayoutId {
|
||||||
match backend {
|
self.select(backend).create_bind_group_layout_id()
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
||||||
Backend::Vulkan => self.vk_hub.create_bind_group_layout_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx12 => self.dx12_hub.create_bind_group_layout_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx11 => self.dx11_hub.create_bind_group_layout_id(),
|
|
||||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
|
||||||
Backend::Metal => self.metal_hub.create_bind_group_layout_id(),
|
|
||||||
_ => self.dummy_hub.create_bind_group_layout_id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_pipeline_layout_id(&mut self, backend: Backend) -> PipelineLayoutId {
|
pub fn create_pipeline_layout_id(&mut self, backend: Backend) -> PipelineLayoutId {
|
||||||
match backend {
|
self.select(backend).create_pipeline_layout_id()
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
||||||
Backend::Vulkan => self.vk_hub.create_pipeline_layout_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx12 => self.dx12_hub.create_pipeline_layout_id(),
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
Backend::Dx11 => self.dx11_hub.create_pipeline_layout_id(),
|
|
||||||
#[cfg(any(target_os = "ios", target_os = "macos"))]
|
|
||||||
Backend::Metal => self.metal_hub.create_pipeline_layout_id(),
|
|
||||||
_ => self.dummy_hub.create_pipeline_layout_id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue