Bug 1700051: part 26) Correct typo in comment of `mozInlineSpellWordUtil::BuildSoftTe...
[gecko.git] / dom / canvas / ImageBitmapRenderingContext.h
blob26d6150d6d19ad3b858d443e12dd8df204420b7c
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef ImageBitmapRenderingContext_h
6 #define ImageBitmapRenderingContext_h
8 #include "mozilla/dom/ImageBitmap.h"
9 #include "mozilla/gfx/2D.h"
10 #include "mozilla/gfx/DataSurfaceHelpers.h"
11 #include "mozilla/gfx/Point.h"
12 #include "mozilla/layers/WebRenderUserData.h"
13 #include "imgIEncoder.h"
14 #include "ImageEncoder.h"
15 #include "nsICanvasRenderingContextInternal.h"
16 #include "nsWrapperCache.h"
18 namespace mozilla {
20 namespace gfx {
21 class DataSourceSurface;
22 class DrawTarget;
23 class SourceSurface;
24 } // namespace gfx
26 namespace layers {
27 class Image;
28 class ImageContainer;
29 } // namespace layers
31 namespace dom {
33 /**
34 * The purpose of ImageBitmapRenderingContext is to provide a faster and
35 * efficient way to display ImageBitmap. Simply call TransferFromImageBitmap()
36 * then we'll transfer the surface of ImageBitmap to this context and then to
37 * use it to display.
39 * See more details in spec: https://wiki.whatwg.org/wiki/OffscreenCanvas
41 class ImageBitmapRenderingContext final
42 : public nsICanvasRenderingContextInternal,
43 public nsWrapperCache {
44 virtual ~ImageBitmapRenderingContext();
46 public:
47 ImageBitmapRenderingContext();
49 virtual JSObject* WrapObject(JSContext* aCx,
50 JS::Handle<JSObject*> aGivenProto) override;
52 // nsISupports interface + CC
53 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
55 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageBitmapRenderingContext)
57 void TransferImageBitmap(ImageBitmap& aImageBitmap);
58 void TransferFromImageBitmap(ImageBitmap& aImageBitmap);
60 // nsICanvasRenderingContextInternal
61 virtual int32_t GetWidth() override { return mWidth; }
62 virtual int32_t GetHeight() override { return mHeight; }
64 NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
66 NS_IMETHOD InitializeWithDrawTarget(
67 nsIDocShell* aDocShell, NotNull<gfx::DrawTarget*> aTarget) override;
69 virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(
70 int32_t* aFormat) override;
71 NS_IMETHOD GetInputStream(const char* aMimeType,
72 const nsAString& aEncoderOptions,
73 nsIInputStream** aStream) override;
75 virtual already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
76 gfxAlphaType* aOutAlphaType) override;
78 virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override;
79 virtual bool GetIsOpaque() override;
80 NS_IMETHOD Reset() override;
81 virtual already_AddRefed<Layer> GetCanvasLayer(
82 nsDisplayListBuilder* aBuilder, Layer* aOldLayer,
83 LayerManager* aManager) override;
84 bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
85 WebRenderCanvasData* aCanvasData) override;
86 virtual void MarkContextClean() override;
88 NS_IMETHOD Redraw(const gfxRect& aDirty) override;
89 NS_IMETHOD SetIsIPC(bool aIsIPC) override;
91 virtual void DidRefresh() override;
93 virtual void MarkContextCleanForFrameCapture() override;
94 virtual bool IsContextCleanForFrameCapture() override;
96 protected:
97 already_AddRefed<gfx::DataSourceSurface> MatchWithIntrinsicSize();
98 already_AddRefed<layers::Image> ClipToIntrinsicSize();
99 int32_t mWidth;
100 int32_t mHeight;
102 RefPtr<layers::Image> mImage;
105 * Flag to avoid unnecessary surface copies to FrameCaptureListeners in the
106 * case when the canvas is not currently being drawn into and not rendered
107 * but canvas capturing is still ongoing.
109 bool mIsCapturedFrameInvalid;
112 } // namespace dom
113 } // namespace mozilla
115 #endif /* ImageBitmapRenderingContext_h */