Bug 1909121 - [wpt-sync] Update web-platform-tests to 5af3e9c2a2aba76ade00f0dbc3486e5...
[gecko.git] / dom / webgpu / TextureView.cpp
blob4964de4b7f72901e1e3be9567bd401cd7363c0bb
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 "TextureView.h"
8 #include "Device.h"
9 #include "mozilla/dom/WebGPUBinding.h"
10 #include "mozilla/webgpu/CanvasContext.h"
11 #include "ipc/WebGPUChild.h"
13 namespace mozilla::webgpu {
15 GPU_IMPL_CYCLE_COLLECTION(TextureView, mParent)
16 GPU_IMPL_JS_WRAP(TextureView)
18 TextureView::TextureView(Texture* const aParent, RawId aId)
19 : ChildOf(aParent), mId(aId) {
20 MOZ_RELEASE_ASSERT(aId);
23 TextureView::~TextureView() { Cleanup(); }
25 CanvasContext* TextureView::GetTargetContext() const {
26 return mParent->mTargetContext;
27 } // namespace webgpu
29 void TextureView::Cleanup() {
30 if (!mValid || !mParent || !mParent->GetDevice()) {
31 return;
33 mValid = false;
35 auto bridge = mParent->GetDevice()->GetBridge();
36 if (!bridge) {
37 return;
40 if (bridge->CanSend()) {
41 bridge->SendTextureViewDrop(mId);
44 wgpu_client_free_texture_view_id(bridge->GetClient(), mId);
47 } // namespace mozilla::webgpu