tor-browser

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

CanvasRenderingContextHelper.h (3539B)


      1 /* -*- Mode: C++; tab-width: 2; 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 file,
      4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_
      7 #define MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_
      8 
      9 #include "mozilla/UniquePtr.h"
     10 #include "mozilla/dom/BindingDeclarations.h"
     11 #include "mozilla/gfx/Point.h"
     12 #include "mozilla/layers/LayersTypes.h"
     13 #include "nsSize.h"
     14 
     15 class nsICanvasRenderingContextInternal;
     16 class nsICookieJarSettings;
     17 class nsIGlobalObject;
     18 
     19 namespace mozilla {
     20 
     21 class ErrorResult;
     22 
     23 namespace layers {
     24 class SurfaceDescriptor;
     25 }  // namespace layers
     26 
     27 namespace CanvasUtils {
     28 enum class ImageExtraction;
     29 }
     30 namespace dom {
     31 
     32 class BlobCallback;
     33 class EncodeCompleteCallback;
     34 
     35 enum class CanvasContextType : uint8_t {
     36  NoContext,
     37  Canvas2D,
     38  OffscreenCanvas2D,
     39  WebGL1,
     40  WebGL2,
     41  WebGPU,
     42  ImageBitmap
     43 };
     44 
     45 /**
     46 * Povides common RenderingContext functionality used by both OffscreenCanvas
     47 * and HTMLCanvasElement.
     48 */
     49 class CanvasRenderingContextHelper {
     50 public:
     51  CanvasRenderingContextHelper();
     52 
     53  virtual bool GetOpaqueAttr() = 0;
     54 
     55 protected:
     56  virtual nsresult UpdateContext(JSContext* aCx,
     57                                 JS::Handle<JS::Value> aNewContextOptions,
     58                                 ErrorResult& aRvForDictionaryInit);
     59 
     60  virtual nsresult ParseParams(JSContext* aCx, const nsAString& aType,
     61                               const JS::Value& aEncoderOptions,
     62                               nsAString& outParams,
     63                               bool* const outCustomParseOptions);
     64 
     65  void ToBlob(JSContext* aCx, EncodeCompleteCallback* aCallback,
     66              const nsAString& aType, JS::Handle<JS::Value> aParams,
     67              CanvasUtils::ImageExtraction aExtractionBehavior,
     68              ErrorResult& aRv);
     69 
     70  void ToBlob(EncodeCompleteCallback* aCallback, nsAString& aType,
     71              const nsAString& aEncodeOptions, bool aUsingCustomOptions,
     72              CanvasUtils::ImageExtraction aExtractionBehavior,
     73              ErrorResult& aRv);
     74 
     75  virtual UniquePtr<uint8_t[]> GetImageBuffer(
     76      CanvasUtils::ImageExtraction aExtractionBehavior, int32_t* aOutFormat,
     77      gfx::IntSize* aOutImageSize);
     78 
     79  nsICookieJarSettings* GetCookieJarSettings() const;
     80 
     81  already_AddRefed<nsISupports> GetOrCreateContext(
     82      JSContext* aCx, const nsAString& aContextId,
     83      JS::Handle<JS::Value> aContextOptions, ErrorResult& aRv);
     84 
     85  already_AddRefed<nsISupports> GetOrCreateContext(
     86      JSContext* aCx, CanvasContextType aContextType,
     87      JS::Handle<JS::Value> aContextOptions, ErrorResult& aRv);
     88 
     89  virtual already_AddRefed<nsICanvasRenderingContextInternal> CreateContext(
     90      CanvasContextType aContextType);
     91 
     92  already_AddRefed<nsICanvasRenderingContextInternal> CreateContextHelper(
     93      CanvasContextType aContextType, layers::LayersBackend aCompositorBackend);
     94 
     95  virtual CSSIntSize GetWidthHeight() = 0;
     96 
     97  CanvasContextType mCurrentContextType;
     98  nsCOMPtr<nsICanvasRenderingContextInternal> mCurrentContext;
     99 };
    100 
    101 bool ValidSurfaceDescriptorForRemoteCanvas2d(
    102    const layers::SurfaceDescriptor& aSd,
    103    Maybe<layers::SurfaceDescriptor>* aResultSd = nullptr);
    104 
    105 }  // namespace dom
    106 namespace CanvasUtils {
    107 bool GetCanvasContextType(const nsAString&, dom::CanvasContextType* const);
    108 }  // namespace CanvasUtils
    109 }  // namespace mozilla
    110 
    111 #endif  // MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_