Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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_
9 #include "2D.h"
10 #include "DrawEventRecorder.h"
12 namespace mozilla {
13 namespace gfx {
15 class DrawTargetRecording : public DrawTarget
16 {
17 public:
18 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording)
19 DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false);
20 ~DrawTargetRecording();
22 virtual BackendType GetType() const { return mFinalDT->GetType(); }
24 virtual TemporaryRef<SourceSurface> Snapshot();
26 virtual IntSize GetSize() { return mFinalDT->GetSize(); }
28 /* Ensure that the DrawTarget backend has flushed all drawing operations to
29 * this draw target. This must be called before using the backing surface of
30 * this draw target outside of GFX 2D code.
31 */
32 virtual void Flush() { mFinalDT->Flush(); }
34 /*
35 * Draw a surface to the draw target. Possibly doing partial drawing or
36 * applying scaling. No sampling happens outside the source.
37 *
38 * aSurface Source surface to draw
39 * aDest Destination rectangle that this drawing operation should draw to
40 * aSource Source rectangle in aSurface coordinates, this area of aSurface
41 * will be stretched to the size of aDest.
42 * aOptions General draw options that are applied to the operation
43 * aSurfOptions DrawSurface options that are applied
44 */
45 virtual void DrawSurface(SourceSurface *aSurface,
46 const Rect &aDest,
47 const Rect &aSource,
48 const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
49 const DrawOptions &aOptions = DrawOptions());
51 virtual void DrawFilter(FilterNode *aNode,
52 const Rect &aSourceRect,
53 const Point &aDestPoint,
54 const DrawOptions &aOptions = DrawOptions());
56 /*
57 * Blend a surface to the draw target with a shadow. The shadow is drawn as a
58 * gaussian blur using a specified sigma. The shadow is clipped to the size
59 * of the input surface, so the input surface should contain a transparent
60 * border the size of the approximate coverage of the blur (3 * aSigma).
61 * NOTE: This function works in device space!
62 *
63 * aSurface Source surface to draw.
64 * aDest Destination point that this drawing operation should draw to.
65 * aColor Color of the drawn shadow
66 * aOffset Offset of the shadow
67 * aSigma Sigma used for the guassian filter kernel
68 * aOperator Composition operator used
69 */
70 virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
71 const Point &aDest,
72 const Color &aColor,
73 const Point &aOffset,
74 Float aSigma,
75 CompositionOp aOperator);
77 /*
78 * Clear a rectangle on the draw target to transparent black. This will
79 * respect the clipping region and transform.
80 *
81 * aRect Rectangle to clear
82 */
83 virtual void ClearRect(const Rect &aRect);
85 /*
86 * This is essentially a 'memcpy' between two surfaces. It moves a pixel
87 * aligned area from the source surface unscaled directly onto the
88 * drawtarget. This ignores both transform and clip.
89 *
90 * aSurface Surface to copy from
91 * aSourceRect Source rectangle to be copied
92 * aDest Destination point to copy the surface to
93 */
94 virtual void CopySurface(SourceSurface *aSurface,
95 const IntRect &aSourceRect,
96 const IntPoint &aDestination);
98 /*
99 * Fill a rectangle on the DrawTarget with a certain source pattern.
100 *
101 * aRect Rectangle that forms the mask of this filling operation
102 * aPattern Pattern that forms the source of this filling operation
103 * aOptions Options that are applied to this operation
104 */
105 virtual void FillRect(const Rect &aRect,
106 const Pattern &aPattern,
107 const DrawOptions &aOptions = DrawOptions());
109 /*
110 * Stroke a rectangle on the DrawTarget with a certain source pattern.
111 *
112 * aRect Rectangle that forms the mask of this stroking operation
113 * aPattern Pattern that forms the source of this stroking operation
114 * aOptions Options that are applied to this operation
115 */
116 virtual void StrokeRect(const Rect &aRect,
117 const Pattern &aPattern,
118 const StrokeOptions &aStrokeOptions = StrokeOptions(),
119 const DrawOptions &aOptions = DrawOptions());
121 /*
122 * Stroke a line on the DrawTarget with a certain source pattern.
123 *
124 * aStart Starting point of the line
125 * aEnd End point of the line
126 * aPattern Pattern that forms the source of this stroking operation
127 * aOptions Options that are applied to this operation
128 */
129 virtual void StrokeLine(const Point &aStart,
130 const Point &aEnd,
131 const Pattern &aPattern,
132 const StrokeOptions &aStrokeOptions = StrokeOptions(),
133 const DrawOptions &aOptions = DrawOptions());
135 /*
136 * Stroke a path on the draw target with a certain source pattern.
137 *
138 * aPath Path that is to be stroked
139 * aPattern Pattern that should be used for the stroke
140 * aStrokeOptions Stroke options used for this operation
141 * aOptions Draw options used for this operation
142 */
143 virtual void Stroke(const Path *aPath,
144 const Pattern &aPattern,
145 const StrokeOptions &aStrokeOptions = StrokeOptions(),
146 const DrawOptions &aOptions = DrawOptions());
148 /*
149 * Fill a path on the draw target with a certain source pattern.
150 *
151 * aPath Path that is to be filled
152 * aPattern Pattern that should be used for the fill
153 * aOptions Draw options used for this operation
154 */
155 virtual void Fill(const Path *aPath,
156 const Pattern &aPattern,
157 const DrawOptions &aOptions = DrawOptions());
159 /*
160 * Fill a series of clyphs on the draw target with a certain source pattern.
161 */
162 virtual void FillGlyphs(ScaledFont *aFont,
163 const GlyphBuffer &aBuffer,
164 const Pattern &aPattern,
165 const DrawOptions &aOptions = DrawOptions(),
166 const GlyphRenderingOptions *aRenderingOptions = nullptr);
168 /*
169 * This takes a source pattern and a mask, and composites the source pattern
170 * onto the destination surface using the alpha channel of the mask pattern
171 * as a mask for the operation.
172 *
173 * aSource Source pattern
174 * aMask Mask pattern
175 * aOptions Drawing options
176 */
177 virtual void Mask(const Pattern &aSource,
178 const Pattern &aMask,
179 const DrawOptions &aOptions = DrawOptions());
181 virtual void MaskSurface(const Pattern &aSource,
182 SourceSurface *aMask,
183 Point aOffset,
184 const DrawOptions &aOptions = DrawOptions());
186 /*
187 * Push a clip to the DrawTarget.
188 *
189 * aPath The path to clip to
190 */
191 virtual void PushClip(const Path *aPath);
193 /*
194 * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
195 * is specified in user space.
196 *
197 * aRect The rect to clip to
198 */
199 virtual void PushClipRect(const Rect &aRect);
201 /* Pop a clip from the DrawTarget. A pop without a corresponding push will
202 * be ignored.
203 */
204 virtual void PopClip();
206 /*
207 * Create a SourceSurface optimized for use with this DrawTarget from
208 * existing bitmap data in memory.
209 *
210 * The SourceSurface does not take ownership of aData, and may be freed at any time.
211 */
212 virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
213 const IntSize &aSize,
214 int32_t aStride,
215 SurfaceFormat aFormat) const;
217 /*
218 * Create a SourceSurface optimized for use with this DrawTarget from
219 * an arbitrary other SourceSurface. This may return aSourceSurface or some
220 * other existing surface.
221 */
222 virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
224 /*
225 * Create a SourceSurface for a type of NativeSurface. This may fail if the
226 * draw target does not know how to deal with the type of NativeSurface passed
227 * in.
228 */
229 virtual TemporaryRef<SourceSurface>
230 CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const;
232 /*
233 * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget.
234 */
235 virtual TemporaryRef<DrawTarget>
236 CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
238 /*
239 * Create a path builder with the specified fillmode.
240 *
241 * We need the fill mode up front because of Direct2D.
242 * ID2D1SimplifiedGeometrySink requires the fill mode
243 * to be set before calling BeginFigure().
244 */
245 virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
247 /*
248 * Create a GradientStops object that holds information about a set of
249 * gradient stops, this object is required for linear or radial gradient
250 * patterns to represent the color stops in the gradient.
251 *
252 * aStops An array of gradient stops
253 * aNumStops Number of stops in the array aStops
254 * aExtendNone This describes how to extend the stop color outside of the
255 * gradient area.
256 */
257 virtual TemporaryRef<GradientStops>
258 CreateGradientStops(GradientStop *aStops,
259 uint32_t aNumStops,
260 ExtendMode aExtendMode = ExtendMode::CLAMP) const;
262 virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
264 /*
265 * Set a transform on the surface, this transform is applied at drawing time
266 * to both the mask and source of the operation.
267 */
268 virtual void SetTransform(const Matrix &aTransform);
270 /* Tries to get a native surface for a DrawTarget, this may fail if the
271 * draw target cannot convert to this surface type.
272 */
273 virtual void *GetNativeSurface(NativeSurfaceType aType) { return mFinalDT->GetNativeSurface(aType); }
275 private:
276 Path *GetPathForPathRecording(const Path *aPath) const;
277 void EnsureStored(const Path *aPath);
279 RefPtr<DrawEventRecorderPrivate> mRecorder;
280 RefPtr<DrawTarget> mFinalDT;
281 };
283 }
284 }
286 #endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */