no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / webgpu / CommandBuffer.cpp
blobff9bbd8d5dfe329e0de35a1c7072a7b168353e44
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 "CommandBuffer.h"
8 #include "CommandEncoder.h"
9 #include "ipc/WebGPUChild.h"
11 #include "mozilla/webgpu/CanvasContext.h"
12 #include "Device.h"
14 namespace mozilla::webgpu {
16 GPU_IMPL_CYCLE_COLLECTION(CommandBuffer, mParent)
17 GPU_IMPL_JS_WRAP(CommandBuffer)
19 CommandBuffer::CommandBuffer(Device* const aParent, RawId aId,
20 nsTArray<WeakPtr<CanvasContext>>&& aTargetContexts,
21 RefPtr<CommandEncoder>&& aEncoder)
22 : ChildOf(aParent), mId(aId), mTargetContexts(std::move(aTargetContexts)) {
23 mEncoder = std::move(aEncoder);
24 MOZ_RELEASE_ASSERT(aId);
27 CommandBuffer::~CommandBuffer() {}
29 void CommandBuffer::Cleanup() { mEncoder = nullptr; }
31 Maybe<RawId> CommandBuffer::Commit() {
32 if (!mValid) {
33 return Nothing();
35 mValid = false;
36 for (const auto& targetContext : mTargetContexts) {
37 if (targetContext) {
38 targetContext->MaybeQueueSwapChainPresent();
41 return Some(mId);
44 } // namespace mozilla::webgpu