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/UniquePtr.h"
10 #include "mozilla/dom/BindingDeclarations.h"
11 #include "mozilla/gfx/Point.h"
12 #include "mozilla/layers/LayersTypes.h"
15 class nsICanvasRenderingContextInternal
;
16 class nsIGlobalObject
;
25 class EncodeCompleteCallback
;
27 enum class CanvasContextType
: uint8_t {
38 * Povides common RenderingContext functionality used by both OffscreenCanvas
39 * and HTMLCanvasElement.
41 class CanvasRenderingContextHelper
{
43 CanvasRenderingContextHelper();
45 virtual bool GetOpaqueAttr() = 0;
48 virtual nsresult
UpdateContext(JSContext
* aCx
,
49 JS::Handle
<JS::Value
> aNewContextOptions
,
50 ErrorResult
& aRvForDictionaryInit
);
52 virtual nsresult
ParseParams(JSContext
* aCx
, const nsAString
& aType
,
53 const JS::Value
& aEncoderOptions
,
55 bool* const outCustomParseOptions
);
57 void ToBlob(JSContext
* aCx
, nsIGlobalObject
* global
, BlobCallback
& aCallback
,
58 const nsAString
& aType
, JS::Handle
<JS::Value
> aParams
,
59 bool aUsePlaceholder
, ErrorResult
& aRv
);
61 void ToBlob(JSContext
* aCx
, EncodeCompleteCallback
* aCallback
,
62 const nsAString
& aType
, JS::Handle
<JS::Value
> aParams
,
63 bool aUsePlaceholder
, ErrorResult
& aRv
);
65 void ToBlob(EncodeCompleteCallback
* aCallback
, nsAString
& aType
,
66 const nsAString
& aEncodeOptions
, bool aUsingCustomOptions
,
67 bool aUsePlaceholder
, ErrorResult
& aRv
);
69 virtual UniquePtr
<uint8_t[]> GetImageBuffer(int32_t* aOutFormat
,
70 gfx::IntSize
* aOutImageSize
);
72 already_AddRefed
<nsISupports
> GetOrCreateContext(
73 JSContext
* aCx
, const nsAString
& aContextId
,
74 JS::Handle
<JS::Value
> aContextOptions
, ErrorResult
& aRv
);
76 already_AddRefed
<nsISupports
> GetOrCreateContext(
77 JSContext
* aCx
, CanvasContextType aContextType
,
78 JS::Handle
<JS::Value
> aContextOptions
, ErrorResult
& aRv
);
80 virtual already_AddRefed
<nsICanvasRenderingContextInternal
> CreateContext(
81 CanvasContextType aContextType
);
83 already_AddRefed
<nsICanvasRenderingContextInternal
> CreateContextHelper(
84 CanvasContextType aContextType
, layers::LayersBackend aCompositorBackend
);
86 virtual nsIntSize
GetWidthHeight() = 0;
88 CanvasContextType mCurrentContextType
;
89 nsCOMPtr
<nsICanvasRenderingContextInternal
> mCurrentContext
;
93 namespace CanvasUtils
{
94 bool GetCanvasContextType(const nsAString
&, dom::CanvasContextType
* const);
95 } // namespace CanvasUtils
96 } // namespace mozilla
98 #endif // MOZILLA_DOM_CANVASRENDERINGCONTEXTHELPER_H_