2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef __NS_SVGFILTERINSTANCE_H__
|
|
|
|
#define __NS_SVGFILTERINSTANCE_H__
|
|
|
|
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxRect.h"
|
2008-07-13 18:21:25 -07:00
|
|
|
#include "nsSVGFilters.h"
|
2011-07-23 01:44:52 -07:00
|
|
|
#include "nsSVGNumber2.h"
|
|
|
|
#include "nsSVGNumberPair.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "nsTArray.h"
|
2013-11-27 03:25:29 -08:00
|
|
|
#include "nsIFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-20 05:15:55 -07:00
|
|
|
class nsIFrame;
|
2014-02-05 14:04:42 -08:00
|
|
|
class nsSVGFilterFrame;
|
2008-09-10 17:24:16 -07:00
|
|
|
class nsSVGFilterPaintCallback;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-17 15:28:47 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class SVGFilterElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-13 18:21:25 -07:00
|
|
|
/**
|
2014-02-24 07:22:58 -08:00
|
|
|
* This class helps nsFilterInstance build its filter graph by processing a
|
|
|
|
* single SVG reference filter.
|
2012-04-13 06:22:06 -07:00
|
|
|
*
|
2014-02-24 07:22:58 -08:00
|
|
|
* In BuildPrimitives, this class iterates through the referenced <filter>
|
|
|
|
* element's primitive elements, creating a FilterPrimitiveDescription for
|
|
|
|
* each one.
|
2014-03-12 05:42:19 -07:00
|
|
|
*
|
|
|
|
* This class uses several different coordinate spaces, defined as follows:
|
|
|
|
*
|
|
|
|
* "user space"
|
|
|
|
* The filtered SVG element's user space or the filtered HTML element's
|
|
|
|
* CSS pixel space. The origin for an HTML element is the top left corner of
|
|
|
|
* its border box.
|
|
|
|
*
|
|
|
|
* "intermediate space"
|
|
|
|
* User space scaled to device pixels. Shares the same origin as user space.
|
|
|
|
* This space is the same across chained SVG and CSS filters. To compute the
|
|
|
|
* overall filter space for a chain, we first need to build each filter's
|
|
|
|
* FilterPrimitiveDescriptions in some common space. That space is
|
|
|
|
* intermediate space.
|
|
|
|
*
|
|
|
|
* "filter space"
|
|
|
|
* Intermediate space translated to the origin of this SVG filter's
|
|
|
|
* filter region. This space may be different for each filter in a chain.
|
|
|
|
*
|
|
|
|
* To understand the spaces better, let's take an example filter that defines a
|
|
|
|
* filter region:
|
|
|
|
* <filter id="f" x="-15" y="-15" width="130" height="130">...</filter>
|
|
|
|
*
|
|
|
|
* And apply the filter to a div element:
|
|
|
|
* <div style="filter: url(#f); ...">...</div>
|
|
|
|
*
|
|
|
|
* And let's say there are 2 device pixels for every 1 CSS pixel.
|
|
|
|
*
|
2014-03-15 14:08:04 -07:00
|
|
|
* Finally, let's define an arbitrary point in user space:
|
|
|
|
* "user space point" = (10, 10)
|
|
|
|
*
|
|
|
|
* The point will be inset 10 CSS pixels from both the top and left edges of the
|
|
|
|
* div element's border box.
|
|
|
|
*
|
|
|
|
* Now, let's transform the point from user space to intermediate space:
|
|
|
|
* "intermediate space point" = "user space point" * "device pixels per CSS pixel"
|
|
|
|
* "intermediate space point" = (10, 10) * 2
|
|
|
|
* "intermediate space point" = (20, 20)
|
|
|
|
*
|
|
|
|
* Next, let's transform the point from user space to filter space:
|
|
|
|
* "filter space point" = ("user space point" - "filter region position in user space") * "device pixels per CSS pixel"
|
|
|
|
* "filter space point" = ((10, 10) - (-15, -15)) * 2
|
|
|
|
* "filter space point" = (50, 50)
|
|
|
|
*
|
|
|
|
* Similarly, we can convert the point from intermediate space to filter space:
|
|
|
|
* "filter space point" = "intermediate space point" - "filter region position in intermediate space"
|
|
|
|
* "filter space point" = "intermediate space point" - ("filter region position in user space" * "device pixels per CSS pixel")
|
|
|
|
* "filter space point" = (20, 20) - ((-15, -15) * 2)
|
|
|
|
* "filter space point" = (50, 50)
|
2008-07-13 18:21:25 -07:00
|
|
|
*/
|
2013-04-11 20:20:45 -07:00
|
|
|
class nsSVGFilterInstance
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-11-27 03:25:29 -08:00
|
|
|
typedef mozilla::gfx::Point3D Point3D;
|
|
|
|
typedef mozilla::gfx::IntRect IntRect;
|
|
|
|
typedef mozilla::gfx::SourceSurface SourceSurface;
|
|
|
|
typedef mozilla::gfx::FilterPrimitiveDescription FilterPrimitiveDescription;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2014-02-06 10:42:35 -08:00
|
|
|
/**
|
2014-02-24 07:22:58 -08:00
|
|
|
* @param aFilter The SVG reference filter to process.
|
2012-04-13 06:22:06 -07:00
|
|
|
* @param aTargetFrame The frame of the filtered element under consideration.
|
2014-02-24 07:22:58 -08:00
|
|
|
* @param aTargetBBox The SVG bbox to use for the target frame, computed by
|
|
|
|
* the caller. The caller may decide to override the actual SVG bbox.
|
2012-04-13 06:22:06 -07:00
|
|
|
*/
|
2014-02-24 07:22:58 -08:00
|
|
|
nsSVGFilterInstance(const nsStyleFilter& aFilter,
|
|
|
|
nsIFrame *aTargetFrame,
|
|
|
|
const gfxRect& aTargetBBox);
|
2014-02-05 14:04:42 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the filter instance was created successfully.
|
|
|
|
*/
|
|
|
|
bool IsInitialized() const { return mInitialized; }
|
2008-07-13 18:21:25 -07:00
|
|
|
|
2014-02-24 07:22:58 -08:00
|
|
|
/**
|
|
|
|
* Iterates through the <filter> element's primitive elements, creating a
|
|
|
|
* FilterPrimitiveDescription for each one. Appends the new
|
|
|
|
* FilterPrimitiveDescription(s) to the aPrimitiveDescrs list. Also, appends
|
|
|
|
* new images from feImage filter primitive elements to the aInputImages list.
|
|
|
|
*/
|
|
|
|
nsresult BuildPrimitives(nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
nsTArray<mozilla::RefPtr<SourceSurface>>& aInputImages);
|
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
|
|
|
* Returns the user specified "filter region", in the filtered element's user
|
|
|
|
* space, after it has been adjusted out (if necessary) so that its edges
|
|
|
|
* coincide with pixel boundaries of the offscreen surface into which the
|
|
|
|
* filtered output would/will be painted.
|
|
|
|
*/
|
2014-03-12 05:42:19 -07:00
|
|
|
gfxRect GetFilterRegion() const { return mUserSpaceBounds; }
|
2008-07-13 18:21:25 -07:00
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
|
|
|
* Returns the size of the user specified "filter region", in filter space.
|
2013-11-27 03:25:29 -08:00
|
|
|
*/
|
2014-02-24 07:22:58 -08:00
|
|
|
nsIntRect GetFilterSpaceBounds() const { return mFilterSpaceBounds; }
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetPrimitiveNumber(uint8_t aCtxType, const nsSVGNumber2 *aNumber) const
|
2011-07-23 01:44:52 -07:00
|
|
|
{
|
|
|
|
return GetPrimitiveNumber(aCtxType, aNumber->GetAnimValue());
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetPrimitiveNumber(uint8_t aCtxType, const nsSVGNumberPair *aNumberPair,
|
2011-07-23 01:44:52 -07:00
|
|
|
nsSVGNumberPair::PairIndex aIndex) const
|
|
|
|
{
|
|
|
|
return GetPrimitiveNumber(aCtxType, aNumberPair->GetAnimValue(aIndex));
|
|
|
|
}
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2011-09-14 07:48:32 -07:00
|
|
|
/**
|
2013-11-27 03:25:29 -08:00
|
|
|
* Converts a userSpaceOnUse/objectBoundingBoxUnits unitless point
|
2012-04-13 06:22:06 -07:00
|
|
|
* into filter space, depending on the value of mPrimitiveUnits. (For
|
|
|
|
* objectBoundingBoxUnits, the bounding box offset is applied to the point.)
|
2011-09-14 07:48:32 -07:00
|
|
|
*/
|
2013-11-27 03:25:29 -08:00
|
|
|
Point3D ConvertLocation(const Point3D& aPoint) const;
|
2011-09-14 07:48:32 -07:00
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
2014-03-12 05:42:19 -07:00
|
|
|
* Transform a rect between user space and filter space.
|
2012-04-13 06:22:06 -07:00
|
|
|
*/
|
2014-03-12 05:42:19 -07:00
|
|
|
gfxRect UserSpaceToFilterSpace(const gfxRect& aUserSpaceRect) const;
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2014-02-24 07:22:58 -08:00
|
|
|
/**
|
|
|
|
* Finds the filter frame associated with this SVG filter.
|
|
|
|
*/
|
|
|
|
nsSVGFilterFrame* GetFilterFrame();
|
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
2013-11-27 03:25:29 -08:00
|
|
|
* Computes the filter primitive subregion for the given primitive.
|
2012-04-13 06:22:06 -07:00
|
|
|
*/
|
2013-11-27 03:25:29 -08:00
|
|
|
IntRect ComputeFilterPrimitiveSubregion(nsSVGFE* aFilterElement,
|
2014-02-24 07:22:58 -08:00
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
2013-11-27 03:25:29 -08:00
|
|
|
const nsTArray<int32_t>& aInputIndices);
|
2008-07-13 18:21:25 -07:00
|
|
|
|
2014-01-08 01:30:03 -08:00
|
|
|
/**
|
|
|
|
* Takes the input indices of a filter primitive and returns for each input
|
|
|
|
* whether the input's output is tainted.
|
|
|
|
*/
|
2014-02-24 07:22:58 -08:00
|
|
|
void GetInputsAreTainted(const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
const nsTArray<int32_t>& aInputIndices,
|
2014-01-08 01:30:03 -08:00
|
|
|
nsTArray<bool>& aOutInputsAreTainted);
|
|
|
|
|
2011-07-23 01:44:52 -07:00
|
|
|
/**
|
|
|
|
* Scales a numeric filter primitive length in the X, Y or "XY" directions
|
|
|
|
* into a length in filter space (no offset is applied).
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetPrimitiveNumber(uint8_t aCtxType, float aValue) const;
|
2011-07-23 01:44:52 -07:00
|
|
|
|
2014-03-12 05:42:19 -07:00
|
|
|
/**
|
|
|
|
* Transform a rect between user space and intermediate space.
|
|
|
|
*/
|
|
|
|
gfxRect UserSpaceToIntermediateSpace(const gfxRect& aUserSpaceRect) const;
|
|
|
|
gfxRect IntermediateSpaceToUserSpace(const gfxRect& aIntermediateSpaceRect) const;
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2014-02-05 14:04:42 -08:00
|
|
|
/**
|
|
|
|
* Returns the transform from frame space to the coordinate space that
|
|
|
|
* GetCanvasTM transforms to. "Frame space" is the origin of a frame, aka the
|
|
|
|
* top-left corner of its border box, aka the top left corner of its mRect.
|
|
|
|
*/
|
|
|
|
gfxMatrix GetUserSpaceToFrameSpaceInCSSPxTransform() const;
|
|
|
|
|
2014-02-28 13:40:00 -08:00
|
|
|
/**
|
|
|
|
* Finds the index in aPrimitiveDescrs of each input to aPrimitiveElement.
|
|
|
|
* For example, if aPrimitiveElement is:
|
|
|
|
* <feGaussianBlur in="another-primitive" .../>
|
|
|
|
* Then, the resulting aSourceIndices will contain the index of the
|
|
|
|
* FilterPrimitiveDescription representing "another-primitive".
|
|
|
|
*/
|
|
|
|
nsresult GetSourceIndices(nsSVGFE* aPrimitiveElement,
|
|
|
|
const nsTArray<FilterPrimitiveDescription>& aPrimitiveDescrs,
|
|
|
|
const nsDataHashtable<nsStringHashKey, int32_t>& aImageTable,
|
|
|
|
nsTArray<int32_t>& aSourceIndices);
|
|
|
|
|
2014-03-12 05:42:19 -07:00
|
|
|
/**
|
|
|
|
* Compute the scale factors between user space and intermediate space.
|
|
|
|
*/
|
|
|
|
nsresult ComputeUserSpaceToIntermediateSpaceScale();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the filter region in user space, intermediate space, and filter
|
|
|
|
* space.
|
|
|
|
*/
|
|
|
|
nsresult ComputeBounds();
|
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
2014-02-24 07:22:58 -08:00
|
|
|
* The SVG reference filter originally from the style system.
|
2012-04-13 06:22:06 -07:00
|
|
|
*/
|
2014-02-24 07:22:58 -08:00
|
|
|
const nsStyleFilter mFilter;
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2014-02-24 07:22:58 -08:00
|
|
|
/**
|
2014-02-24 07:22:58 -08:00
|
|
|
* The frame for the element that is currently being filtered.
|
2014-02-24 07:22:58 -08:00
|
|
|
*/
|
2014-02-24 07:22:58 -08:00
|
|
|
nsIFrame* mTargetFrame;
|
2014-02-05 14:04:42 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The filter element referenced by mTargetFrame's element.
|
|
|
|
*/
|
2013-02-17 15:28:47 -08:00
|
|
|
const mozilla::dom::SVGFilterElement* mFilterElement;
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2014-02-24 07:22:58 -08:00
|
|
|
/**
|
|
|
|
* The frame for the SVG filter element.
|
|
|
|
*/
|
|
|
|
nsSVGFilterFrame* mFilterFrame;
|
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
|
|
|
* The SVG bbox of the element that is being filtered, in user space.
|
|
|
|
*/
|
2009-06-11 08:21:03 -07:00
|
|
|
gfxRect mTargetBBox;
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2014-02-05 14:04:42 -08:00
|
|
|
/**
|
2014-03-12 05:42:19 -07:00
|
|
|
* The "filter region" in various spaces.
|
2014-02-05 14:04:42 -08:00
|
|
|
*/
|
2014-03-12 05:42:19 -07:00
|
|
|
gfxRect mUserSpaceBounds;
|
|
|
|
nsIntRect mIntermediateSpaceBounds;
|
2013-11-27 03:25:29 -08:00
|
|
|
nsIntRect mFilterSpaceBounds;
|
2012-04-13 06:22:06 -07:00
|
|
|
|
2014-03-12 05:42:19 -07:00
|
|
|
/**
|
|
|
|
* The scale factors between user space and intermediate space.
|
|
|
|
*/
|
|
|
|
gfxSize mUserSpaceToIntermediateSpaceScale;
|
|
|
|
gfxSize mIntermediateSpaceToUserSpaceScale;
|
|
|
|
|
2012-04-13 06:22:06 -07:00
|
|
|
/**
|
|
|
|
* The 'primitiveUnits' attribute value (objectBoundingBox or userSpaceOnUse).
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t mPrimitiveUnits;
|
2008-07-13 18:21:25 -07:00
|
|
|
|
2014-02-28 13:40:00 -08:00
|
|
|
/**
|
|
|
|
* The index of the FilterPrimitiveDescription that this SVG filter should use
|
|
|
|
* as its SourceGraphic, or the SourceGraphic keyword index if this is the
|
|
|
|
* first filter in a chain.
|
|
|
|
*/
|
|
|
|
int32_t mSourceGraphicIndex;
|
|
|
|
|
2014-02-05 14:04:42 -08:00
|
|
|
bool mInitialized;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|