/src/mozilla-central/gfx/2d/DrawTargetRecording.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_DRAWTARGETRECORDING_H_ |
8 | | #define MOZILLA_GFX_DRAWTARGETRECORDING_H_ |
9 | | |
10 | | #include "2D.h" |
11 | | #include "DrawEventRecorder.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace gfx { |
15 | | |
16 | | class DrawTargetRecording : public DrawTarget |
17 | | { |
18 | | public: |
19 | | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override) |
20 | | DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, IntSize aSize, bool aHasData = false); |
21 | | |
22 | | ~DrawTargetRecording(); |
23 | | |
24 | 0 | virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); } |
25 | 0 | virtual BackendType GetBackendType() const override { return BackendType::RECORDING; } |
26 | 0 | virtual bool IsRecording() const override { return true; } |
27 | | |
28 | | virtual already_AddRefed<SourceSurface> Snapshot() override; |
29 | | virtual already_AddRefed<SourceSurface> IntoLuminanceSource(LuminanceType aLuminanceType, float aOpacity) override; |
30 | | |
31 | | virtual void DetachAllSnapshots() override; |
32 | | |
33 | 0 | virtual IntSize GetSize() const override { return mSize; } |
34 | | |
35 | | /* Ensure that the DrawTarget backend has flushed all drawing operations to |
36 | | * this draw target. This must be called before using the backing surface of |
37 | | * this draw target outside of GFX 2D code. |
38 | | */ |
39 | 0 | virtual void Flush() override { mFinalDT->Flush(); } |
40 | | |
41 | | virtual void FlushItem(const IntRect &aBounds) override; |
42 | | |
43 | | /* |
44 | | * Draw a surface to the draw target. Possibly doing partial drawing or |
45 | | * applying scaling. No sampling happens outside the source. |
46 | | * |
47 | | * aSurface Source surface to draw |
48 | | * aDest Destination rectangle that this drawing operation should draw to |
49 | | * aSource Source rectangle in aSurface coordinates, this area of aSurface |
50 | | * will be stretched to the size of aDest. |
51 | | * aOptions General draw options that are applied to the operation |
52 | | * aSurfOptions DrawSurface options that are applied |
53 | | */ |
54 | | virtual void DrawSurface(SourceSurface *aSurface, |
55 | | const Rect &aDest, |
56 | | const Rect &aSource, |
57 | | const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), |
58 | | const DrawOptions &aOptions = DrawOptions()) override; |
59 | | |
60 | | virtual void DrawFilter(FilterNode *aNode, |
61 | | const Rect &aSourceRect, |
62 | | const Point &aDestPoint, |
63 | | const DrawOptions &aOptions = DrawOptions()) override; |
64 | | |
65 | | /* |
66 | | * Blend a surface to the draw target with a shadow. The shadow is drawn as a |
67 | | * gaussian blur using a specified sigma. The shadow is clipped to the size |
68 | | * of the input surface, so the input surface should contain a transparent |
69 | | * border the size of the approximate coverage of the blur (3 * aSigma). |
70 | | * NOTE: This function works in device space! |
71 | | * |
72 | | * aSurface Source surface to draw. |
73 | | * aDest Destination point that this drawing operation should draw to. |
74 | | * aColor Color of the drawn shadow |
75 | | * aOffset Offset of the shadow |
76 | | * aSigma Sigma used for the guassian filter kernel |
77 | | * aOperator Composition operator used |
78 | | */ |
79 | | virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, |
80 | | const Point &aDest, |
81 | | const Color &aColor, |
82 | | const Point &aOffset, |
83 | | Float aSigma, |
84 | | CompositionOp aOperator) override; |
85 | | |
86 | | /* |
87 | | * Clear a rectangle on the draw target to transparent black. This will |
88 | | * respect the clipping region and transform. |
89 | | * |
90 | | * aRect Rectangle to clear |
91 | | */ |
92 | | virtual void ClearRect(const Rect &aRect) override; |
93 | | |
94 | | /* |
95 | | * This is essentially a 'memcpy' between two surfaces. It moves a pixel |
96 | | * aligned area from the source surface unscaled directly onto the |
97 | | * drawtarget. This ignores both transform and clip. |
98 | | * |
99 | | * aSurface Surface to copy from |
100 | | * aSourceRect Source rectangle to be copied |
101 | | * aDest Destination point to copy the surface to |
102 | | */ |
103 | | virtual void CopySurface(SourceSurface *aSurface, |
104 | | const IntRect &aSourceRect, |
105 | | const IntPoint &aDestination) override; |
106 | | |
107 | | /* |
108 | | * Fill a rectangle on the DrawTarget with a certain source pattern. |
109 | | * |
110 | | * aRect Rectangle that forms the mask of this filling operation |
111 | | * aPattern Pattern that forms the source of this filling operation |
112 | | * aOptions Options that are applied to this operation |
113 | | */ |
114 | | virtual void FillRect(const Rect &aRect, |
115 | | const Pattern &aPattern, |
116 | | const DrawOptions &aOptions = DrawOptions()) override; |
117 | | |
118 | | /* |
119 | | * Stroke a rectangle on the DrawTarget with a certain source pattern. |
120 | | * |
121 | | * aRect Rectangle that forms the mask of this stroking operation |
122 | | * aPattern Pattern that forms the source of this stroking operation |
123 | | * aOptions Options that are applied to this operation |
124 | | */ |
125 | | virtual void StrokeRect(const Rect &aRect, |
126 | | const Pattern &aPattern, |
127 | | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
128 | | const DrawOptions &aOptions = DrawOptions()) override; |
129 | | |
130 | | /* |
131 | | * Stroke a line on the DrawTarget with a certain source pattern. |
132 | | * |
133 | | * aStart Starting point of the line |
134 | | * aEnd End point of the line |
135 | | * aPattern Pattern that forms the source of this stroking operation |
136 | | * aOptions Options that are applied to this operation |
137 | | */ |
138 | | virtual void StrokeLine(const Point &aStart, |
139 | | const Point &aEnd, |
140 | | const Pattern &aPattern, |
141 | | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
142 | | const DrawOptions &aOptions = DrawOptions()) override; |
143 | | |
144 | | /* |
145 | | * Stroke a path on the draw target with a certain source pattern. |
146 | | * |
147 | | * aPath Path that is to be stroked |
148 | | * aPattern Pattern that should be used for the stroke |
149 | | * aStrokeOptions Stroke options used for this operation |
150 | | * aOptions Draw options used for this operation |
151 | | */ |
152 | | virtual void Stroke(const Path *aPath, |
153 | | const Pattern &aPattern, |
154 | | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
155 | | const DrawOptions &aOptions = DrawOptions()) override; |
156 | | |
157 | | /* |
158 | | * Fill a path on the draw target with a certain source pattern. |
159 | | * |
160 | | * aPath Path that is to be filled |
161 | | * aPattern Pattern that should be used for the fill |
162 | | * aOptions Draw options used for this operation |
163 | | */ |
164 | | virtual void Fill(const Path *aPath, |
165 | | const Pattern &aPattern, |
166 | | const DrawOptions &aOptions = DrawOptions()) override; |
167 | | |
168 | | /* |
169 | | * Fill a series of clyphs on the draw target with a certain source pattern. |
170 | | */ |
171 | | virtual void FillGlyphs(ScaledFont *aFont, |
172 | | const GlyphBuffer &aBuffer, |
173 | | const Pattern &aPattern, |
174 | | const DrawOptions &aOptions = DrawOptions()) override; |
175 | | |
176 | | /* |
177 | | * This takes a source pattern and a mask, and composites the source pattern |
178 | | * onto the destination surface using the alpha channel of the mask pattern |
179 | | * as a mask for the operation. |
180 | | * |
181 | | * aSource Source pattern |
182 | | * aMask Mask pattern |
183 | | * aOptions Drawing options |
184 | | */ |
185 | | virtual void Mask(const Pattern &aSource, |
186 | | const Pattern &aMask, |
187 | | const DrawOptions &aOptions = DrawOptions()) override; |
188 | | |
189 | | virtual void MaskSurface(const Pattern &aSource, |
190 | | SourceSurface *aMask, |
191 | | Point aOffset, |
192 | | const DrawOptions &aOptions = DrawOptions()) override; |
193 | | |
194 | | /* |
195 | | * Push a clip to the DrawTarget. |
196 | | * |
197 | | * aPath The path to clip to |
198 | | */ |
199 | | virtual void PushClip(const Path *aPath) override; |
200 | | |
201 | | /* |
202 | | * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle |
203 | | * is specified in user space. |
204 | | * |
205 | | * aRect The rect to clip to |
206 | | */ |
207 | | virtual void PushClipRect(const Rect &aRect) override; |
208 | | |
209 | | /* Pop a clip from the DrawTarget. A pop without a corresponding push will |
210 | | * be ignored. |
211 | | */ |
212 | | virtual void PopClip() override; |
213 | | |
214 | | /** |
215 | | * Push a 'layer' to the DrawTarget, a layer is a temporary surface that all |
216 | | * drawing will be redirected to, this is used for example to support group |
217 | | * opacity or the masking of groups. Clips must be balanced within a layer, |
218 | | * i.e. between a matching PushLayer/PopLayer pair there must be as many |
219 | | * PushClip(Rect) calls as there are PopClip calls. |
220 | | * |
221 | | * @param aOpaque Whether the layer will be opaque |
222 | | * @param aOpacity Opacity of the layer |
223 | | * @param aMask Mask applied to the layer |
224 | | * @param aMaskTransform Transform applied to the layer mask |
225 | | * @param aBounds Optional bounds in device space to which the layer is |
226 | | * limited in size. |
227 | | * @param aCopyBackground Whether to copy the background into the layer, this |
228 | | * is only supported when aOpaque is true. |
229 | | */ |
230 | | virtual void PushLayer(bool aOpaque, Float aOpacity, |
231 | | SourceSurface* aMask, |
232 | | const Matrix& aMaskTransform, |
233 | | const IntRect& aBounds = IntRect(), |
234 | | bool aCopyBackground = false) override; |
235 | | |
236 | | /** |
237 | | * Push a 'layer' to the DrawTarget, a layer is a temporary surface that all |
238 | | * drawing will be redirected to, this is used for example to support group |
239 | | * opacity or the masking of groups. Clips must be balanced within a layer, |
240 | | * i.e. between a matching PushLayer/PopLayer pair there must be as many |
241 | | * PushClip(Rect) calls as there are PopClip calls. |
242 | | * |
243 | | * @param aOpaque Whether the layer will be opaque |
244 | | * @param aOpacity Opacity of the layer |
245 | | * @param aMask Mask applied to the layer |
246 | | * @param aMaskTransform Transform applied to the layer mask |
247 | | * @param aBounds Optional bounds in device space to which the layer is |
248 | | * limited in size. |
249 | | * @param aCopyBackground Whether to copy the background into the layer, this |
250 | | * is only supported when aOpaque is true.a |
251 | | * @param aCompositionOp The CompositionOp to use when blending the layer into |
252 | | * the destination |
253 | | */ |
254 | | virtual void PushLayerWithBlend(bool aOpaque, Float aOpacity, |
255 | | SourceSurface* aMask, |
256 | | const Matrix& aMaskTransform, |
257 | | const IntRect& aBounds = IntRect(), |
258 | | bool aCopyBackground = false, |
259 | | CompositionOp aCompositionOp = CompositionOp::OP_OVER) override; |
260 | | |
261 | | |
262 | | /** |
263 | | * This balances a call to PushLayer and proceeds to blend the layer back |
264 | | * onto the background. This blend will blend the temporary surface back |
265 | | * onto the target in device space using POINT sampling and operator over. |
266 | | */ |
267 | | virtual void PopLayer() override; |
268 | | |
269 | | /* |
270 | | * Create a SourceSurface optimized for use with this DrawTarget from |
271 | | * existing bitmap data in memory. |
272 | | * |
273 | | * The SourceSurface does not take ownership of aData, and may be freed at any time. |
274 | | */ |
275 | | virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData, |
276 | | const IntSize &aSize, |
277 | | int32_t aStride, |
278 | | SurfaceFormat aFormat) const override; |
279 | | |
280 | | /* |
281 | | * Create a SourceSurface optimized for use with this DrawTarget from |
282 | | * an arbitrary other SourceSurface. This may return aSourceSurface or some |
283 | | * other existing surface. |
284 | | */ |
285 | | virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override; |
286 | | |
287 | | /* |
288 | | * Create a SourceSurface for a type of NativeSurface. This may fail if the |
289 | | * draw target does not know how to deal with the type of NativeSurface passed |
290 | | * in. |
291 | | */ |
292 | | virtual already_AddRefed<SourceSurface> |
293 | | CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override; |
294 | | |
295 | | /* |
296 | | * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget. |
297 | | */ |
298 | | virtual already_AddRefed<DrawTarget> |
299 | | CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override; |
300 | | |
301 | | /** |
302 | | * Create a similar DrawTarget whose requested size may be clipped based |
303 | | * on this DrawTarget's rect transformed to the new target's space. |
304 | | */ |
305 | | virtual RefPtr<DrawTarget> CreateClippedDrawTarget(const IntSize& aMaxSize, |
306 | | const Matrix& aTransform, |
307 | | SurfaceFormat aFormat) const override; |
308 | | |
309 | | /* |
310 | | * Create a path builder with the specified fillmode. |
311 | | * |
312 | | * We need the fill mode up front because of Direct2D. |
313 | | * ID2D1SimplifiedGeometrySink requires the fill mode |
314 | | * to be set before calling BeginFigure(). |
315 | | */ |
316 | | virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override; |
317 | | |
318 | | /* |
319 | | * Create a GradientStops object that holds information about a set of |
320 | | * gradient stops, this object is required for linear or radial gradient |
321 | | * patterns to represent the color stops in the gradient. |
322 | | * |
323 | | * aStops An array of gradient stops |
324 | | * aNumStops Number of stops in the array aStops |
325 | | * aExtendNone This describes how to extend the stop color outside of the |
326 | | * gradient area. |
327 | | */ |
328 | | virtual already_AddRefed<GradientStops> |
329 | | CreateGradientStops(GradientStop *aStops, |
330 | | uint32_t aNumStops, |
331 | | ExtendMode aExtendMode = ExtendMode::CLAMP) const override; |
332 | | |
333 | | virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override; |
334 | | |
335 | | /* |
336 | | * Set a transform on the surface, this transform is applied at drawing time |
337 | | * to both the mask and source of the operation. |
338 | | */ |
339 | | virtual void SetTransform(const Matrix &aTransform) override; |
340 | | |
341 | | /* Tries to get a native surface for a DrawTarget, this may fail if the |
342 | | * draw target cannot convert to this surface type. |
343 | | */ |
344 | 0 | virtual void *GetNativeSurface(NativeSurfaceType aType) override { return mFinalDT->GetNativeSurface(aType); } |
345 | | |
346 | 0 | virtual bool IsCurrentGroupOpaque() override { |
347 | 0 | return mFinalDT->IsCurrentGroupOpaque(); |
348 | 0 | } |
349 | | |
350 | | private: |
351 | | /** |
352 | | * Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call. |
353 | | * |
354 | | * @param aDT DrawTargetRecording on which CreateSimilarDrawTarget was called |
355 | | * @param aSize size of the the similar DrawTarget |
356 | | * @param aFormat format of the similar DrawTarget |
357 | | */ |
358 | | DrawTargetRecording(const DrawTargetRecording *aDT, |
359 | | IntSize aSize, SurfaceFormat aFormat); |
360 | | |
361 | | Path *GetPathForPathRecording(const Path *aPath) const; |
362 | | already_AddRefed<PathRecording> EnsurePathStored(const Path *aPath); |
363 | | void EnsurePatternDependenciesStored(const Pattern &aPattern); |
364 | | |
365 | | RefPtr<DrawEventRecorderPrivate> mRecorder; |
366 | | RefPtr<DrawTarget> mFinalDT; |
367 | | IntSize mSize; |
368 | | }; |
369 | | |
370 | | } // namespace gfx |
371 | | } // namespace mozilla |
372 | | |
373 | | #endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */ |