Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / dom / webgpu / Texture.h
blobe31878f825efda51b26d37b75cfe93999c66d151
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 #ifndef GPU_Texture_H_
7 #define GPU_Texture_H_
9 #include <cstdint>
10 #include "mozilla/WeakPtr.h"
11 #include "nsWrapperCache.h"
12 #include "ObjectModel.h"
13 #include "mozilla/webgpu/WebGPUTypes.h"
14 #include "mozilla/webgpu/ffi/wgpu.h"
16 namespace mozilla {
17 namespace dom {
18 struct GPUTextureDescriptor;
19 struct GPUTextureViewDescriptor;
20 enum class GPUTextureDimension : uint8_t;
21 enum class GPUTextureFormat : uint8_t;
22 enum class GPUTextureUsageFlags : uint32_t;
23 } // namespace dom
25 namespace webgpu {
27 class CanvasContext;
28 class Device;
29 class TextureView;
31 class Texture final : public ObjectBase, public ChildOf<Device> {
32 public:
33 GPU_DECL_CYCLE_COLLECTION(Texture)
34 GPU_DECL_JS_WRAP(Texture)
36 Texture(Device* const aParent, RawId aId,
37 const dom::GPUTextureDescriptor& aDesc);
38 Device* GetParentDevice() { return mParent; }
39 const RawId mId;
40 const dom::GPUTextureFormat mFormat;
41 const Maybe<uint8_t> mBytesPerBlock;
43 WeakPtr<CanvasContext> mTargetContext;
45 private:
46 virtual ~Texture();
47 void Cleanup();
49 const ffi::WGPUExtent3d mSize;
50 const uint32_t mMipLevelCount;
51 const uint32_t mSampleCount;
52 const dom::GPUTextureDimension mDimension;
53 const uint32_t mUsage;
55 public:
56 already_AddRefed<TextureView> CreateView(
57 const dom::GPUTextureViewDescriptor& aDesc);
58 void Destroy();
60 uint32_t Width() const { return mSize.width; }
61 uint32_t Height() const { return mSize.height; }
62 uint32_t DepthOrArrayLayers() const { return mSize.depth_or_array_layers; }
63 uint32_t MipLevelCount() const { return mMipLevelCount; }
64 uint32_t SampleCount() const { return mSampleCount; }
65 dom::GPUTextureDimension Dimension() const { return mDimension; }
66 dom::GPUTextureFormat Format() const { return mFormat; }
67 uint32_t Usage() const { return mUsage; }
70 } // namespace webgpu
71 } // namespace mozilla
73 #endif // GPU_Texture_H_