Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / webgpu / ShaderModule.cpp
blobfce469a1743c679410e6b7f01508f0a5cee5f2cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/dom/WebGPUBinding.h"
7 #include "mozilla/dom/Promise.h"
8 #include "ShaderModule.h"
9 #include "CompilationInfo.h"
10 #include "ipc/WebGPUChild.h"
12 #include "Device.h"
14 namespace mozilla::webgpu {
16 GPU_IMPL_CYCLE_COLLECTION(ShaderModule, mParent, mCompilationInfo)
17 GPU_IMPL_JS_WRAP(ShaderModule)
19 ShaderModule::ShaderModule(Device* const aParent, RawId aId,
20 const RefPtr<dom::Promise>& aCompilationInfo)
21 : ChildOf(aParent), mId(aId), mCompilationInfo(aCompilationInfo) {
22 MOZ_RELEASE_ASSERT(aId);
25 ShaderModule::~ShaderModule() { Cleanup(); }
27 void ShaderModule::Cleanup() {
28 if (!mValid) {
29 return;
31 mValid = false;
33 auto bridge = mParent->GetBridge();
34 if (!bridge) {
35 return;
38 if (bridge->CanSend()) {
39 bridge->SendShaderModuleDrop(mId);
42 wgpu_client_free_shader_module_id(bridge->GetClient(), mId);
45 already_AddRefed<dom::Promise> ShaderModule::CompilationInfo(ErrorResult& aRv) {
46 return GetCompilationInfo(aRv);
49 already_AddRefed<dom::Promise> ShaderModule::GetCompilationInfo(
50 ErrorResult& aRv) {
51 RefPtr<dom::Promise> tmp = mCompilationInfo;
52 return tmp.forget();
55 } // namespace mozilla::webgpu