aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/identityhub.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-11-28 11:05:19 -0500
committerGitHub <noreply@github.com>2019-11-28 11:05:19 -0500
commitb0012a62b2ac97bad2a12c048de830362e0ea4bc (patch)
tree0961191ed62b3bd819a58ef5f74e9173a0c9d550 /components/script/dom/identityhub.rs
parent5f1681ad25921e7bb779a9223445167124e44e14 (diff)
parentb26598d47094a24db3f8041c8e070229106e419d (diff)
downloadservo-b0012a62b2ac97bad2a12c048de830362e0ea4bc.tar.gz
servo-b0012a62b2ac97bad2a12c048de830362e0ea4bc.zip
Auto merge of #24883 - szeged:id_management, r=jdm
Add WebGPU identity management <!-- 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 <!-- 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.--> cc @jdm, @kvark, @zakorgy <!-- 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/identityhub.rs')
-rw-r--r--components/script/dom/identityhub.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/components/script/dom/identityhub.rs b/components/script/dom/identityhub.rs
new file mode 100644
index 00000000000..489eaacc78d
--- /dev/null
+++ b/components/script/dom/identityhub.rs
@@ -0,0 +1,47 @@
+/* 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 webgpu::wgpu::{AdapterId, Backend, DeviceId, IdentityManager, SurfaceId};
+
+#[derive(Debug)]
+pub struct IdentityHub {
+ adapters: IdentityManager<AdapterId>,
+ devices: IdentityManager<DeviceId>,
+}
+
+impl IdentityHub {
+ fn new(backend: Backend) -> Self {
+ IdentityHub {
+ adapters: IdentityManager::new(backend),
+ devices: IdentityManager::new(backend),
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct Identities {
+ surface: IdentityManager<SurfaceId>,
+ hub: IdentityHub,
+}
+
+impl Identities {
+ pub fn new() -> Self {
+ let hub = if cfg!(any(target_os = "linux", target_os = "windows")) {
+ IdentityHub::new(Backend::Vulkan)
+ } else if cfg!(any(target_os = "ios", target_os = "macos")) {
+ IdentityHub::new(Backend::Metal)
+ } else {
+ IdentityHub::new(Backend::Empty)
+ };
+
+ Identities {
+ surface: IdentityManager::new(Backend::Empty),
+ hub,
+ }
+ }
+
+ pub fn create_adapter_id(&mut self) -> AdapterId {
+ self.hub.adapters.alloc()
+ }
+}