summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/webgpu/worker_navigator_gpu.cc
blob: 8f5e7cbe15e14392cf0f564f4680b72fb971b7dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/webgpu/worker_navigator_gpu.h"

#include "third_party/blink/renderer/core/workers/worker_navigator.h"
#include "third_party/blink/renderer/modules/webgpu/gpu.h"

namespace blink {

// static
WorkerNavigatorGPU& WorkerNavigatorGPU::From(WorkerNavigator& navigator) {
  WorkerNavigatorGPU* supplement =
      Supplement<WorkerNavigator>::From<WorkerNavigatorGPU>(navigator);
  if (!supplement) {
    supplement = MakeGarbageCollected<WorkerNavigatorGPU>(navigator);
    ProvideTo(navigator, supplement);
  }
  return *supplement;
}

// static
GPU* WorkerNavigatorGPU::gpu(ScriptState* script_state,
                             WorkerNavigator& navigator) {
  return WorkerNavigatorGPU::From(navigator).gpu(script_state);
}

GPU* WorkerNavigatorGPU::gpu(ScriptState* script_state) {
  if (!gpu_) {
    ExecutionContext* context = ExecutionContext::From(script_state);
    DCHECK(context);

    gpu_ = GPU::Create(*context);
  }
  return gpu_;
}

void WorkerNavigatorGPU::Trace(blink::Visitor* visitor) {
  visitor->Trace(gpu_);
  Supplement<WorkerNavigator>::Trace(visitor);
}

WorkerNavigatorGPU::WorkerNavigatorGPU(WorkerNavigator& navigator)
    : Supplement<WorkerNavigator>(navigator) {}

const char WorkerNavigatorGPU::kSupplementName[] = "WorkerNavigatorGPU";

}  // namespace blink