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