/src/mozilla-central/dom/canvas/nsICanvasRenderingContextInternal.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 40; 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 nsICanvasRenderingContextInternal_h___ |
7 | | #define nsICanvasRenderingContextInternal_h___ |
8 | | |
9 | | #include "mozilla/gfx/2D.h" |
10 | | #include "nsISupports.h" |
11 | | #include "nsIInputStream.h" |
12 | | #include "nsIDocShell.h" |
13 | | #include "nsRefreshDriver.h" |
14 | | #include "mozilla/dom/HTMLCanvasElement.h" |
15 | | #include "mozilla/dom/OffscreenCanvas.h" |
16 | | #include "mozilla/RefPtr.h" |
17 | | #include "mozilla/UniquePtr.h" |
18 | | #include "mozilla/NotNull.h" |
19 | | |
20 | | #define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \ |
21 | | { 0xb84f2fed, 0x9d4b, 0x430b, \ |
22 | | { 0xbd, 0xfb, 0x85, 0x57, 0x8a, 0xc2, 0xb4, 0x4b } } |
23 | | |
24 | | class nsDisplayListBuilder; |
25 | | |
26 | | namespace mozilla { |
27 | | namespace layers { |
28 | | class CanvasLayer; |
29 | | class CanvasRenderer; |
30 | | class Layer; |
31 | | class LayerManager; |
32 | | class WebRenderCanvasData; |
33 | | } // namespace layers |
34 | | namespace gfx { |
35 | | class SourceSurface; |
36 | | } // namespace gfx |
37 | | } // namespace mozilla |
38 | | |
39 | | class nsICanvasRenderingContextInternal : |
40 | | public nsISupports, |
41 | | public nsAPostRefreshObserver |
42 | | { |
43 | | public: |
44 | | typedef mozilla::layers::CanvasLayer CanvasLayer; |
45 | | typedef mozilla::layers::CanvasRenderer CanvasRenderer; |
46 | | typedef mozilla::layers::Layer Layer; |
47 | | typedef mozilla::layers::LayerManager LayerManager; |
48 | | typedef mozilla::layers::WebRenderCanvasData WebRenderCanvasData; |
49 | | |
50 | | NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) |
51 | | |
52 | | void SetCanvasElement(mozilla::dom::HTMLCanvasElement* parentCanvas) |
53 | 0 | { |
54 | 0 | RemovePostRefreshObserver(); |
55 | 0 | mCanvasElement = parentCanvas; |
56 | 0 | AddPostRefreshObserverIfNecessary(); |
57 | 0 | } |
58 | | |
59 | 0 | virtual nsIPresShell *GetPresShell() { |
60 | 0 | if (mCanvasElement) { |
61 | 0 | return mCanvasElement->OwnerDoc()->GetShell(); |
62 | 0 | } |
63 | 0 | return nullptr; |
64 | 0 | } |
65 | | |
66 | | void RemovePostRefreshObserver() |
67 | 0 | { |
68 | 0 | if (mRefreshDriver) { |
69 | 0 | mRefreshDriver->RemovePostRefreshObserver(this); |
70 | 0 | mRefreshDriver = nullptr; |
71 | 0 | } |
72 | 0 | } |
73 | | |
74 | | void AddPostRefreshObserverIfNecessary() |
75 | 0 | { |
76 | 0 | if (!GetPresShell() || |
77 | 0 | !GetPresShell()->GetPresContext() || |
78 | 0 | !GetPresShell()->GetPresContext()->RefreshDriver()) { |
79 | 0 | return; |
80 | 0 | } |
81 | 0 | mRefreshDriver = GetPresShell()->GetPresContext()->RefreshDriver(); |
82 | 0 | mRefreshDriver->AddPostRefreshObserver(this); |
83 | 0 | } |
84 | | |
85 | | mozilla::dom::HTMLCanvasElement* GetParentObject() const |
86 | 0 | { |
87 | 0 | return mCanvasElement; |
88 | 0 | } |
89 | | |
90 | | void SetOffscreenCanvas(mozilla::dom::OffscreenCanvas* aOffscreenCanvas) |
91 | 0 | { |
92 | 0 | mOffscreenCanvas = aOffscreenCanvas; |
93 | 0 | } |
94 | | |
95 | | // Dimensions of the canvas, in pixels. |
96 | | virtual int32_t GetWidth() = 0; |
97 | | virtual int32_t GetHeight() = 0; |
98 | | |
99 | | // Sets the dimensions of the canvas, in pixels. Called |
100 | | // whenever the size of the element changes. |
101 | | NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0; |
102 | | |
103 | | // Initializes with an nsIDocShell and DrawTarget. The size is taken from the |
104 | | // DrawTarget. |
105 | | NS_IMETHOD InitializeWithDrawTarget(nsIDocShell *aDocShell, |
106 | | mozilla::NotNull<mozilla::gfx::DrawTarget*> aTarget) = 0; |
107 | | |
108 | | // Creates an image buffer. Returns null on failure. |
109 | | virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* format) = 0; |
110 | | |
111 | | // Gives you a stream containing the image represented by this context. |
112 | | // The format is given in mimeTime, for example "image/png". |
113 | | // |
114 | | // If the image format does not support transparency or includeTransparency |
115 | | // is false, alpha will be discarded and the result will be the image |
116 | | // composited on black. |
117 | | NS_IMETHOD GetInputStream(const char *mimeType, |
118 | | const char16_t *encoderOptions, |
119 | | nsIInputStream **stream) = 0; |
120 | | |
121 | | // This gets an Azure SourceSurface for the canvas, this will be a snapshot |
122 | | // of the canvas at the time it was called. |
123 | | // If premultAlpha is provided, then it assumed the callee can handle |
124 | | // un-premultiplied surfaces, and *premultAlpha will be set to false |
125 | | // if one is returned. |
126 | | virtual already_AddRefed<mozilla::gfx::SourceSurface> |
127 | | GetSurfaceSnapshot(gfxAlphaType* out_alphaType = nullptr) = 0; |
128 | | |
129 | | // If this is called with true, the backing store of the canvas should |
130 | | // be created as opaque; all compositing operators should assume the |
131 | | // dst alpha is always 1.0. If this is never called, the context's |
132 | | // opaqueness is determined by the context attributes that it's initialized |
133 | | // with. |
134 | | virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) = 0; |
135 | | |
136 | | // Returns whether the context is opaque. This value can be based both on |
137 | | // the value of the moz-opaque attribute and on the context's initialization |
138 | | // attributes. |
139 | | virtual bool GetIsOpaque() = 0; |
140 | | |
141 | | // Invalidate this context and release any held resources, in preperation |
142 | | // for possibly reinitializing with SetDimensions/InitializeWithSurface. |
143 | | NS_IMETHOD Reset() = 0; |
144 | | |
145 | | // Return the CanvasLayer for this context, creating |
146 | | // one for the given layer manager if not available. |
147 | | virtual already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* builder, |
148 | | Layer *oldLayer, |
149 | | LayerManager *manager) = 0; |
150 | | virtual bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder, |
151 | 0 | WebRenderCanvasData* aCanvasData) { return false; } |
152 | | virtual bool InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder, |
153 | 0 | CanvasRenderer* aRenderer) { return true; } |
154 | | |
155 | | // Return true if the canvas should be forced to be "inactive" to ensure |
156 | | // it can be drawn to the screen even if it's too large to be blitted by |
157 | | // an accelerated CanvasLayer. |
158 | 0 | virtual bool ShouldForceInactiveLayer(LayerManager *manager) { return false; } |
159 | | |
160 | | virtual void MarkContextClean() = 0; |
161 | | |
162 | | // Called when a frame is captured. |
163 | | virtual void MarkContextCleanForFrameCapture() = 0; |
164 | | |
165 | | // Whether the context is clean or has been invalidated since the last frame |
166 | | // was captured. |
167 | | virtual bool IsContextCleanForFrameCapture() = 0; |
168 | | |
169 | | // Redraw the dirty rectangle of this canvas. |
170 | | NS_IMETHOD Redraw(const gfxRect &dirty) = 0; |
171 | | |
172 | | NS_IMETHOD SetContextOptions(JSContext* cx, JS::Handle<JS::Value> options, |
173 | | mozilla::ErrorResult& aRvForDictionaryInit) |
174 | 0 | { |
175 | 0 | return NS_OK; |
176 | 0 | } |
177 | | |
178 | | // return true and fills in the bounding rect if elementis a child and has a hit region. |
179 | 0 | virtual bool GetHitRegionRect(mozilla::dom::Element* element, nsRect& rect) { return false; } |
180 | | |
181 | | // Given a point, return hit region ID if it exists or an empty string if it doesn't |
182 | 0 | virtual nsString GetHitRegion(const mozilla::gfx::Point& point) { return nsString(); } |
183 | | |
184 | 0 | virtual void OnVisibilityChange() {} |
185 | | |
186 | 0 | virtual void OnMemoryPressure() {} |
187 | | |
188 | | // |
189 | | // shmem support |
190 | | // |
191 | | |
192 | | // If this context can be set to use Mozilla's Shmem segments as its backing |
193 | | // store, this will set it to that state. Note that if you have drawn |
194 | | // anything into this canvas before changing the shmem state, it will be |
195 | | // lost. |
196 | | NS_IMETHOD SetIsIPC(bool isIPC) = 0; |
197 | | |
198 | | protected: |
199 | | RefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement; |
200 | | RefPtr<mozilla::dom::OffscreenCanvas> mOffscreenCanvas; |
201 | | RefPtr<nsRefreshDriver> mRefreshDriver; |
202 | | }; |
203 | | |
204 | | NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal, |
205 | | NS_ICANVASRENDERINGCONTEXTINTERNAL_IID) |
206 | | |
207 | | #endif /* nsICanvasRenderingContextInternal_h___ */ |