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"
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() {
36 for (const auto& targetContext
: mTargetContexts
) {
38 targetContext
->MaybeQueueSwapChainPresent();
44 } // namespace mozilla::webgpu