2012-09-24 19:02:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2016-01-05 13:08:56 +03:00
|
|
|
* vim: set ts=8 sts=2 et sw=2 tw=80:
|
2012-09-24 19:02:50 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_DRAWTARGETRECORDING_H_
|
|
|
|
#define MOZILLA_GFX_DRAWTARGETRECORDING_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include "DrawEventRecorder.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class DrawTargetRecording : public DrawTarget
|
|
|
|
{
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override)
|
2017-06-13 00:53:21 +03:00
|
|
|
DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, IntSize aSize, bool aHasData = false);
|
2016-01-05 13:08:57 +03:00
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
~DrawTargetRecording();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); }
|
2017-06-13 00:53:21 +03:00
|
|
|
virtual BackendType GetBackendType() const override { return BackendType::RECORDING; }
|
2016-01-05 13:08:56 +03:00
|
|
|
virtual bool IsRecording() const override { return true; }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> Snapshot() override;
|
2017-06-12 17:21:16 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> IntoLuminanceSource(LuminanceType aLuminanceType, float aOpacity) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2016-07-01 11:58:13 +03:00
|
|
|
virtual void DetachAllSnapshots() override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual IntSize GetSize() override { return mFinalDT->GetSize(); }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/* Ensure that the DrawTarget backend has flushed all drawing operations to
|
|
|
|
* this draw target. This must be called before using the backing surface of
|
|
|
|
* this draw target outside of GFX 2D code.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Flush() override { mFinalDT->Flush(); }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Draw a surface to the draw target. Possibly doing partial drawing or
|
|
|
|
* applying scaling. No sampling happens outside the source.
|
|
|
|
*
|
|
|
|
* aSurface Source surface to draw
|
|
|
|
* aDest Destination rectangle that this drawing operation should draw to
|
|
|
|
* aSource Source rectangle in aSurface coordinates, this area of aSurface
|
|
|
|
* will be stretched to the size of aDest.
|
|
|
|
* aOptions General draw options that are applied to the operation
|
|
|
|
* aSurfOptions DrawSurface options that are applied
|
|
|
|
*/
|
|
|
|
virtual void DrawSurface(SourceSurface *aSurface,
|
|
|
|
const Rect &aDest,
|
|
|
|
const Rect &aSource,
|
|
|
|
const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2013-11-27 15:25:28 +04:00
|
|
|
virtual void DrawFilter(FilterNode *aNode,
|
|
|
|
const Rect &aSourceRect,
|
|
|
|
const Point &aDestPoint,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2013-11-27 15:25:28 +04:00
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
/*
|
|
|
|
* Blend a surface to the draw target with a shadow. The shadow is drawn as a
|
|
|
|
* gaussian blur using a specified sigma. The shadow is clipped to the size
|
|
|
|
* of the input surface, so the input surface should contain a transparent
|
|
|
|
* border the size of the approximate coverage of the blur (3 * aSigma).
|
|
|
|
* NOTE: This function works in device space!
|
|
|
|
*
|
|
|
|
* aSurface Source surface to draw.
|
|
|
|
* aDest Destination point that this drawing operation should draw to.
|
|
|
|
* aColor Color of the drawn shadow
|
|
|
|
* aOffset Offset of the shadow
|
|
|
|
* aSigma Sigma used for the guassian filter kernel
|
|
|
|
* aOperator Composition operator used
|
|
|
|
*/
|
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
|
|
|
|
const Point &aDest,
|
|
|
|
const Color &aColor,
|
|
|
|
const Point &aOffset,
|
|
|
|
Float aSigma,
|
2015-03-21 19:28:04 +03:00
|
|
|
CompositionOp aOperator) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear a rectangle on the draw target to transparent black. This will
|
|
|
|
* respect the clipping region and transform.
|
|
|
|
*
|
|
|
|
* aRect Rectangle to clear
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ClearRect(const Rect &aRect) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is essentially a 'memcpy' between two surfaces. It moves a pixel
|
|
|
|
* aligned area from the source surface unscaled directly onto the
|
|
|
|
* drawtarget. This ignores both transform and clip.
|
|
|
|
*
|
|
|
|
* aSurface Surface to copy from
|
|
|
|
* aSourceRect Source rectangle to be copied
|
|
|
|
* aDest Destination point to copy the surface to
|
|
|
|
*/
|
|
|
|
virtual void CopySurface(SourceSurface *aSurface,
|
|
|
|
const IntRect &aSourceRect,
|
2015-03-21 19:28:04 +03:00
|
|
|
const IntPoint &aDestination) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill a rectangle on the DrawTarget with a certain source pattern.
|
|
|
|
*
|
|
|
|
* aRect Rectangle that forms the mask of this filling operation
|
|
|
|
* aPattern Pattern that forms the source of this filling operation
|
|
|
|
* aOptions Options that are applied to this operation
|
|
|
|
*/
|
|
|
|
virtual void FillRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stroke a rectangle on the DrawTarget with a certain source pattern.
|
|
|
|
*
|
|
|
|
* aRect Rectangle that forms the mask of this stroking operation
|
|
|
|
* aPattern Pattern that forms the source of this stroking operation
|
|
|
|
* aOptions Options that are applied to this operation
|
|
|
|
*/
|
|
|
|
virtual void StrokeRect(const Rect &aRect,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stroke a line on the DrawTarget with a certain source pattern.
|
|
|
|
*
|
|
|
|
* aStart Starting point of the line
|
|
|
|
* aEnd End point of the line
|
|
|
|
* aPattern Pattern that forms the source of this stroking operation
|
|
|
|
* aOptions Options that are applied to this operation
|
|
|
|
*/
|
|
|
|
virtual void StrokeLine(const Point &aStart,
|
|
|
|
const Point &aEnd,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stroke a path on the draw target with a certain source pattern.
|
|
|
|
*
|
|
|
|
* aPath Path that is to be stroked
|
|
|
|
* aPattern Pattern that should be used for the stroke
|
|
|
|
* aStrokeOptions Stroke options used for this operation
|
|
|
|
* aOptions Draw options used for this operation
|
|
|
|
*/
|
|
|
|
virtual void Stroke(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const StrokeOptions &aStrokeOptions = StrokeOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill a path on the draw target with a certain source pattern.
|
|
|
|
*
|
|
|
|
* aPath Path that is to be filled
|
|
|
|
* aPattern Pattern that should be used for the fill
|
|
|
|
* aOptions Draw options used for this operation
|
|
|
|
*/
|
|
|
|
virtual void Fill(const Path *aPath,
|
|
|
|
const Pattern &aPattern,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill a series of clyphs on the draw target with a certain source pattern.
|
|
|
|
*/
|
|
|
|
virtual void FillGlyphs(ScaledFont *aFont,
|
|
|
|
const GlyphBuffer &aBuffer,
|
|
|
|
const Pattern &aPattern,
|
|
|
|
const DrawOptions &aOptions = DrawOptions(),
|
2015-03-21 19:28:04 +03:00
|
|
|
const GlyphRenderingOptions *aRenderingOptions = nullptr) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This takes a source pattern and a mask, and composites the source pattern
|
|
|
|
* onto the destination surface using the alpha channel of the mask pattern
|
|
|
|
* as a mask for the operation.
|
|
|
|
*
|
|
|
|
* aSource Source pattern
|
|
|
|
* aMask Mask pattern
|
|
|
|
* aOptions Drawing options
|
|
|
|
*/
|
|
|
|
virtual void Mask(const Pattern &aSource,
|
|
|
|
const Pattern &aMask,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2013-06-28 00:20:30 +04:00
|
|
|
virtual void MaskSurface(const Pattern &aSource,
|
|
|
|
SourceSurface *aMask,
|
|
|
|
Point aOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
const DrawOptions &aOptions = DrawOptions()) override;
|
2013-06-28 00:20:30 +04:00
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
/*
|
|
|
|
* Push a clip to the DrawTarget.
|
|
|
|
*
|
|
|
|
* aPath The path to clip to
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PushClip(const Path *aPath) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
|
|
|
|
* is specified in user space.
|
|
|
|
*
|
|
|
|
* aRect The rect to clip to
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PushClipRect(const Rect &aRect) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/* Pop a clip from the DrawTarget. A pop without a corresponding push will
|
|
|
|
* be ignored.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void PopClip() override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2016-01-26 13:03:07 +03:00
|
|
|
/**
|
|
|
|
* Push a 'layer' to the DrawTarget, a layer is a temporary surface that all
|
|
|
|
* drawing will be redirected to, this is used for example to support group
|
|
|
|
* opacity or the masking of groups. Clips must be balanced within a layer,
|
|
|
|
* i.e. between a matching PushLayer/PopLayer pair there must be as many
|
|
|
|
* PushClip(Rect) calls as there are PopClip calls.
|
|
|
|
*
|
|
|
|
* @param aOpaque Whether the layer will be opaque
|
|
|
|
* @param aOpacity Opacity of the layer
|
|
|
|
* @param aMask Mask applied to the layer
|
|
|
|
* @param aMaskTransform Transform applied to the layer mask
|
|
|
|
* @param aBounds Optional bounds in device space to which the layer is
|
|
|
|
* limited in size.
|
|
|
|
* @param aCopyBackground Whether to copy the background into the layer, this
|
|
|
|
* is only supported when aOpaque is true.
|
|
|
|
*/
|
|
|
|
virtual void PushLayer(bool aOpaque, Float aOpacity,
|
|
|
|
SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds = IntRect(),
|
|
|
|
bool aCopyBackground = false) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This balances a call to PushLayer and proceeds to blend the layer back
|
|
|
|
* onto the background. This blend will blend the temporary surface back
|
|
|
|
* onto the target in device space using POINT sampling and operator over.
|
|
|
|
*/
|
|
|
|
virtual void PopLayer() override;
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
/*
|
|
|
|
* Create a SourceSurface optimized for use with this DrawTarget from
|
|
|
|
* existing bitmap data in memory.
|
|
|
|
*
|
|
|
|
* The SourceSurface does not take ownership of aData, and may be freed at any time.
|
|
|
|
*/
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
|
2012-09-24 19:02:50 +04:00
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
2015-03-21 19:28:04 +03:00
|
|
|
SurfaceFormat aFormat) const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a SourceSurface optimized for use with this DrawTarget from
|
|
|
|
* an arbitrary other SourceSurface. This may return aSourceSurface or some
|
|
|
|
* other existing surface.
|
|
|
|
*/
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a SourceSurface for a type of NativeSurface. This may fail if the
|
|
|
|
* draw target does not know how to deal with the type of NativeSurface passed
|
|
|
|
* in.
|
|
|
|
*/
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<SourceSurface>
|
2015-03-21 19:28:04 +03:00
|
|
|
CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a DrawTarget whose snapshot is optimized for use with this DrawTarget.
|
|
|
|
*/
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<DrawTarget>
|
2015-03-21 19:28:04 +03:00
|
|
|
CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a path builder with the specified fillmode.
|
|
|
|
*
|
|
|
|
* We need the fill mode up front because of Direct2D.
|
|
|
|
* ID2D1SimplifiedGeometrySink requires the fill mode
|
|
|
|
* to be set before calling BeginFigure().
|
|
|
|
*/
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a GradientStops object that holds information about a set of
|
|
|
|
* gradient stops, this object is required for linear or radial gradient
|
|
|
|
* patterns to represent the color stops in the gradient.
|
|
|
|
*
|
|
|
|
* aStops An array of gradient stops
|
|
|
|
* aNumStops Number of stops in the array aStops
|
|
|
|
* aExtendNone This describes how to extend the stop color outside of the
|
|
|
|
* gradient area.
|
|
|
|
*/
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<GradientStops>
|
2012-09-24 19:02:50 +04:00
|
|
|
CreateGradientStops(GradientStop *aStops,
|
|
|
|
uint32_t aNumStops,
|
2015-03-21 19:28:04 +03:00
|
|
|
ExtendMode aExtendMode = ExtendMode::CLAMP) const override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override;
|
2013-11-27 15:25:28 +04:00
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
/*
|
|
|
|
* Set a transform on the surface, this transform is applied at drawing time
|
|
|
|
* to both the mask and source of the operation.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetTransform(const Matrix &aTransform) override;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
/* Tries to get a native surface for a DrawTarget, this may fail if the
|
|
|
|
* draw target cannot convert to this surface type.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void *GetNativeSurface(NativeSurfaceType aType) override { return mFinalDT->GetNativeSurface(aType); }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2016-01-26 13:03:07 +03:00
|
|
|
virtual bool IsCurrentGroupOpaque() override {
|
|
|
|
return mFinalDT->IsCurrentGroupOpaque();
|
|
|
|
}
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
private:
|
2016-11-15 14:10:02 +03:00
|
|
|
/**
|
|
|
|
* Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
|
|
|
|
*
|
|
|
|
* @param aDT DrawTargetRecording on which CreateSimilarDrawTarget was called
|
2017-06-13 00:53:21 +03:00
|
|
|
* @param aSize size of the the similar DrawTarget
|
|
|
|
* @param aFormat format of the similar DrawTarget
|
2016-11-15 14:10:02 +03:00
|
|
|
*/
|
|
|
|
DrawTargetRecording(const DrawTargetRecording *aDT,
|
2017-06-13 00:53:21 +03:00
|
|
|
IntSize aSize, SurfaceFormat aFormat);
|
2016-11-15 14:10:02 +03:00
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
Path *GetPathForPathRecording(const Path *aPath) const;
|
2016-01-05 13:08:56 +03:00
|
|
|
already_AddRefed<PathRecording> EnsurePathStored(const Path *aPath);
|
|
|
|
void EnsurePatternDependenciesStored(const Pattern &aPattern);
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawEventRecorderPrivate> mRecorder;
|
|
|
|
RefPtr<DrawTarget> mFinalDT;
|
2017-06-13 00:53:21 +03:00
|
|
|
IntSize mSize;
|
2012-09-24 19:02:50 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */
|