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/. */
6 #ifndef MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_
7 #define MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_
9 #include "mozilla/dom/BindingDeclarations.h"
10 #include "mozilla/layers/LayersTypes.h"
13 class nsICanvasRenderingContextInternal
;
14 class nsIGlobalObject
;
23 class EncodeCompleteCallback
;
25 enum class CanvasContextType
: uint8_t {
36 * Povides common RenderingContext functionality used by both OffscreenCanvas
37 * and HTMLCanvasElement.
39 class CanvasRenderingContextHelper
{
41 CanvasRenderingContextHelper();
43 virtual bool GetOpaqueAttr() = 0;
46 virtual nsresult
UpdateContext(JSContext
* aCx
,
47 JS::Handle
<JS::Value
> aNewContextOptions
,
48 ErrorResult
& aRvForDictionaryInit
);
50 virtual nsresult
ParseParams(JSContext
* aCx
, const nsAString
& aType
,
51 const JS::Value
& aEncoderOptions
,
53 bool* const outCustomParseOptions
);
55 void ToBlob(JSContext
* aCx
, nsIGlobalObject
* global
, BlobCallback
& aCallback
,
56 const nsAString
& aType
, JS::Handle
<JS::Value
> aParams
,
57 bool aUsePlaceholder
, ErrorResult
& aRv
);
59 void ToBlob(JSContext
* aCx
, EncodeCompleteCallback
* aCallback
,
60 const nsAString
& aType
, JS::Handle
<JS::Value
> aParams
,
61 bool aUsePlaceholder
, ErrorResult
& aRv
);
63 void ToBlob(EncodeCompleteCallback
* aCallback
, nsAString
& aType
,
64 const nsAString
& aEncodeOptions
, bool aUsingCustomOptions
,
65 bool aUsePlaceholder
, ErrorResult
& aRv
);
67 already_AddRefed
<nsISupports
> GetOrCreateContext(
68 JSContext
* aCx
, const nsAString
& aContextId
,
69 JS::Handle
<JS::Value
> aContextOptions
, ErrorResult
& aRv
);
71 already_AddRefed
<nsISupports
> GetOrCreateContext(
72 JSContext
* aCx
, CanvasContextType aContextType
,
73 JS::Handle
<JS::Value
> aContextOptions
, ErrorResult
& aRv
);
75 virtual already_AddRefed
<nsICanvasRenderingContextInternal
> CreateContext(
76 CanvasContextType aContextType
);
78 already_AddRefed
<nsICanvasRenderingContextInternal
> CreateContextHelper(
79 CanvasContextType aContextType
, layers::LayersBackend aCompositorBackend
);
81 virtual nsIntSize
GetWidthHeight() = 0;
83 CanvasContextType mCurrentContextType
;
84 nsCOMPtr
<nsICanvasRenderingContextInternal
> mCurrentContext
;
88 namespace CanvasUtils
{
89 bool GetCanvasContextType(const nsAString
&, dom::CanvasContextType
* const);
90 } // namespace CanvasUtils
91 } // namespace mozilla
93 #endif // MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_