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.
|
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.
|
|
|
|
*/
|
2012-06-16 13:23:48 -07:00
|
|
|
gfxRect GetFilterRegion() const { return mFilterRegion; }
|
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.
|
2014-02-28 14:48:31 -08:00
|
|
|
* The size will be {filterRes.x by filterRes.y}, whether the user specified
|
|
|
|
* the filter's filterRes attribute explicitly, or the implementation chose
|
|
|
|
* the filterRes values.
|
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
|
|
|
/**
|
|
|
|
* Returns the transform from the filtered element's user space to filter
|
|
|
|
* space. This will be a simple translation and/or scale.
|
|
|
|
*/
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix GetUserSpaceToFilterSpaceTransform() 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
|
|
|
|
2008-07-13 18:21:25 -07:00
|
|
|
gfxRect UserSpaceToFilterSpace(const gfxRect& aUserSpace) 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);
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* The "filter region", in the filtered element's user space.
|
|
|
|
*/
|
2012-06-16 13:23:48 -07:00
|
|
|
gfxRect mFilterRegion;
|
2013-11-27 03:25:29 -08:00
|
|
|
nsIntRect mFilterSpaceBounds;
|
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
|