1 /* -*- Mode: C++; tab-width: 20; 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/. */
6 #ifndef MOZILLA_GFX_DRAWTARGETRECORDING_H_
7 #define MOZILLA_GFX_DRAWTARGETRECORDING_H_
10 #include "DrawEventRecorder.h"
15 class DrawTargetRecording
: public DrawTarget
18 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording
)
19 DrawTargetRecording(DrawEventRecorder
*aRecorder
, DrawTarget
*aDT
, bool aHasData
= false);
20 ~DrawTargetRecording();
22 virtual DrawTargetType
GetType() const MOZ_OVERRIDE
{ return mFinalDT
->GetType(); }
23 virtual BackendType
GetBackendType() const { return mFinalDT
->GetBackendType(); }
25 virtual TemporaryRef
<SourceSurface
> Snapshot();
27 virtual IntSize
GetSize() { return mFinalDT
->GetSize(); }
29 /* Ensure that the DrawTarget backend has flushed all drawing operations to
30 * this draw target. This must be called before using the backing surface of
31 * this draw target outside of GFX 2D code.
33 virtual void Flush() { mFinalDT
->Flush(); }
36 * Draw a surface to the draw target. Possibly doing partial drawing or
37 * applying scaling. No sampling happens outside the source.
39 * aSurface Source surface to draw
40 * aDest Destination rectangle that this drawing operation should draw to
41 * aSource Source rectangle in aSurface coordinates, this area of aSurface
42 * will be stretched to the size of aDest.
43 * aOptions General draw options that are applied to the operation
44 * aSurfOptions DrawSurface options that are applied
46 virtual void DrawSurface(SourceSurface
*aSurface
,
49 const DrawSurfaceOptions
&aSurfOptions
= DrawSurfaceOptions(),
50 const DrawOptions
&aOptions
= DrawOptions());
52 virtual void DrawFilter(FilterNode
*aNode
,
53 const Rect
&aSourceRect
,
54 const Point
&aDestPoint
,
55 const DrawOptions
&aOptions
= DrawOptions());
58 * Blend a surface to the draw target with a shadow. The shadow is drawn as a
59 * gaussian blur using a specified sigma. The shadow is clipped to the size
60 * of the input surface, so the input surface should contain a transparent
61 * border the size of the approximate coverage of the blur (3 * aSigma).
62 * NOTE: This function works in device space!
64 * aSurface Source surface to draw.
65 * aDest Destination point that this drawing operation should draw to.
66 * aColor Color of the drawn shadow
67 * aOffset Offset of the shadow
68 * aSigma Sigma used for the guassian filter kernel
69 * aOperator Composition operator used
71 virtual void DrawSurfaceWithShadow(SourceSurface
*aSurface
,
76 CompositionOp aOperator
);
79 * Clear a rectangle on the draw target to transparent black. This will
80 * respect the clipping region and transform.
82 * aRect Rectangle to clear
84 virtual void ClearRect(const Rect
&aRect
);
87 * This is essentially a 'memcpy' between two surfaces. It moves a pixel
88 * aligned area from the source surface unscaled directly onto the
89 * drawtarget. This ignores both transform and clip.
91 * aSurface Surface to copy from
92 * aSourceRect Source rectangle to be copied
93 * aDest Destination point to copy the surface to
95 virtual void CopySurface(SourceSurface
*aSurface
,
96 const IntRect
&aSourceRect
,
97 const IntPoint
&aDestination
);
100 * Fill a rectangle on the DrawTarget with a certain source pattern.
102 * aRect Rectangle that forms the mask of this filling operation
103 * aPattern Pattern that forms the source of this filling operation
104 * aOptions Options that are applied to this operation
106 virtual void FillRect(const Rect
&aRect
,
107 const Pattern
&aPattern
,
108 const DrawOptions
&aOptions
= DrawOptions());
111 * Stroke a rectangle on the DrawTarget with a certain source pattern.
113 * aRect Rectangle that forms the mask of this stroking operation
114 * aPattern Pattern that forms the source of this stroking operation
115 * aOptions Options that are applied to this operation
117 virtual void StrokeRect(const Rect
&aRect
,
118 const Pattern
&aPattern
,
119 const StrokeOptions
&aStrokeOptions
= StrokeOptions(),
120 const DrawOptions
&aOptions
= DrawOptions());
123 * Stroke a line on the DrawTarget with a certain source pattern.
125 * aStart Starting point of the line
126 * aEnd End point of the line
127 * aPattern Pattern that forms the source of this stroking operation
128 * aOptions Options that are applied to this operation
130 virtual void StrokeLine(const Point
&aStart
,
132 const Pattern
&aPattern
,
133 const StrokeOptions
&aStrokeOptions
= StrokeOptions(),
134 const DrawOptions
&aOptions
= DrawOptions());
137 * Stroke a path on the draw target with a certain source pattern.
139 * aPath Path that is to be stroked
140 * aPattern Pattern that should be used for the stroke
141 * aStrokeOptions Stroke options used for this operation
142 * aOptions Draw options used for this operation
144 virtual void Stroke(const Path
*aPath
,
145 const Pattern
&aPattern
,
146 const StrokeOptions
&aStrokeOptions
= StrokeOptions(),
147 const DrawOptions
&aOptions
= DrawOptions());
150 * Fill a path on the draw target with a certain source pattern.
152 * aPath Path that is to be filled
153 * aPattern Pattern that should be used for the fill
154 * aOptions Draw options used for this operation
156 virtual void Fill(const Path
*aPath
,
157 const Pattern
&aPattern
,
158 const DrawOptions
&aOptions
= DrawOptions());
161 * Fill a series of clyphs on the draw target with a certain source pattern.
163 virtual void FillGlyphs(ScaledFont
*aFont
,
164 const GlyphBuffer
&aBuffer
,
165 const Pattern
&aPattern
,
166 const DrawOptions
&aOptions
= DrawOptions(),
167 const GlyphRenderingOptions
*aRenderingOptions
= nullptr);
170 * This takes a source pattern and a mask, and composites the source pattern
171 * onto the destination surface using the alpha channel of the mask pattern
172 * as a mask for the operation.
174 * aSource Source pattern
176 * aOptions Drawing options
178 virtual void Mask(const Pattern
&aSource
,
179 const Pattern
&aMask
,
180 const DrawOptions
&aOptions
= DrawOptions());
182 virtual void MaskSurface(const Pattern
&aSource
,
183 SourceSurface
*aMask
,
185 const DrawOptions
&aOptions
= DrawOptions());
188 * Push a clip to the DrawTarget.
190 * aPath The path to clip to
192 virtual void PushClip(const Path
*aPath
);
195 * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
196 * is specified in user space.
198 * aRect The rect to clip to
200 virtual void PushClipRect(const Rect
&aRect
);
202 /* Pop a clip from the DrawTarget. A pop without a corresponding push will
205 virtual void PopClip();
208 * Create a SourceSurface optimized for use with this DrawTarget from
209 * existing bitmap data in memory.
211 * The SourceSurface does not take ownership of aData, and may be freed at any time.
213 virtual TemporaryRef
<SourceSurface
> CreateSourceSurfaceFromData(unsigned char *aData
,
214 const IntSize
&aSize
,
216 SurfaceFormat aFormat
) const;
219 * Create a SourceSurface optimized for use with this DrawTarget from
220 * an arbitrary other SourceSurface. This may return aSourceSurface or some
221 * other existing surface.
223 virtual TemporaryRef
<SourceSurface
> OptimizeSourceSurface(SourceSurface
*aSurface
) const;
226 * Create a SourceSurface for a type of NativeSurface. This may fail if the
227 * draw target does not know how to deal with the type of NativeSurface passed
230 virtual TemporaryRef
<SourceSurface
>
231 CreateSourceSurfaceFromNativeSurface(const NativeSurface
&aSurface
) const;
234 * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget.
236 virtual TemporaryRef
<DrawTarget
>
237 CreateSimilarDrawTarget(const IntSize
&aSize
, SurfaceFormat aFormat
) const;
240 * Create a path builder with the specified fillmode.
242 * We need the fill mode up front because of Direct2D.
243 * ID2D1SimplifiedGeometrySink requires the fill mode
244 * to be set before calling BeginFigure().
246 virtual TemporaryRef
<PathBuilder
> CreatePathBuilder(FillRule aFillRule
= FillRule::FILL_WINDING
) const;
249 * Create a GradientStops object that holds information about a set of
250 * gradient stops, this object is required for linear or radial gradient
251 * patterns to represent the color stops in the gradient.
253 * aStops An array of gradient stops
254 * aNumStops Number of stops in the array aStops
255 * aExtendNone This describes how to extend the stop color outside of the
258 virtual TemporaryRef
<GradientStops
>
259 CreateGradientStops(GradientStop
*aStops
,
261 ExtendMode aExtendMode
= ExtendMode::CLAMP
) const;
263 virtual TemporaryRef
<FilterNode
> CreateFilter(FilterType aType
);
266 * Set a transform on the surface, this transform is applied at drawing time
267 * to both the mask and source of the operation.
269 virtual void SetTransform(const Matrix
&aTransform
);
271 /* Tries to get a native surface for a DrawTarget, this may fail if the
272 * draw target cannot convert to this surface type.
274 virtual void *GetNativeSurface(NativeSurfaceType aType
) { return mFinalDT
->GetNativeSurface(aType
); }
277 Path
*GetPathForPathRecording(const Path
*aPath
) const;
278 void EnsureStored(const Path
*aPath
);
280 RefPtr
<DrawEventRecorderPrivate
> mRecorder
;
281 RefPtr
<DrawTarget
> mFinalDT
;
287 #endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */