tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Texture.h (2124B)


      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 #ifndef GPU_Texture_H_
      7 #define GPU_Texture_H_
      8 
      9 #include <cstdint>
     10 
     11 #include "ObjectModel.h"
     12 #include "mozilla/WeakPtr.h"
     13 #include "mozilla/webgpu/WebGPUTypes.h"
     14 #include "mozilla/webgpu/ffi/wgpu.h"
     15 #include "nsWrapperCache.h"
     16 
     17 namespace mozilla {
     18 namespace dom {
     19 struct GPUTextureDescriptor;
     20 struct GPUTextureViewDescriptor;
     21 enum class GPUTextureDimension : uint8_t;
     22 enum class GPUTextureFormat : uint8_t;
     23 enum class GPUTextureUsageFlags : uint32_t;
     24 }  // namespace dom
     25 
     26 namespace webgpu {
     27 
     28 class CanvasContext;
     29 class Device;
     30 class TextureView;
     31 
     32 class Texture final : public nsWrapperCache,
     33                      public ObjectBase,
     34                      public ChildOf<Device> {
     35 public:
     36  GPU_DECL_CYCLE_COLLECTION(Texture)
     37  GPU_DECL_JS_WRAP(Texture)
     38 
     39  Texture(Device* const aParent, RawId aId,
     40          const dom::GPUTextureDescriptor& aDesc);
     41 
     42  const dom::GPUTextureFormat mFormat;
     43  const Maybe<uint8_t> mBytesPerBlock;
     44 
     45  WeakPtr<CanvasContext> mTargetContext;
     46 
     47 private:
     48  virtual ~Texture();
     49 
     50  const ffi::WGPUExtent3d mSize;
     51  const uint32_t mMipLevelCount;
     52  const uint32_t mSampleCount;
     53  const dom::GPUTextureDimension mDimension;
     54  const uint32_t mUsage;
     55 
     56 public:
     57  already_AddRefed<TextureView> CreateView(
     58      const dom::GPUTextureViewDescriptor& aDesc);
     59  void Destroy();
     60 
     61  uint32_t Width() const { return mSize.width; }
     62  uint32_t Height() const { return mSize.height; }
     63  uint32_t DepthOrArrayLayers() const { return mSize.depth_or_array_layers; }
     64  uint32_t MipLevelCount() const { return mMipLevelCount; }
     65  uint32_t SampleCount() const { return mSampleCount; }
     66  dom::GPUTextureDimension Dimension() const { return mDimension; }
     67  dom::GPUTextureFormat Format() const { return mFormat; }
     68  uint32_t Usage() const { return mUsage; }
     69 };
     70 
     71 }  // namespace webgpu
     72 }  // namespace mozilla
     73 
     74 #endif  // GPU_Texture_H_