1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/DrawTargetRecording.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,286 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef MOZILLA_GFX_DRAWTARGETRECORDING_H_ 1.10 +#define MOZILLA_GFX_DRAWTARGETRECORDING_H_ 1.11 + 1.12 +#include "2D.h" 1.13 +#include "DrawEventRecorder.h" 1.14 + 1.15 +namespace mozilla { 1.16 +namespace gfx { 1.17 + 1.18 +class DrawTargetRecording : public DrawTarget 1.19 +{ 1.20 +public: 1.21 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording) 1.22 + DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false); 1.23 + ~DrawTargetRecording(); 1.24 + 1.25 + virtual BackendType GetType() const { return mFinalDT->GetType(); } 1.26 + 1.27 + virtual TemporaryRef<SourceSurface> Snapshot(); 1.28 + 1.29 + virtual IntSize GetSize() { return mFinalDT->GetSize(); } 1.30 + 1.31 + /* Ensure that the DrawTarget backend has flushed all drawing operations to 1.32 + * this draw target. This must be called before using the backing surface of 1.33 + * this draw target outside of GFX 2D code. 1.34 + */ 1.35 + virtual void Flush() { mFinalDT->Flush(); } 1.36 + 1.37 + /* 1.38 + * Draw a surface to the draw target. Possibly doing partial drawing or 1.39 + * applying scaling. No sampling happens outside the source. 1.40 + * 1.41 + * aSurface Source surface to draw 1.42 + * aDest Destination rectangle that this drawing operation should draw to 1.43 + * aSource Source rectangle in aSurface coordinates, this area of aSurface 1.44 + * will be stretched to the size of aDest. 1.45 + * aOptions General draw options that are applied to the operation 1.46 + * aSurfOptions DrawSurface options that are applied 1.47 + */ 1.48 + virtual void DrawSurface(SourceSurface *aSurface, 1.49 + const Rect &aDest, 1.50 + const Rect &aSource, 1.51 + const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), 1.52 + const DrawOptions &aOptions = DrawOptions()); 1.53 + 1.54 + virtual void DrawFilter(FilterNode *aNode, 1.55 + const Rect &aSourceRect, 1.56 + const Point &aDestPoint, 1.57 + const DrawOptions &aOptions = DrawOptions()); 1.58 + 1.59 + /* 1.60 + * Blend a surface to the draw target with a shadow. The shadow is drawn as a 1.61 + * gaussian blur using a specified sigma. The shadow is clipped to the size 1.62 + * of the input surface, so the input surface should contain a transparent 1.63 + * border the size of the approximate coverage of the blur (3 * aSigma). 1.64 + * NOTE: This function works in device space! 1.65 + * 1.66 + * aSurface Source surface to draw. 1.67 + * aDest Destination point that this drawing operation should draw to. 1.68 + * aColor Color of the drawn shadow 1.69 + * aOffset Offset of the shadow 1.70 + * aSigma Sigma used for the guassian filter kernel 1.71 + * aOperator Composition operator used 1.72 + */ 1.73 + virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, 1.74 + const Point &aDest, 1.75 + const Color &aColor, 1.76 + const Point &aOffset, 1.77 + Float aSigma, 1.78 + CompositionOp aOperator); 1.79 + 1.80 + /* 1.81 + * Clear a rectangle on the draw target to transparent black. This will 1.82 + * respect the clipping region and transform. 1.83 + * 1.84 + * aRect Rectangle to clear 1.85 + */ 1.86 + virtual void ClearRect(const Rect &aRect); 1.87 + 1.88 + /* 1.89 + * This is essentially a 'memcpy' between two surfaces. It moves a pixel 1.90 + * aligned area from the source surface unscaled directly onto the 1.91 + * drawtarget. This ignores both transform and clip. 1.92 + * 1.93 + * aSurface Surface to copy from 1.94 + * aSourceRect Source rectangle to be copied 1.95 + * aDest Destination point to copy the surface to 1.96 + */ 1.97 + virtual void CopySurface(SourceSurface *aSurface, 1.98 + const IntRect &aSourceRect, 1.99 + const IntPoint &aDestination); 1.100 + 1.101 + /* 1.102 + * Fill a rectangle on the DrawTarget with a certain source pattern. 1.103 + * 1.104 + * aRect Rectangle that forms the mask of this filling operation 1.105 + * aPattern Pattern that forms the source of this filling operation 1.106 + * aOptions Options that are applied to this operation 1.107 + */ 1.108 + virtual void FillRect(const Rect &aRect, 1.109 + const Pattern &aPattern, 1.110 + const DrawOptions &aOptions = DrawOptions()); 1.111 + 1.112 + /* 1.113 + * Stroke a rectangle on the DrawTarget with a certain source pattern. 1.114 + * 1.115 + * aRect Rectangle that forms the mask of this stroking operation 1.116 + * aPattern Pattern that forms the source of this stroking operation 1.117 + * aOptions Options that are applied to this operation 1.118 + */ 1.119 + virtual void StrokeRect(const Rect &aRect, 1.120 + const Pattern &aPattern, 1.121 + const StrokeOptions &aStrokeOptions = StrokeOptions(), 1.122 + const DrawOptions &aOptions = DrawOptions()); 1.123 + 1.124 + /* 1.125 + * Stroke a line on the DrawTarget with a certain source pattern. 1.126 + * 1.127 + * aStart Starting point of the line 1.128 + * aEnd End point of the line 1.129 + * aPattern Pattern that forms the source of this stroking operation 1.130 + * aOptions Options that are applied to this operation 1.131 + */ 1.132 + virtual void StrokeLine(const Point &aStart, 1.133 + const Point &aEnd, 1.134 + const Pattern &aPattern, 1.135 + const StrokeOptions &aStrokeOptions = StrokeOptions(), 1.136 + const DrawOptions &aOptions = DrawOptions()); 1.137 + 1.138 + /* 1.139 + * Stroke a path on the draw target with a certain source pattern. 1.140 + * 1.141 + * aPath Path that is to be stroked 1.142 + * aPattern Pattern that should be used for the stroke 1.143 + * aStrokeOptions Stroke options used for this operation 1.144 + * aOptions Draw options used for this operation 1.145 + */ 1.146 + virtual void Stroke(const Path *aPath, 1.147 + const Pattern &aPattern, 1.148 + const StrokeOptions &aStrokeOptions = StrokeOptions(), 1.149 + const DrawOptions &aOptions = DrawOptions()); 1.150 + 1.151 + /* 1.152 + * Fill a path on the draw target with a certain source pattern. 1.153 + * 1.154 + * aPath Path that is to be filled 1.155 + * aPattern Pattern that should be used for the fill 1.156 + * aOptions Draw options used for this operation 1.157 + */ 1.158 + virtual void Fill(const Path *aPath, 1.159 + const Pattern &aPattern, 1.160 + const DrawOptions &aOptions = DrawOptions()); 1.161 + 1.162 + /* 1.163 + * Fill a series of clyphs on the draw target with a certain source pattern. 1.164 + */ 1.165 + virtual void FillGlyphs(ScaledFont *aFont, 1.166 + const GlyphBuffer &aBuffer, 1.167 + const Pattern &aPattern, 1.168 + const DrawOptions &aOptions = DrawOptions(), 1.169 + const GlyphRenderingOptions *aRenderingOptions = nullptr); 1.170 + 1.171 + /* 1.172 + * This takes a source pattern and a mask, and composites the source pattern 1.173 + * onto the destination surface using the alpha channel of the mask pattern 1.174 + * as a mask for the operation. 1.175 + * 1.176 + * aSource Source pattern 1.177 + * aMask Mask pattern 1.178 + * aOptions Drawing options 1.179 + */ 1.180 + virtual void Mask(const Pattern &aSource, 1.181 + const Pattern &aMask, 1.182 + const DrawOptions &aOptions = DrawOptions()); 1.183 + 1.184 + virtual void MaskSurface(const Pattern &aSource, 1.185 + SourceSurface *aMask, 1.186 + Point aOffset, 1.187 + const DrawOptions &aOptions = DrawOptions()); 1.188 + 1.189 + /* 1.190 + * Push a clip to the DrawTarget. 1.191 + * 1.192 + * aPath The path to clip to 1.193 + */ 1.194 + virtual void PushClip(const Path *aPath); 1.195 + 1.196 + /* 1.197 + * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle 1.198 + * is specified in user space. 1.199 + * 1.200 + * aRect The rect to clip to 1.201 + */ 1.202 + virtual void PushClipRect(const Rect &aRect); 1.203 + 1.204 + /* Pop a clip from the DrawTarget. A pop without a corresponding push will 1.205 + * be ignored. 1.206 + */ 1.207 + virtual void PopClip(); 1.208 + 1.209 + /* 1.210 + * Create a SourceSurface optimized for use with this DrawTarget from 1.211 + * existing bitmap data in memory. 1.212 + * 1.213 + * The SourceSurface does not take ownership of aData, and may be freed at any time. 1.214 + */ 1.215 + virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData, 1.216 + const IntSize &aSize, 1.217 + int32_t aStride, 1.218 + SurfaceFormat aFormat) const; 1.219 + 1.220 + /* 1.221 + * Create a SourceSurface optimized for use with this DrawTarget from 1.222 + * an arbitrary other SourceSurface. This may return aSourceSurface or some 1.223 + * other existing surface. 1.224 + */ 1.225 + virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const; 1.226 + 1.227 + /* 1.228 + * Create a SourceSurface for a type of NativeSurface. This may fail if the 1.229 + * draw target does not know how to deal with the type of NativeSurface passed 1.230 + * in. 1.231 + */ 1.232 + virtual TemporaryRef<SourceSurface> 1.233 + CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const; 1.234 + 1.235 + /* 1.236 + * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget. 1.237 + */ 1.238 + virtual TemporaryRef<DrawTarget> 1.239 + CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; 1.240 + 1.241 + /* 1.242 + * Create a path builder with the specified fillmode. 1.243 + * 1.244 + * We need the fill mode up front because of Direct2D. 1.245 + * ID2D1SimplifiedGeometrySink requires the fill mode 1.246 + * to be set before calling BeginFigure(). 1.247 + */ 1.248 + virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; 1.249 + 1.250 + /* 1.251 + * Create a GradientStops object that holds information about a set of 1.252 + * gradient stops, this object is required for linear or radial gradient 1.253 + * patterns to represent the color stops in the gradient. 1.254 + * 1.255 + * aStops An array of gradient stops 1.256 + * aNumStops Number of stops in the array aStops 1.257 + * aExtendNone This describes how to extend the stop color outside of the 1.258 + * gradient area. 1.259 + */ 1.260 + virtual TemporaryRef<GradientStops> 1.261 + CreateGradientStops(GradientStop *aStops, 1.262 + uint32_t aNumStops, 1.263 + ExtendMode aExtendMode = ExtendMode::CLAMP) const; 1.264 + 1.265 + virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType); 1.266 + 1.267 + /* 1.268 + * Set a transform on the surface, this transform is applied at drawing time 1.269 + * to both the mask and source of the operation. 1.270 + */ 1.271 + virtual void SetTransform(const Matrix &aTransform); 1.272 + 1.273 + /* Tries to get a native surface for a DrawTarget, this may fail if the 1.274 + * draw target cannot convert to this surface type. 1.275 + */ 1.276 + virtual void *GetNativeSurface(NativeSurfaceType aType) { return mFinalDT->GetNativeSurface(aType); } 1.277 + 1.278 +private: 1.279 + Path *GetPathForPathRecording(const Path *aPath) const; 1.280 + void EnsureStored(const Path *aPath); 1.281 + 1.282 + RefPtr<DrawEventRecorderPrivate> mRecorder; 1.283 + RefPtr<DrawTarget> mFinalDT; 1.284 +}; 1.285 + 1.286 +} 1.287 +} 1.288 + 1.289 +#endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */