michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_DRAWTARGETRECORDING_H_ michael@0: #define MOZILLA_GFX_DRAWTARGETRECORDING_H_ michael@0: michael@0: #include "2D.h" michael@0: #include "DrawEventRecorder.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: class DrawTargetRecording : public DrawTarget michael@0: { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording) michael@0: DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false); michael@0: ~DrawTargetRecording(); michael@0: michael@0: virtual BackendType GetType() const { return mFinalDT->GetType(); } michael@0: michael@0: virtual TemporaryRef Snapshot(); michael@0: michael@0: virtual IntSize GetSize() { return mFinalDT->GetSize(); } michael@0: michael@0: /* Ensure that the DrawTarget backend has flushed all drawing operations to michael@0: * this draw target. This must be called before using the backing surface of michael@0: * this draw target outside of GFX 2D code. michael@0: */ michael@0: virtual void Flush() { mFinalDT->Flush(); } michael@0: michael@0: /* michael@0: * Draw a surface to the draw target. Possibly doing partial drawing or michael@0: * applying scaling. No sampling happens outside the source. michael@0: * michael@0: * aSurface Source surface to draw michael@0: * aDest Destination rectangle that this drawing operation should draw to michael@0: * aSource Source rectangle in aSurface coordinates, this area of aSurface michael@0: * will be stretched to the size of aDest. michael@0: * aOptions General draw options that are applied to the operation michael@0: * aSurfOptions DrawSurface options that are applied michael@0: */ michael@0: virtual void DrawSurface(SourceSurface *aSurface, michael@0: const Rect &aDest, michael@0: const Rect &aSource, michael@0: const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: virtual void DrawFilter(FilterNode *aNode, michael@0: const Rect &aSourceRect, michael@0: const Point &aDestPoint, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Blend a surface to the draw target with a shadow. The shadow is drawn as a michael@0: * gaussian blur using a specified sigma. The shadow is clipped to the size michael@0: * of the input surface, so the input surface should contain a transparent michael@0: * border the size of the approximate coverage of the blur (3 * aSigma). michael@0: * NOTE: This function works in device space! michael@0: * michael@0: * aSurface Source surface to draw. michael@0: * aDest Destination point that this drawing operation should draw to. michael@0: * aColor Color of the drawn shadow michael@0: * aOffset Offset of the shadow michael@0: * aSigma Sigma used for the guassian filter kernel michael@0: * aOperator Composition operator used michael@0: */ michael@0: virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, michael@0: const Point &aDest, michael@0: const Color &aColor, michael@0: const Point &aOffset, michael@0: Float aSigma, michael@0: CompositionOp aOperator); michael@0: michael@0: /* michael@0: * Clear a rectangle on the draw target to transparent black. This will michael@0: * respect the clipping region and transform. michael@0: * michael@0: * aRect Rectangle to clear michael@0: */ michael@0: virtual void ClearRect(const Rect &aRect); michael@0: michael@0: /* michael@0: * This is essentially a 'memcpy' between two surfaces. It moves a pixel michael@0: * aligned area from the source surface unscaled directly onto the michael@0: * drawtarget. This ignores both transform and clip. michael@0: * michael@0: * aSurface Surface to copy from michael@0: * aSourceRect Source rectangle to be copied michael@0: * aDest Destination point to copy the surface to michael@0: */ michael@0: virtual void CopySurface(SourceSurface *aSurface, michael@0: const IntRect &aSourceRect, michael@0: const IntPoint &aDestination); michael@0: michael@0: /* michael@0: * Fill a rectangle on the DrawTarget with a certain source pattern. michael@0: * michael@0: * aRect Rectangle that forms the mask of this filling operation michael@0: * aPattern Pattern that forms the source of this filling operation michael@0: * aOptions Options that are applied to this operation michael@0: */ michael@0: virtual void FillRect(const Rect &aRect, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Stroke a rectangle on the DrawTarget with a certain source pattern. michael@0: * michael@0: * aRect Rectangle that forms the mask of this stroking operation michael@0: * aPattern Pattern that forms the source of this stroking operation michael@0: * aOptions Options that are applied to this operation michael@0: */ michael@0: virtual void StrokeRect(const Rect &aRect, michael@0: const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions = StrokeOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Stroke a line on the DrawTarget with a certain source pattern. michael@0: * michael@0: * aStart Starting point of the line michael@0: * aEnd End point of the line michael@0: * aPattern Pattern that forms the source of this stroking operation michael@0: * aOptions Options that are applied to this operation michael@0: */ michael@0: virtual void StrokeLine(const Point &aStart, michael@0: const Point &aEnd, michael@0: const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions = StrokeOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Stroke a path on the draw target with a certain source pattern. michael@0: * michael@0: * aPath Path that is to be stroked michael@0: * aPattern Pattern that should be used for the stroke michael@0: * aStrokeOptions Stroke options used for this operation michael@0: * aOptions Draw options used for this operation michael@0: */ michael@0: virtual void Stroke(const Path *aPath, michael@0: const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions = StrokeOptions(), michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Fill a path on the draw target with a certain source pattern. michael@0: * michael@0: * aPath Path that is to be filled michael@0: * aPattern Pattern that should be used for the fill michael@0: * aOptions Draw options used for this operation michael@0: */ michael@0: virtual void Fill(const Path *aPath, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Fill a series of clyphs on the draw target with a certain source pattern. michael@0: */ michael@0: virtual void FillGlyphs(ScaledFont *aFont, michael@0: const GlyphBuffer &aBuffer, michael@0: const Pattern &aPattern, michael@0: const DrawOptions &aOptions = DrawOptions(), michael@0: const GlyphRenderingOptions *aRenderingOptions = nullptr); michael@0: michael@0: /* michael@0: * This takes a source pattern and a mask, and composites the source pattern michael@0: * onto the destination surface using the alpha channel of the mask pattern michael@0: * as a mask for the operation. michael@0: * michael@0: * aSource Source pattern michael@0: * aMask Mask pattern michael@0: * aOptions Drawing options michael@0: */ michael@0: virtual void Mask(const Pattern &aSource, michael@0: const Pattern &aMask, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: virtual void MaskSurface(const Pattern &aSource, michael@0: SourceSurface *aMask, michael@0: Point aOffset, michael@0: const DrawOptions &aOptions = DrawOptions()); michael@0: michael@0: /* michael@0: * Push a clip to the DrawTarget. michael@0: * michael@0: * aPath The path to clip to michael@0: */ michael@0: virtual void PushClip(const Path *aPath); michael@0: michael@0: /* michael@0: * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle michael@0: * is specified in user space. michael@0: * michael@0: * aRect The rect to clip to michael@0: */ michael@0: virtual void PushClipRect(const Rect &aRect); michael@0: michael@0: /* Pop a clip from the DrawTarget. A pop without a corresponding push will michael@0: * be ignored. michael@0: */ michael@0: virtual void PopClip(); michael@0: michael@0: /* michael@0: * Create a SourceSurface optimized for use with this DrawTarget from michael@0: * existing bitmap data in memory. michael@0: * michael@0: * The SourceSurface does not take ownership of aData, and may be freed at any time. michael@0: */ michael@0: virtual TemporaryRef CreateSourceSurfaceFromData(unsigned char *aData, michael@0: const IntSize &aSize, michael@0: int32_t aStride, michael@0: SurfaceFormat aFormat) const; michael@0: michael@0: /* michael@0: * Create a SourceSurface optimized for use with this DrawTarget from michael@0: * an arbitrary other SourceSurface. This may return aSourceSurface or some michael@0: * other existing surface. michael@0: */ michael@0: virtual TemporaryRef OptimizeSourceSurface(SourceSurface *aSurface) const; michael@0: michael@0: /* michael@0: * Create a SourceSurface for a type of NativeSurface. This may fail if the michael@0: * draw target does not know how to deal with the type of NativeSurface passed michael@0: * in. michael@0: */ michael@0: virtual TemporaryRef michael@0: CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const; michael@0: michael@0: /* michael@0: * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget. michael@0: */ michael@0: virtual TemporaryRef michael@0: CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; michael@0: michael@0: /* michael@0: * Create a path builder with the specified fillmode. michael@0: * michael@0: * We need the fill mode up front because of Direct2D. michael@0: * ID2D1SimplifiedGeometrySink requires the fill mode michael@0: * to be set before calling BeginFigure(). michael@0: */ michael@0: virtual TemporaryRef CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; michael@0: michael@0: /* michael@0: * Create a GradientStops object that holds information about a set of michael@0: * gradient stops, this object is required for linear or radial gradient michael@0: * patterns to represent the color stops in the gradient. michael@0: * michael@0: * aStops An array of gradient stops michael@0: * aNumStops Number of stops in the array aStops michael@0: * aExtendNone This describes how to extend the stop color outside of the michael@0: * gradient area. michael@0: */ michael@0: virtual TemporaryRef michael@0: CreateGradientStops(GradientStop *aStops, michael@0: uint32_t aNumStops, michael@0: ExtendMode aExtendMode = ExtendMode::CLAMP) const; michael@0: michael@0: virtual TemporaryRef CreateFilter(FilterType aType); michael@0: michael@0: /* michael@0: * Set a transform on the surface, this transform is applied at drawing time michael@0: * to both the mask and source of the operation. michael@0: */ michael@0: virtual void SetTransform(const Matrix &aTransform); michael@0: michael@0: /* Tries to get a native surface for a DrawTarget, this may fail if the michael@0: * draw target cannot convert to this surface type. michael@0: */ michael@0: virtual void *GetNativeSurface(NativeSurfaceType aType) { return mFinalDT->GetNativeSurface(aType); } michael@0: michael@0: private: michael@0: Path *GetPathForPathRecording(const Path *aPath) const; michael@0: void EnsureStored(const Path *aPath); michael@0: michael@0: RefPtr mRecorder; michael@0: RefPtr mFinalDT; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */