1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/SVGFEGaussianBlurElement.h"
8 #include "mozilla/dom/SVGFEGaussianBlurElementBinding.h"
9 #include "nsSVGFilterInstance.h"
10 #include "nsSVGUtils.h"
12 NS_IMPL_NS_NEW_SVG_ELEMENT(FEGaussianBlur
)
14 using namespace mozilla::gfx
;
19 JSObject
* SVGFEGaussianBlurElement::WrapNode(
20 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
21 return SVGFEGaussianBlurElement_Binding::Wrap(aCx
, this, aGivenProto
);
24 SVGElement::NumberPairInfo
SVGFEGaussianBlurElement::sNumberPairInfo
[1] = {
25 {nsGkAtoms::stdDeviation
, 0, 0}};
27 SVGElement::StringInfo
SVGFEGaussianBlurElement::sStringInfo
[2] = {
28 {nsGkAtoms::result
, kNameSpaceID_None
, true},
29 {nsGkAtoms::in
, kNameSpaceID_None
, true}};
31 //----------------------------------------------------------------------
34 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEGaussianBlurElement
)
36 //----------------------------------------------------------------------
38 already_AddRefed
<DOMSVGAnimatedString
> SVGFEGaussianBlurElement::In1() {
39 return mStringAttributes
[IN1
].ToDOMAnimatedString(this);
42 already_AddRefed
<DOMSVGAnimatedNumber
>
43 SVGFEGaussianBlurElement::StdDeviationX() {
44 return mNumberPairAttributes
[STD_DEV
].ToDOMAnimatedNumber(
45 SVGAnimatedNumberPair::eFirst
, this);
48 already_AddRefed
<DOMSVGAnimatedNumber
>
49 SVGFEGaussianBlurElement::StdDeviationY() {
50 return mNumberPairAttributes
[STD_DEV
].ToDOMAnimatedNumber(
51 SVGAnimatedNumberPair::eSecond
, this);
54 void SVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX
,
55 float stdDeviationY
) {
56 mNumberPairAttributes
[STD_DEV
].SetBaseValues(stdDeviationX
, stdDeviationY
,
60 FilterPrimitiveDescription
SVGFEGaussianBlurElement::GetPrimitiveDescription(
61 nsSVGFilterInstance
* aInstance
, const IntRect
& aFilterSubregion
,
62 const nsTArray
<bool>& aInputsAreTainted
,
63 nsTArray
<RefPtr
<SourceSurface
>>& aInputImages
) {
64 float stdX
= aInstance
->GetPrimitiveNumber(SVGContentUtils::X
,
65 &mNumberPairAttributes
[STD_DEV
],
66 SVGAnimatedNumberPair::eFirst
);
67 float stdY
= aInstance
->GetPrimitiveNumber(SVGContentUtils::Y
,
68 &mNumberPairAttributes
[STD_DEV
],
69 SVGAnimatedNumberPair::eSecond
);
70 if (stdX
< 0 || stdY
< 0) {
71 return FilterPrimitiveDescription();
74 GaussianBlurAttributes atts
;
75 atts
.mStdDeviation
= Size(stdX
, stdY
);
76 return FilterPrimitiveDescription(AsVariant(std::move(atts
)));
79 bool SVGFEGaussianBlurElement::AttributeAffectsRendering(
80 int32_t aNameSpaceID
, nsAtom
* aAttribute
) const {
81 return SVGFEGaussianBlurElementBase::AttributeAffectsRendering(aNameSpaceID
,
83 (aNameSpaceID
== kNameSpaceID_None
&&
84 (aAttribute
== nsGkAtoms::in
||
85 aAttribute
== nsGkAtoms::stdDeviation
));
88 void SVGFEGaussianBlurElement::GetSourceImageNames(
89 nsTArray
<SVGStringInfo
>& aSources
) {
90 aSources
.AppendElement(SVGStringInfo(&mStringAttributes
[IN1
], this));
93 //----------------------------------------------------------------------
96 SVGElement::NumberPairAttributesInfo
97 SVGFEGaussianBlurElement::GetNumberPairInfo() {
98 return NumberPairAttributesInfo(mNumberPairAttributes
, sNumberPairInfo
,
99 ArrayLength(sNumberPairInfo
));
102 SVGElement::StringAttributesInfo
SVGFEGaussianBlurElement::GetStringInfo() {
103 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
104 ArrayLength(sStringInfo
));
108 } // namespace mozilla