tor-browser

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

Adapter.h (3769B)


      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_Adapter_H_
      7 #define GPU_Adapter_H_
      8 
      9 #include <memory>
     10 
     11 #include "ObjectModel.h"
     12 #include "mozilla/AlreadyAddRefed.h"
     13 #include "mozilla/IntegerPrintfMacros.h"
     14 #include "mozilla/webgpu/WebGPUTypes.h"
     15 #include "nsPrintfCString.h"
     16 #include "nsString.h"
     17 
     18 namespace mozilla {
     19 class ErrorResult;
     20 namespace dom {
     21 class Promise;
     22 struct GPUDeviceDescriptor;
     23 struct GPUExtensions;
     24 struct GPUFeatures;
     25 enum class GPUFeatureName : uint8_t;
     26 enum class WgpuBackend : uint8_t;
     27 enum class WgpuDeviceType : uint8_t;
     28 template <typename T>
     29 class Sequence;
     30 }  // namespace dom
     31 
     32 namespace webgpu {
     33 class Adapter;
     34 class Device;
     35 class Instance;
     36 class SupportedFeatures;
     37 class SupportedLimits;
     38 class WebGPUChild;
     39 namespace ffi {
     40 struct WGPUAdapterInformation;
     41 }  // namespace ffi
     42 
     43 class AdapterInfo final : public nsWrapperCache, public ChildOf<Adapter> {
     44 public:
     45  GPU_DECL_CYCLE_COLLECTION(AdapterInfo)
     46  GPU_DECL_JS_WRAP(AdapterInfo)
     47 
     48 protected:
     49  const std::shared_ptr<ffi::WGPUAdapterInformation> mAboutSupportInfo;
     50  virtual ~AdapterInfo() = default;
     51 
     52 public:
     53  explicit AdapterInfo(
     54      Adapter* const aParent,
     55      const std::shared_ptr<ffi::WGPUAdapterInformation>& aAboutSupportInfo)
     56      : ChildOf(aParent), mAboutSupportInfo(aAboutSupportInfo) {}
     57 
     58  /// Changing implementation in a way that increases fingerprinting
     59  /// surface? Please create a bug in [Core::Privacy: Anti
     60  /// Tracking](https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=Privacy%3A%20Anti-Tracking)
     61  void GetVendor(nsString& s) const { s = nsString(); }
     62  void GetArchitecture(nsString& s) const { s = nsString(); }
     63  void GetDevice(nsString& s) const { s = nsString(); }
     64  void GetDescription(nsString& s) const { s = nsString(); }
     65  uint32_t SubgroupMinSize() const;
     66  uint32_t SubgroupMaxSize() const;
     67  bool IsFallbackAdapter() const;
     68 
     69  // Non-standard field getters; see also TODO BUGZILLA LINK
     70  void GetWgpuName(nsString&) const;
     71  uint32_t WgpuVendor() const;
     72  uint32_t WgpuDevice() const;
     73  void GetWgpuDeviceType(nsString&) const;
     74  void GetWgpuDriver(nsString&) const;
     75  void GetWgpuDriverInfo(nsString&) const;
     76  void GetWgpuBackend(nsString&) const;
     77 };
     78 
     79 inline auto ToHexCString(const uint64_t v) {
     80  return nsPrintfCString("0x%" PRIx64, v);
     81 }
     82 
     83 class Adapter final : public nsWrapperCache,
     84                      public ObjectBase,
     85                      public ChildOf<Instance> {
     86 public:
     87  GPU_DECL_CYCLE_COLLECTION(Adapter)
     88  GPU_DECL_JS_WRAP(Adapter)
     89 
     90 private:
     91  virtual ~Adapter();
     92 
     93  // Cant have them as `const` right now, since we wouldn't be able
     94  // to unlink them in CC unlink.
     95  RefPtr<SupportedFeatures> mFeatures;
     96  RefPtr<SupportedLimits> mLimits;
     97  RefPtr<AdapterInfo> mInfo;
     98  const std::shared_ptr<ffi::WGPUAdapterInformation> mInfoInner;
     99 
    100 public:
    101  Adapter(Instance* const aParent, WebGPUChild* const aChild,
    102          const std::shared_ptr<ffi::WGPUAdapterInformation>& aInfo);
    103  const RefPtr<SupportedFeatures>& Features() const;
    104  const RefPtr<SupportedLimits>& Limits() const;
    105  const RefPtr<AdapterInfo>& Info() const;
    106  bool SupportSharedTextureInSwapChain() const;
    107  uint64_t MissingFeatures() const;
    108 
    109  nsCString LabelOrId() const {
    110    nsCString ret = this->CLabel();
    111    if (ret.IsEmpty()) {
    112      ret = ToHexCString(GetId());
    113    }
    114    return ret;
    115  }
    116 
    117  already_AddRefed<dom::Promise> RequestDevice(
    118      const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv);
    119 };
    120 
    121 }  // namespace webgpu
    122 }  // namespace mozilla
    123 
    124 #endif  // GPU_Adapter_H_