Bug 847120: Convert SVGFEGaussianBlurElement to WebIDL r=Ms2ger

This commit is contained in:
David Zbarsky 2013-03-19 13:43:31 -04:00
parent 12dbdb3cb0
commit a63c50b8f7
9 changed files with 119 additions and 96 deletions

View File

@ -4,18 +4,27 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/SVGFEGaussianBlurElement.h"
#include "mozilla/dom/SVGFEGaussianBlurElementBinding.h"
#include "nsSVGFilterInstance.h"
#include "nsSVGUtils.h"
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEGaussianBlur)
namespace mozilla {
namespace dom {
nsSVGElement::NumberPairInfo nsSVGFEGaussianBlurElement::sNumberPairInfo[1] =
JSObject*
SVGFEGaussianBlurElement::WrapNode(JSContext* aCx, JSObject* aScope)
{
return SVGFEGaussianBlurElementBinding::Wrap(aCx, aScope, this);
}
nsSVGElement::NumberPairInfo SVGFEGaussianBlurElement::sNumberPairInfo[1] =
{
{ &nsGkAtoms::stdDeviation, 0, 0 }
};
nsSVGElement::StringInfo nsSVGFEGaussianBlurElement::sStringInfo[2] =
nsSVGElement::StringInfo SVGFEGaussianBlurElement::sStringInfo[2] =
{
{ &nsGkAtoms::result, kNameSpaceID_None, true },
{ &nsGkAtoms::in, kNameSpaceID_None, true }
@ -24,53 +33,45 @@ nsSVGElement::StringInfo nsSVGFEGaussianBlurElement::sStringInfo[2] =
//----------------------------------------------------------------------
// nsISupports methods
NS_IMPL_ADDREF_INHERITED(nsSVGFEGaussianBlurElement,nsSVGFEGaussianBlurElementBase)
NS_IMPL_RELEASE_INHERITED(nsSVGFEGaussianBlurElement,nsSVGFEGaussianBlurElementBase)
NS_IMPL_ADDREF_INHERITED(SVGFEGaussianBlurElement,SVGFEGaussianBlurElementBase)
NS_IMPL_RELEASE_INHERITED(SVGFEGaussianBlurElement,SVGFEGaussianBlurElementBase)
DOMCI_NODE_DATA(SVGFEGaussianBlurElement, nsSVGFEGaussianBlurElement)
NS_INTERFACE_TABLE_HEAD(nsSVGFEGaussianBlurElement)
NS_NODE_INTERFACE_TABLE5(nsSVGFEGaussianBlurElement, nsIDOMNode,
nsIDOMElement, nsIDOMSVGElement,
nsIDOMSVGFilterPrimitiveStandardAttributes,
nsIDOMSVGFEGaussianBlurElement)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGFEGaussianBlurElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGFEGaussianBlurElementBase)
NS_INTERFACE_TABLE_HEAD(SVGFEGaussianBlurElement)
NS_NODE_INTERFACE_TABLE3(SVGFEGaussianBlurElement, nsIDOMNode,
nsIDOMElement, nsIDOMSVGElement)
NS_INTERFACE_MAP_END_INHERITING(SVGFEGaussianBlurElementBase)
//----------------------------------------------------------------------
// nsIDOMNode methods
NS_IMPL_ELEMENT_CLONE_WITH_INIT(nsSVGFEGaussianBlurElement)
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEGaussianBlurElement)
//----------------------------------------------------------------------
// nsIDOMSVGFEGaussianBlurElement methods
/* readonly attribute nsIDOMSVGAnimatedString in1; */
NS_IMETHODIMP nsSVGFEGaussianBlurElement::GetIn1(nsIDOMSVGAnimatedString * *aIn)
already_AddRefed<nsIDOMSVGAnimatedString>
SVGFEGaussianBlurElement::In1()
{
return mStringAttributes[IN1].ToDOMAnimatedString(aIn, this);
return mStringAttributes[IN1].ToDOMAnimatedString(this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber stdDeviationX; */
NS_IMETHODIMP nsSVGFEGaussianBlurElement::GetStdDeviationX(nsIDOMSVGAnimatedNumber * *aX)
already_AddRefed<nsIDOMSVGAnimatedNumber>
SVGFEGaussianBlurElement::StdDeviationX()
{
return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(aX, nsSVGNumberPair::eFirst, this);
return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(nsSVGNumberPair::eFirst, this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber stdDeviationY; */
NS_IMETHODIMP nsSVGFEGaussianBlurElement::GetStdDeviationY(nsIDOMSVGAnimatedNumber * *aY)
already_AddRefed<nsIDOMSVGAnimatedNumber>
SVGFEGaussianBlurElement::StdDeviationY()
{
return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(aY, nsSVGNumberPair::eSecond, this);
return mNumberPairAttributes[STD_DEV].ToDOMAnimatedNumber(nsSVGNumberPair::eSecond, this);
}
NS_IMETHODIMP
nsSVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviationY)
void
SVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviationY)
{
NS_ENSURE_FINITE2(stdDeviationX, stdDeviationY, NS_ERROR_ILLEGAL_VALUE);
mNumberPairAttributes[STD_DEV].SetBaseValues(stdDeviationX, stdDeviationY, this);
return NS_OK;
}
/**
@ -82,7 +83,7 @@ nsSVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviat
* division, 32-bit multiply). Dividing by 2^24 is a simple shift so it's
* fast. The main problem is choosing a value for K; this function returns
* K's value.
*
*
* If the result is correct for the extrema, V=0 and V=255*N, then we'll
* be in good shape since both the original function and our approximation
* are linear. V=0 always gives 0 in both cases, no problem there.
@ -90,7 +91,7 @@ nsSVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviat
* and ensure that it gives the right answer. The constraints are
* (1) 255*N*K < 2^32
* and (2) 255*N*K >= 255*(2^24)
*
*
* From (1) we find the best value of K is floor((2^32 - 1)/(255*N)).
* (2) tells us when this will be valid:
* N*floor((2^32 - 1)/(255*N)) >= 2^24
@ -98,11 +99,11 @@ nsSVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviat
* N*((2^32 - 1)/(255*N) - 1) >= 2^24
* (2^32 - 1)/255 - 2^24 >= N
* N <= 65793
*
*
* If all that math confuses you, this should convince you:
* > perl -e 'for($N=1;(255*$N*int(0xFFFFFFFF/(255*$N)))>>24==255;++$N){}print"$N\n"'
* 66052
*
*
* So this is fine for all reasonable values of N. For larger values of N
* we may as well just use the same approximation and accept the fact that
* the output channel values will be a little low.
@ -111,7 +112,7 @@ static uint32_t ComputeScaledDivisor(uint32_t aDivisor)
{
return UINT32_MAX/(255*aDivisor);
}
static void
BoxBlur(const uint8_t *aInput, uint8_t *aOutput,
int32_t aStrideMinor, int32_t aStartMinor, int32_t aEndMinor,
@ -211,8 +212,8 @@ GetBlurBoxSize(double aStdDev)
}
nsresult
nsSVGFEGaussianBlurElement::GetDXY(uint32_t *aDX, uint32_t *aDY,
const nsSVGFilterInstance& aInstance)
SVGFEGaussianBlurElement::GetDXY(uint32_t *aDX, uint32_t *aDY,
const nsSVGFilterInstance& aInstance)
{
float stdX = aInstance.GetPrimitiveNumber(SVGContentUtils::X,
&mNumberPairAttributes[STD_DEV],
@ -240,10 +241,10 @@ AreAllColorChannelsZero(const nsSVGFE::Image* aTarget)
}
void
nsSVGFEGaussianBlurElement::GaussianBlur(const Image *aSource,
const Image *aTarget,
const nsIntRect& aDataRect,
uint32_t aDX, uint32_t aDY)
SVGFEGaussianBlurElement::GaussianBlur(const Image* aSource,
const Image* aTarget,
const nsIntRect& aDataRect,
uint32_t aDX, uint32_t aDY)
{
NS_ASSERTION(nsIntRect(0, 0, aTarget->mImage->Width(), aTarget->mImage->Height()).Contains(aDataRect),
"aDataRect out of bounds");
@ -254,7 +255,7 @@ nsSVGFEGaussianBlurElement::GaussianBlur(const Image *aSource,
memset(tmp, 0, aTarget->mImage->GetDataSize());
bool alphaOnly = AreAllColorChannelsZero(aTarget);
const uint8_t* sourceData = aSource->mImage->Data();
uint8_t* targetData = aTarget->mImage->Data();
uint32_t stride = aTarget->mImage->Stride();
@ -338,10 +339,10 @@ ClipComputationRectToSurface(nsSVGFilterInstance* aInstance,
}
nsresult
nsSVGFEGaussianBlurElement::Filter(nsSVGFilterInstance* aInstance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& rect)
SVGFEGaussianBlurElement::Filter(nsSVGFilterInstance* aInstance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
const nsIntRect& rect)
{
uint32_t dx, dy;
nsresult rv = GetDXY(&dx, &dy, *aInstance);
@ -357,24 +358,24 @@ nsSVGFEGaussianBlurElement::Filter(nsSVGFilterInstance* aInstance,
}
bool
nsSVGFEGaussianBlurElement::AttributeAffectsRendering(int32_t aNameSpaceID,
nsIAtom* aAttribute) const
SVGFEGaussianBlurElement::AttributeAffectsRendering(int32_t aNameSpaceID,
nsIAtom* aAttribute) const
{
return nsSVGFEGaussianBlurElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
return SVGFEGaussianBlurElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) ||
(aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::in ||
aAttribute == nsGkAtoms::stdDeviation));
}
void
nsSVGFEGaussianBlurElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
SVGFEGaussianBlurElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources)
{
aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this));
}
nsIntRect
nsSVGFEGaussianBlurElement::InflateRectForBlur(const nsIntRect& aRect,
const nsSVGFilterInstance& aInstance)
SVGFEGaussianBlurElement::InflateRectForBlur(const nsIntRect& aRect,
const nsSVGFilterInstance& aInstance)
{
uint32_t dX, dY;
nsresult rv = GetDXY(&dX, &dY, aInstance);
@ -386,22 +387,22 @@ nsSVGFEGaussianBlurElement::InflateRectForBlur(const nsIntRect& aRect,
}
nsIntRect
nsSVGFEGaussianBlurElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
SVGFEGaussianBlurElement::ComputeTargetBBox(const nsTArray<nsIntRect>& aSourceBBoxes,
const nsSVGFilterInstance& aInstance)
{
return InflateRectForBlur(aSourceBBoxes[0], aInstance);
}
void
nsSVGFEGaussianBlurElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
SVGFEGaussianBlurElement::ComputeNeededSourceBBoxes(const nsIntRect& aTargetBBox,
nsTArray<nsIntRect>& aSourceBBoxes, const nsSVGFilterInstance& aInstance)
{
aSourceBBoxes[0] = InflateRectForBlur(aTargetBBox, aInstance);
}
nsIntRect
nsSVGFEGaussianBlurElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance)
SVGFEGaussianBlurElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance)
{
return InflateRectForBlur(aSourceChangeBoxes[0], aInstance);
}
@ -410,14 +411,14 @@ nsSVGFEGaussianBlurElement::ComputeChangeBBox(const nsTArray<nsIntRect>& aSource
// nsSVGElement methods
nsSVGElement::NumberPairAttributesInfo
nsSVGFEGaussianBlurElement::GetNumberPairInfo()
SVGFEGaussianBlurElement::GetNumberPairInfo()
{
return NumberPairAttributesInfo(mNumberPairAttributes, sNumberPairInfo,
ArrayLength(sNumberPairInfo));
}
nsSVGElement::StringAttributesInfo
nsSVGFEGaussianBlurElement::GetStringInfo()
SVGFEGaussianBlurElement::GetStringInfo()
{
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));

View File

@ -7,28 +7,34 @@
#define mozilla_dom_SVGFEGaussianBlurElement_h
#include "nsSVGFilters.h"
#include "nsSVGNumberPair.h"
#include "nsSVGString.h"
nsresult NS_NewSVGFEGaussianBlurElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
namespace mozilla {
namespace dom {
typedef nsSVGFE nsSVGFEGaussianBlurElementBase;
typedef nsSVGFE SVGFEGaussianBlurElementBase;
class nsSVGFEGaussianBlurElement : public nsSVGFEGaussianBlurElementBase,
public nsIDOMSVGFEGaussianBlurElement
class SVGFEGaussianBlurElement : public SVGFEGaussianBlurElementBase,
public nsIDOMSVGElement
{
friend nsresult NS_NewSVGFEGaussianBlurElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo);
friend nsresult (::NS_NewSVGFEGaussianBlurElement(nsIContent **aResult,
already_AddRefed<nsINodeInfo> aNodeInfo));
protected:
nsSVGFEGaussianBlurElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsSVGFEGaussianBlurElementBase(aNodeInfo) {}
SVGFEGaussianBlurElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: SVGFEGaussianBlurElementBase(aNodeInfo)
{
SetIsDOMBinding();
}
virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope) MOZ_OVERRIDE;
public:
// interfaces:
NS_DECL_ISUPPORTS_INHERITED
// FE Base
NS_FORWARD_NSIDOMSVGFILTERPRIMITIVESTANDARDATTRIBUTES(nsSVGFEGaussianBlurElementBase::)
virtual nsresult Filter(nsSVGFilterInstance* aInstance,
const nsTArray<const Image*>& aSources,
const Image* aTarget,
@ -44,19 +50,21 @@ public:
virtual nsIntRect ComputeChangeBBox(const nsTArray<nsIntRect>& aSourceChangeBoxes,
const nsSVGFilterInstance& aInstance);
// Gaussian
NS_DECL_NSIDOMSVGFEGAUSSIANBLURELEMENT
NS_FORWARD_NSIDOMSVGELEMENT(nsSVGFEGaussianBlurElementBase::)
NS_FORWARD_NSIDOMSVGELEMENT(SVGFEGaussianBlurElementBase::)
NS_FORWARD_NSIDOMNODE_TO_NSINODE
NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsXPCClassInfo* GetClassInfo();
virtual nsIDOMNode* AsDOMNode() { return this; }
// WebIDL
already_AddRefed<nsIDOMSVGAnimatedString> In1();
already_AddRefed<nsIDOMSVGAnimatedNumber> StdDeviationX();
already_AddRefed<nsIDOMSVGAnimatedNumber> StdDeviationY();
void SetStdDeviation(float stdDeviationX, float stdDeviationY);
protected:
virtual NumberPairAttributesInfo GetNumberPairInfo();
virtual StringAttributesInfo GetStringInfo();

View File

@ -167,9 +167,17 @@ nsSVGNumberPair::SetAnimValue(const float aValue[2], nsSVGElement *aSVGElement)
}
nsresult
nsSVGNumberPair::ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber **aResult,
nsSVGNumberPair::ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber** aResult,
PairIndex aIndex,
nsSVGElement *aSVGElement)
nsSVGElement* aSVGElement)
{
*aResult = ToDOMAnimatedNumber(aIndex, aSVGElement).get();
return NS_OK;
}
already_AddRefed<nsIDOMSVGAnimatedNumber>
nsSVGNumberPair::ToDOMAnimatedNumber(PairIndex aIndex,
nsSVGElement* aSVGElement)
{
nsRefPtr<DOMAnimatedNumber> domAnimatedNumber =
aIndex == eFirst ? sSVGFirstAnimatedNumberTearoffTable.GetTearoff(this) :
@ -183,8 +191,7 @@ nsSVGNumberPair::ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber **aResult,
}
}
domAnimatedNumber.forget(aResult);
return NS_OK;
return domAnimatedNumber.forget();
}
nsSVGNumberPair::DOMAnimatedNumber::~DOMAnimatedNumber()

View File

@ -60,9 +60,12 @@ public:
bool IsExplicitlySet() const
{ return mIsAnimated || mIsBaseSet; }
nsresult ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber **aResult,
nsresult ToDOMAnimatedNumber(nsIDOMSVGAnimatedNumber** aResult,
PairIndex aIndex,
nsSVGElement* aSVGElement);
already_AddRefed<nsIDOMSVGAnimatedNumber>
ToDOMAnimatedNumber(PairIndex aIndex,
nsSVGElement* aSVGElement);
// Returns a new nsISMILAttr object that the caller must delete
nsISMILAttr* ToSMILAttr(nsSVGElement* aSVGElement);

View File

@ -815,8 +815,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFEDisplacementMapElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFEGaussianBlurElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFEMorphologyElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGFEOffsetElement, nsElementSH,
@ -2249,12 +2247,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGFEGaussianBlurElement, nsIDOMSVGFEGaussianBlurElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFEGaussianBlurElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFilterPrimitiveStandardAttributes)
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGFEMorphologyElement, nsIDOMSVGFEMorphologyElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFEMorphologyElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGFilterPrimitiveStandardAttributes)

View File

@ -125,7 +125,6 @@ DOMCI_CLASS(TimeEvent)
DOMCI_CLASS(SVGFEConvolveMatrixElement)
DOMCI_CLASS(SVGFEDiffuseLightingElement)
DOMCI_CLASS(SVGFEDisplacementMapElement)
DOMCI_CLASS(SVGFEGaussianBlurElement)
DOMCI_CLASS(SVGFEMorphologyElement)
DOMCI_CLASS(SVGFEOffsetElement)
DOMCI_CLASS(SVGFESpecularLightingElement)

View File

@ -21,16 +21,6 @@ interface nsIDOMSVGFilterPrimitiveStandardAttributes : nsIDOMSVGElement
readonly attribute nsIDOMSVGAnimatedString result;
};
[scriptable, uuid(08f2d7e5-b79f-405c-8140-7faa72c53ead)]
interface nsIDOMSVGFEGaussianBlurElement : nsIDOMSVGFilterPrimitiveStandardAttributes
{
readonly attribute nsIDOMSVGAnimatedString in1;
readonly attribute nsIDOMSVGAnimatedNumber stdDeviationX;
readonly attribute nsIDOMSVGAnimatedNumber stdDeviationY;
void setStdDeviation ( in float stdDeviationX, in float stdDeviationY );
};
[scriptable, uuid(4fa9fbbe-482c-418a-afd1-d51b003f5a04)]
interface nsIDOMSVGFEOffsetElement : nsIDOMSVGFilterPrimitiveStandardAttributes {
readonly attribute nsIDOMSVGAnimatedString in1;

View File

@ -0,0 +1,22 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://www.w3.org/TR/SVG2/
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
interface SVGAnimatedNumber;
interface SVGAnimatedString;
interface SVGFEGaussianBlurElement : SVGElement {
readonly attribute SVGAnimatedString in1;
readonly attribute SVGAnimatedNumber stdDeviationX;
readonly attribute SVGAnimatedNumber stdDeviationY;
void setStdDeviation(float stdDeviationX, float stdDeviationY);
};

View File

@ -194,6 +194,7 @@ webidl_files = \
SVGFEFuncBElement.webidl \
SVGFEFuncGElement.webidl \
SVGFEFuncRElement.webidl \
SVGFEGaussianBlurElement.webidl \
SVGFEImageElement.webidl \
SVGFEMergeElement.webidl \
SVGFEMergeNodeElement.webidl \