2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-09-24 15:02:50 +00:00
|
|
|
* 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 {
|
2024-01-10 14:31:41 +00:00
|
|
|
namespace layers {
|
|
|
|
class CanvasDrawEventRecorder;
|
2024-07-15 13:31:40 +00:00
|
|
|
class RecordedTextureData;
|
2024-01-10 14:31:41 +00:00
|
|
|
struct RemoteTextureOwnerId;
|
|
|
|
} // namespace layers
|
|
|
|
|
2012-09-24 15:02:50 +00:00
|
|
|
namespace gfx {
|
|
|
|
|
Bug 1874461 - Filter spurious DrawTargetRecording::SetTransform calls. r=aosmond
This is an evolution of Andrew Osmond's original version of this patch. The main
addition here is an mOptimizeTransform setting which controls whether or not the
transform filtering will be used. If it is disabled, then transforms will be
immediately flushed upon a SetTransform call as normal, so that transform state
will always be visibly changed for any use-cases that depend on this, like
potentially blobs, screenshots, or printing. However, for the main case where
this optimization is both beneficial and safe, Canvas2D recordings, we can
now safely enable this setting allowing the optimization to take place.
Andrew's original rationale for the patch is as follows:
DrawTargetRecording::SetTransform is relatively expensive because of the
cost of recording a 3x2 matrix (25 bytes). Because drawing code is often
caching the transform on the DrawTarget to accumulate transformations
prior to drawing, because it is either trying to do calculations
relevant to the drawing beforehand, or the code is layered and each
layer is applying its own transformations, we can easily save recording
space by accumulating them locally and only flushing when there is an
actual operation that depends on the transform being set.
Differential Revision: https://phabricator.services.mozilla.com/D206573
2024-04-04 19:27:27 +00:00
|
|
|
class DrawTargetRecording final : public DrawTarget {
|
2018-11-30 10:46:48 +00:00
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override)
|
2019-05-01 08:47:10 +00:00
|
|
|
DrawTargetRecording(DrawEventRecorder* aRecorder, DrawTarget* aDT,
|
2019-07-10 13:49:08 +00:00
|
|
|
IntRect aRect, bool aHasData = false);
|
2024-01-10 14:31:41 +00:00
|
|
|
DrawTargetRecording(layers::CanvasDrawEventRecorder* aRecorder,
|
|
|
|
const layers::RemoteTextureOwnerId& aTextureOwnerId,
|
|
|
|
DrawTarget* aDT, const IntSize& aSize);
|
2016-01-05 10:08:57 +00:00
|
|
|
|
2012-09-24 15:02:50 +00:00
|
|
|
~DrawTargetRecording();
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual DrawTargetType GetType() const override {
|
|
|
|
return mFinalDT->GetType();
|
|
|
|
}
|
|
|
|
virtual BackendType GetBackendType() const override {
|
|
|
|
return BackendType::RECORDING;
|
|
|
|
}
|
2016-01-05 10:08:56 +00:00
|
|
|
virtual bool IsRecording() const override { return true; }
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2024-05-29 17:19:38 +00:00
|
|
|
virtual void Link(const char* aLocalDest, const char* aURI,
|
|
|
|
const Rect& aRect) override;
|
2021-08-04 12:52:38 +00:00
|
|
|
virtual void Destination(const char* aDestination,
|
|
|
|
const Point& aPoint) override;
|
2021-05-11 17:00:29 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
virtual already_AddRefed<SourceSurface> Snapshot() override;
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<SourceSurface> IntoLuminanceSource(
|
|
|
|
LuminanceType aLuminanceType, float aOpacity) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2016-07-01 08:58:13 +00:00
|
|
|
virtual void DetachAllSnapshots() override;
|
|
|
|
|
2019-07-10 13:49:08 +00:00
|
|
|
virtual IntSize GetSize() const override { return mRect.Size(); }
|
|
|
|
virtual IntRect GetRect() const override { return mRect; }
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2018-12-02 14:14:11 +00:00
|
|
|
virtual void Flush() override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void FlushItem(const IntRect& aBounds) override;
|
2018-03-16 23:20:26 +00:00
|
|
|
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual void DrawSurface(
|
2019-05-01 08:47:10 +00:00
|
|
|
SourceSurface* aSurface, const Rect& aDest, const Rect& aSource,
|
|
|
|
const DrawSurfaceOptions& aSurfOptions = DrawSurfaceOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2024-03-28 06:24:41 +00:00
|
|
|
virtual void DrawSurfaceDescriptor(
|
|
|
|
const layers::SurfaceDescriptor& aDesc,
|
|
|
|
const RefPtr<layers::Image>& aImageOfSurfaceDescriptor, const Rect& aDest,
|
|
|
|
const Rect& aSource,
|
|
|
|
const DrawSurfaceOptions& aSurfOptions = DrawSurfaceOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
|
2021-08-09 22:07:36 +00:00
|
|
|
virtual void DrawDependentSurface(uint64_t aId, const Rect& aDest) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void DrawFilter(FilterNode* aNode, const Rect& aSourceRect,
|
|
|
|
const Point& aDestPoint,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2013-11-27 11:25:28 +00:00
|
|
|
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void DrawSurfaceWithShadow(SourceSurface* aSurface,
|
2020-03-09 14:16:17 +00:00
|
|
|
const Point& aDest,
|
2022-04-01 19:03:29 +00:00
|
|
|
const ShadowOptions& aShadow,
|
2015-03-21 16:28:04 +00:00
|
|
|
CompositionOp aOperator) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2023-12-18 18:10:47 +00:00
|
|
|
virtual void DrawShadow(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const ShadowOptions& aShadow,
|
|
|
|
const DrawOptions& aOptions,
|
|
|
|
const StrokeOptions* aStrokeOptions) override;
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
/*
|
2012-09-24 15:02:50 +00:00
|
|
|
* Clear a rectangle on the draw target to transparent black. This will
|
|
|
|
* respect the clipping region and transform.
|
|
|
|
*
|
|
|
|
* aRect Rectangle to clear
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void ClearRect(const Rect& aRect) override;
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void CopySurface(SourceSurface* aSurface, const IntRect& aSourceRect,
|
|
|
|
const IntPoint& aDestination) override;
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void FillRect(const Rect& aRect, const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void StrokeRect(const Rect& aRect, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void StrokeLine(const Point& aStart, const Point& aEnd,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void Stroke(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void Fill(const Path* aPath, const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
|
|
|
/*
|
2024-01-17 05:02:01 +00:00
|
|
|
* Fill a series of glyphs on the draw target with a certain source pattern.
|
2012-09-24 15:02:50 +00:00
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void FillGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2024-01-17 05:02:01 +00:00
|
|
|
/**
|
|
|
|
* Stroke a series of glyphs on the draw target with a certain source pattern.
|
|
|
|
*/
|
|
|
|
virtual void StrokeGlyphs(
|
|
|
|
ScaledFont* aFont, const GlyphBuffer& aBuffer, const Pattern& aPattern,
|
|
|
|
const StrokeOptions& aStrokeOptions = StrokeOptions(),
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
|
|
|
|
2012-09-24 15:02:50 +00: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
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void Mask(const Pattern& aSource, const Pattern& aMask,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual void MaskSurface(
|
2019-05-01 08:47:10 +00:00
|
|
|
const Pattern& aSource, SourceSurface* aMask, Point aOffset,
|
|
|
|
const DrawOptions& aOptions = DrawOptions()) override;
|
2013-06-27 20:20:30 +00:00
|
|
|
|
2012-09-24 15:02:50 +00:00
|
|
|
/*
|
|
|
|
* Push a clip to the DrawTarget.
|
|
|
|
*
|
|
|
|
* aPath The path to clip to
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void PushClip(const Path* aPath) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Push an axis-aligned rectangular clip to the DrawTarget. This rectangle
|
|
|
|
* is specified in user space.
|
|
|
|
*
|
|
|
|
* aRect The rect to clip to
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void PushClipRect(const Rect& aRect) override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
|
|
|
/* Pop a clip from the DrawTarget. A pop without a corresponding push will
|
|
|
|
* be ignored.
|
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void PopClip() override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2024-09-06 15:20:15 +00:00
|
|
|
/* Remove all applied clips. */
|
|
|
|
virtual bool RemoveAllClips() override;
|
|
|
|
|
2016-01-26 10:03:07 +00: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.
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void PushLayer(bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform,
|
|
|
|
const IntRect& aBounds = IntRect(),
|
2016-01-26 10:03:07 +00:00
|
|
|
bool aCopyBackground = false) override;
|
|
|
|
|
2018-02-17 17:07:30 +00: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.a
|
|
|
|
* @param aCompositionOp The CompositionOp to use when blending the layer into
|
|
|
|
* the destination
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual void PushLayerWithBlend(
|
2019-05-01 08:47:10 +00:00
|
|
|
bool aOpaque, Float aOpacity, SourceSurface* aMask,
|
|
|
|
const Matrix& aMaskTransform, const IntRect& aBounds = IntRect(),
|
2018-11-30 10:46:48 +00:00
|
|
|
bool aCopyBackground = false,
|
|
|
|
CompositionOp aCompositionOp = CompositionOp::OP_OVER) override;
|
2018-02-17 17:07:30 +00:00
|
|
|
|
2016-01-26 10:03:07 +00:00
|
|
|
/**
|
|
|
|
* 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 15:02:50 +00:00
|
|
|
/*
|
|
|
|
* Create a SourceSurface optimized for use with this DrawTarget from
|
|
|
|
* existing bitmap data in memory.
|
|
|
|
*
|
2018-11-30 10:46:48 +00:00
|
|
|
* The SourceSurface does not take ownership of aData, and may be freed at any
|
|
|
|
* time.
|
2012-09-24 15:02:50 +00:00
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(
|
2019-05-01 08:47:10 +00:00
|
|
|
unsigned char* aData, const IntSize& aSize, int32_t aStride,
|
2018-11-30 10:46:48 +00:00
|
|
|
SurfaceFormat aFormat) const override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a SourceSurface optimized for use with this DrawTarget from
|
|
|
|
* an arbitrary other SourceSurface. This may return aSourceSurface or some
|
|
|
|
* other existing surface.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(
|
2019-05-01 08:47:10 +00:00
|
|
|
SourceSurface* aSurface) const override;
|
2012-09-24 15:02:50 +00: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.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromNativeSurface(
|
2019-05-01 08:47:10 +00:00
|
|
|
const NativeSurface& aSurface) const override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
|
|
|
/*
|
2018-11-30 10:46:48 +00:00
|
|
|
* Create a DrawTarget whose snapshot is optimized for use with this
|
|
|
|
* DrawTarget.
|
2012-09-24 15:02:50 +00:00
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<DrawTarget> CreateSimilarDrawTarget(
|
2019-05-01 08:47:10 +00:00
|
|
|
const IntSize& aSize, SurfaceFormat aFormat) const override;
|
2020-02-25 13:56:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a DrawTarget whose backing surface is optimized for use with this
|
|
|
|
* DrawTarget.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<DrawTarget> CreateSimilarDrawTargetWithBacking(
|
|
|
|
const IntSize& aSize, SurfaceFormat aFormat) const override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2019-05-01 08:47:10 +00:00
|
|
|
bool CanCreateSimilarDrawTarget(const IntSize& aSize,
|
2018-11-13 10:39:02 +00:00
|
|
|
SurfaceFormat aFormat) const override;
|
|
|
|
/**
|
2018-02-05 17:59:42 +00:00
|
|
|
* Create a similar DrawTarget whose requested size may be clipped based
|
|
|
|
* on this DrawTarget's rect transformed to the new target's space.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual RefPtr<DrawTarget> CreateClippedDrawTarget(
|
2019-06-21 09:51:00 +00:00
|
|
|
const Rect& aBounds, SurfaceFormat aFormat) override;
|
2018-02-05 17:59:42 +00:00
|
|
|
|
2019-01-27 23:36:04 +00:00
|
|
|
virtual already_AddRefed<DrawTarget> CreateSimilarDrawTargetForFilter(
|
2019-05-01 08:47:10 +00:00
|
|
|
const IntSize& aSize, SurfaceFormat aFormat, FilterNode* aFilter,
|
|
|
|
FilterNode* aSource, const Rect& aSourceRect,
|
|
|
|
const Point& aDestPoint) override;
|
2012-09-24 15:02:50 +00: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().
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<PathBuilder> CreatePathBuilder(
|
|
|
|
FillRule aFillRule = FillRule::FILL_WINDING) const override;
|
2012-09-24 15:02:50 +00: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.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<GradientStops> CreateGradientStops(
|
2019-05-01 08:47:10 +00:00
|
|
|
GradientStop* aStops, uint32_t aNumStops,
|
2018-11-30 10:46:48 +00:00
|
|
|
ExtendMode aExtendMode = ExtendMode::CLAMP) const override;
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override;
|
2013-11-27 11:25:28 +00:00
|
|
|
|
2024-01-20 01:44:41 +00:00
|
|
|
/*
|
|
|
|
* Set a transform on the surface, this transform is applied at drawing time
|
|
|
|
* to both the mask and source of the operation.
|
|
|
|
*/
|
|
|
|
virtual void SetTransform(const Matrix& aTransform) override;
|
|
|
|
|
2024-01-18 17:16:08 +00:00
|
|
|
virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override;
|
|
|
|
|
2012-09-24 15:02:50 +00:00
|
|
|
/* Tries to get a native surface for a DrawTarget, this may fail if the
|
|
|
|
* draw target cannot convert to this surface type.
|
|
|
|
*/
|
2019-05-01 08:47:10 +00:00
|
|
|
virtual void* GetNativeSurface(NativeSurfaceType aType) override {
|
2018-11-30 10:46:48 +00:00
|
|
|
return mFinalDT->GetNativeSurface(aType);
|
|
|
|
}
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2016-01-26 10:03:07 +00:00
|
|
|
virtual bool IsCurrentGroupOpaque() override {
|
|
|
|
return mFinalDT->IsCurrentGroupOpaque();
|
|
|
|
}
|
|
|
|
|
Bug 1874461 - Filter spurious DrawTargetRecording::SetTransform calls. r=aosmond
This is an evolution of Andrew Osmond's original version of this patch. The main
addition here is an mOptimizeTransform setting which controls whether or not the
transform filtering will be used. If it is disabled, then transforms will be
immediately flushed upon a SetTransform call as normal, so that transform state
will always be visibly changed for any use-cases that depend on this, like
potentially blobs, screenshots, or printing. However, for the main case where
this optimization is both beneficial and safe, Canvas2D recordings, we can
now safely enable this setting allowing the optimization to take place.
Andrew's original rationale for the patch is as follows:
DrawTargetRecording::SetTransform is relatively expensive because of the
cost of recording a 3x2 matrix (25 bytes). Because drawing code is often
caching the transform on the DrawTarget to accumulate transformations
prior to drawing, because it is either trying to do calculations
relevant to the drawing beforehand, or the code is layered and each
layer is applying its own transformations, we can easily save recording
space by accumulating them locally and only flushing when there is an
actual operation that depends on the transform being set.
Differential Revision: https://phabricator.services.mozilla.com/D206573
2024-04-04 19:27:27 +00:00
|
|
|
void SetOptimizeTransform(bool aOptimizeTransform) {
|
|
|
|
mOptimizeTransform = aOptimizeTransform;
|
|
|
|
}
|
|
|
|
|
2024-07-15 13:31:40 +00:00
|
|
|
protected:
|
|
|
|
friend class layers::RecordedTextureData;
|
|
|
|
|
|
|
|
void AttachTextureData(layers::RecordedTextureData* aTextureData) {
|
|
|
|
mTextureData = aTextureData;
|
|
|
|
}
|
|
|
|
void DetachTextureData(layers::RecordedTextureData*) {
|
|
|
|
mTextureData = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
layers::RecordedTextureData* mTextureData = nullptr;
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
private:
|
2016-11-15 11:10:02 +00:00
|
|
|
/**
|
|
|
|
* Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
|
|
|
|
*
|
|
|
|
* @param aDT DrawTargetRecording on which CreateSimilarDrawTarget was called
|
2017-06-12 21:53:21 +00:00
|
|
|
* @param aSize size of the the similar DrawTarget
|
|
|
|
* @param aFormat format of the similar DrawTarget
|
2016-11-15 11:10:02 +00:00
|
|
|
*/
|
2019-07-10 13:49:08 +00:00
|
|
|
DrawTargetRecording(const DrawTargetRecording* aDT, IntRect aRect,
|
2018-11-30 10:46:48 +00:00
|
|
|
SurfaceFormat aFormat);
|
2016-11-15 11:10:02 +00:00
|
|
|
|
Bug 1874461 - Filter spurious DrawTargetRecording::SetTransform calls. r=aosmond
This is an evolution of Andrew Osmond's original version of this patch. The main
addition here is an mOptimizeTransform setting which controls whether or not the
transform filtering will be used. If it is disabled, then transforms will be
immediately flushed upon a SetTransform call as normal, so that transform state
will always be visibly changed for any use-cases that depend on this, like
potentially blobs, screenshots, or printing. However, for the main case where
this optimization is both beneficial and safe, Canvas2D recordings, we can
now safely enable this setting allowing the optimization to take place.
Andrew's original rationale for the patch is as follows:
DrawTargetRecording::SetTransform is relatively expensive because of the
cost of recording a 3x2 matrix (25 bytes). Because drawing code is often
caching the transform on the DrawTarget to accumulate transformations
prior to drawing, because it is either trying to do calculations
relevant to the drawing beforehand, or the code is layered and each
layer is applying its own transformations, we can easily save recording
space by accumulating them locally and only flushing when there is an
actual operation that depends on the transform being set.
Differential Revision: https://phabricator.services.mozilla.com/D206573
2024-04-04 19:27:27 +00:00
|
|
|
void RecordTransform(const Matrix& aTransform) const;
|
|
|
|
|
|
|
|
void FlushTransform() const {
|
|
|
|
if (mTransformDirty) {
|
|
|
|
if (!mRecordedTransform.ExactlyEquals(mTransform)) {
|
|
|
|
RecordTransform(mTransform);
|
|
|
|
}
|
|
|
|
mTransformDirty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordEvent(const RecordedEvent& aEvent) const {
|
|
|
|
FlushTransform();
|
|
|
|
mRecorder->RecordEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordEventSelf(const RecordedEvent& aEvent) const {
|
|
|
|
FlushTransform();
|
|
|
|
mRecorder->RecordEvent(this, aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordEventSkipFlushTransform(const RecordedEvent& aEvent) const {
|
|
|
|
mRecorder->RecordEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordEventSelfSkipFlushTransform(const RecordedEvent& aEvent) const {
|
|
|
|
mRecorder->RecordEvent(this, aEvent);
|
|
|
|
}
|
|
|
|
|
2019-05-01 08:47:10 +00:00
|
|
|
Path* GetPathForPathRecording(const Path* aPath) const;
|
|
|
|
already_AddRefed<PathRecording> EnsurePathStored(const Path* aPath);
|
|
|
|
void EnsurePatternDependenciesStored(const Pattern& aPattern);
|
2012-09-24 15:02:50 +00:00
|
|
|
|
2024-01-17 05:02:01 +00:00
|
|
|
void DrawGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
|
|
|
|
const Pattern& aPattern,
|
|
|
|
const DrawOptions& aOptions = DrawOptions(),
|
|
|
|
const StrokeOptions* aStrokeOptions = nullptr);
|
|
|
|
|
2024-02-08 23:46:59 +00:00
|
|
|
void MarkChanged();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawEventRecorderPrivate> mRecorder;
|
|
|
|
RefPtr<DrawTarget> mFinalDT;
|
2019-07-10 13:49:08 +00:00
|
|
|
IntRect mRect;
|
2024-01-18 17:16:08 +00:00
|
|
|
|
|
|
|
struct PushedLayer {
|
|
|
|
explicit PushedLayer(bool aOldPermitSubpixelAA)
|
|
|
|
: mOldPermitSubpixelAA(aOldPermitSubpixelAA) {}
|
|
|
|
bool mOldPermitSubpixelAA;
|
|
|
|
};
|
|
|
|
std::vector<PushedLayer> mPushedLayers;
|
2024-02-08 23:46:59 +00:00
|
|
|
|
Bug 1874461 - Filter spurious DrawTargetRecording::SetTransform calls. r=aosmond
This is an evolution of Andrew Osmond's original version of this patch. The main
addition here is an mOptimizeTransform setting which controls whether or not the
transform filtering will be used. If it is disabled, then transforms will be
immediately flushed upon a SetTransform call as normal, so that transform state
will always be visibly changed for any use-cases that depend on this, like
potentially blobs, screenshots, or printing. However, for the main case where
this optimization is both beneficial and safe, Canvas2D recordings, we can
now safely enable this setting allowing the optimization to take place.
Andrew's original rationale for the patch is as follows:
DrawTargetRecording::SetTransform is relatively expensive because of the
cost of recording a 3x2 matrix (25 bytes). Because drawing code is often
caching the transform on the DrawTarget to accumulate transformations
prior to drawing, because it is either trying to do calculations
relevant to the drawing beforehand, or the code is layered and each
layer is applying its own transformations, we can easily save recording
space by accumulating them locally and only flushing when there is an
actual operation that depends on the transform being set.
Differential Revision: https://phabricator.services.mozilla.com/D206573
2024-04-04 19:27:27 +00:00
|
|
|
bool mOptimizeTransform = false;
|
|
|
|
|
|
|
|
// Last transform that was used in the recording.
|
|
|
|
mutable Matrix mRecordedTransform;
|
2012-09-24 15:02:50 +00:00
|
|
|
};
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-09-24 15:02:50 +00:00
|
|
|
|
|
|
|
#endif /* MOZILLA_GFX_DRAWTARGETRECORDING_H_ */
|