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 "mozilla/SVGFilterInstance.h"
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/dom/BindContext.h"
13 NS_IMPL_NS_NEW_SVG_ELEMENT(FEGaussianBlur
)
15 using namespace mozilla::gfx
;
17 namespace mozilla::dom
{
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 SVGFilterInstance
* 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 nsresult
SVGFEGaussianBlurElement::BindToTree(BindContext
& aCtx
,
95 if (aCtx
.InComposedDoc()) {
96 aCtx
.OwnerDoc().SetUseCounter(eUseCounter_custom_feGaussianBlur
);
99 return SVGFEGaussianBlurElementBase::BindToTree(aCtx
, aParent
);
102 //----------------------------------------------------------------------
103 // SVGElement methods
105 SVGElement::NumberPairAttributesInfo
106 SVGFEGaussianBlurElement::GetNumberPairInfo() {
107 return NumberPairAttributesInfo(mNumberPairAttributes
, sNumberPairInfo
,
108 std::size(sNumberPairInfo
));
111 SVGElement::StringAttributesInfo
SVGFEGaussianBlurElement::GetStringInfo() {
112 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
113 std::size(sStringInfo
));
116 } // namespace mozilla::dom