CommandBuffer.cpp (1409B)
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/. */ 5 6 #include "CommandBuffer.h" 7 8 #include "CommandEncoder.h" 9 #include "Device.h" 10 #include "ExternalTexture.h" 11 #include "ipc/WebGPUChild.h" 12 #include "mozilla/dom/WebGPUBinding.h" 13 #include "mozilla/webgpu/CanvasContext.h" 14 #include "nsTArray.h" 15 16 namespace mozilla::webgpu { 17 18 GPU_IMPL_CYCLE_COLLECTION(CommandBuffer, mParent, mExternalTextures) 19 GPU_IMPL_JS_WRAP(CommandBuffer) 20 21 CommandBuffer::CommandBuffer( 22 Device* const aParent, RawId aId, 23 nsTArray<WeakPtr<CanvasContext>>&& aPresentationContexts, 24 nsTArray<RefPtr<ExternalTexture>>&& aExternalTextures) 25 : ObjectBase(aParent->GetChild(), aId, 26 ffi::wgpu_client_drop_command_buffer), 27 ChildOf(aParent), 28 mPresentationContexts(std::move(aPresentationContexts)), 29 mExternalTextures(std::move(aExternalTextures)) { 30 MOZ_RELEASE_ASSERT(aId); 31 } 32 33 CommandBuffer::~CommandBuffer() = default; 34 35 RawId CommandBuffer::Commit() { 36 for (const auto& presentationContext : mPresentationContexts) { 37 if (presentationContext) { 38 presentationContext->MaybeQueueSwapChainPresent(); 39 } 40 } 41 return GetId(); 42 } 43 44 } // namespace mozilla::webgpu