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/. */
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"
18 struct GPUTextureDescriptor
;
19 struct GPUTextureViewDescriptor
;
20 enum class GPUTextureDimension
: uint8_t;
21 enum class GPUTextureFormat
: uint8_t;
22 enum class GPUTextureUsageFlags
: uint32_t;
31 class Texture final
: public ObjectBase
, public ChildOf
<Device
> {
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
; }
40 const dom::GPUTextureFormat mFormat
;
41 const Maybe
<uint8_t> mBytesPerBlock
;
43 WeakPtr
<CanvasContext
> mTargetContext
;
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
;
56 already_AddRefed
<TextureView
> CreateView(
57 const dom::GPUTextureViewDescriptor
& aDesc
);
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
; }
71 } // namespace mozilla
73 #endif // GPU_Texture_H_