gfx/2d/DrawTargetRecording.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

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

mercurial