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/SVGFEDisplacementMapElement.h"
8 #include "mozilla/dom/SVGFEDisplacementMapElementBinding.h"
9 #include "nsSVGFilterInstance.h"
10 #include "nsSVGUtils.h"
12 NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDisplacementMap
)
14 using namespace mozilla::gfx
;
20 SVGFEDisplacementMapElement::WrapNode(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
)
22 return SVGFEDisplacementMapElementBinding::Wrap(aCx
, this, aGivenProto
);
25 nsSVGElement::NumberInfo
SVGFEDisplacementMapElement::sNumberInfo
[1] =
27 { &nsGkAtoms::scale
, 0, false },
30 nsSVGEnumMapping
SVGFEDisplacementMapElement::sChannelMap
[] = {
31 {&nsGkAtoms::R
, SVG_CHANNEL_R
},
32 {&nsGkAtoms::G
, SVG_CHANNEL_G
},
33 {&nsGkAtoms::B
, SVG_CHANNEL_B
},
34 {&nsGkAtoms::A
, SVG_CHANNEL_A
},
38 nsSVGElement::EnumInfo
SVGFEDisplacementMapElement::sEnumInfo
[2] =
40 { &nsGkAtoms::xChannelSelector
,
44 { &nsGkAtoms::yChannelSelector
,
50 nsSVGElement::StringInfo
SVGFEDisplacementMapElement::sStringInfo
[3] =
52 { &nsGkAtoms::result
, kNameSpaceID_None
, true },
53 { &nsGkAtoms::in
, kNameSpaceID_None
, true },
54 { &nsGkAtoms::in2
, kNameSpaceID_None
, true }
57 //----------------------------------------------------------------------
60 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDisplacementMapElement
)
62 //----------------------------------------------------------------------
64 already_AddRefed
<SVGAnimatedString
>
65 SVGFEDisplacementMapElement::In1()
67 return mStringAttributes
[IN1
].ToDOMAnimatedString(this);
70 already_AddRefed
<SVGAnimatedString
>
71 SVGFEDisplacementMapElement::In2()
73 return mStringAttributes
[IN2
].ToDOMAnimatedString(this);
76 already_AddRefed
<SVGAnimatedNumber
>
77 SVGFEDisplacementMapElement::Scale()
79 return mNumberAttributes
[SCALE
].ToDOMAnimatedNumber(this);
82 already_AddRefed
<SVGAnimatedEnumeration
>
83 SVGFEDisplacementMapElement::XChannelSelector()
85 return mEnumAttributes
[CHANNEL_X
].ToDOMAnimatedEnum(this);
88 already_AddRefed
<SVGAnimatedEnumeration
>
89 SVGFEDisplacementMapElement::YChannelSelector()
91 return mEnumAttributes
[CHANNEL_Y
].ToDOMAnimatedEnum(this);
94 FilterPrimitiveDescription
95 SVGFEDisplacementMapElement::GetPrimitiveDescription(nsSVGFilterInstance
* aInstance
,
96 const IntRect
& aFilterSubregion
,
97 const nsTArray
<bool>& aInputsAreTainted
,
98 nsTArray
<RefPtr
<SourceSurface
>>& aInputImages
)
100 if (aInputsAreTainted
[1]) {
101 // If the map is tainted, refuse to apply the effect and act as a
102 // pass-through filter instead, as required by the spec.
103 FilterPrimitiveDescription
descr(PrimitiveType::Offset
);
104 descr
.Attributes().Set(eOffsetOffset
, IntPoint(0, 0));
108 float scale
= aInstance
->GetPrimitiveNumber(SVGContentUtils::XY
,
109 &mNumberAttributes
[SCALE
]);
110 uint32_t xChannel
= mEnumAttributes
[CHANNEL_X
].GetAnimValue();
111 uint32_t yChannel
= mEnumAttributes
[CHANNEL_Y
].GetAnimValue();
112 FilterPrimitiveDescription
descr(PrimitiveType::DisplacementMap
);
113 descr
.Attributes().Set(eDisplacementMapScale
, scale
);
114 descr
.Attributes().Set(eDisplacementMapXChannel
, xChannel
);
115 descr
.Attributes().Set(eDisplacementMapYChannel
, yChannel
);
120 SVGFEDisplacementMapElement::AttributeAffectsRendering(int32_t aNameSpaceID
,
121 nsAtom
* aAttribute
) const
123 return SVGFEDisplacementMapElementBase::AttributeAffectsRendering(aNameSpaceID
, aAttribute
) ||
124 (aNameSpaceID
== kNameSpaceID_None
&&
125 (aAttribute
== nsGkAtoms::in
||
126 aAttribute
== nsGkAtoms::in2
||
127 aAttribute
== nsGkAtoms::scale
||
128 aAttribute
== nsGkAtoms::xChannelSelector
||
129 aAttribute
== nsGkAtoms::yChannelSelector
));
133 SVGFEDisplacementMapElement::GetSourceImageNames(nsTArray
<nsSVGStringInfo
>& aSources
)
135 aSources
.AppendElement(nsSVGStringInfo(&mStringAttributes
[IN1
], this));
136 aSources
.AppendElement(nsSVGStringInfo(&mStringAttributes
[IN2
], this));
139 //----------------------------------------------------------------------
140 // nsSVGElement methods
142 nsSVGElement::NumberAttributesInfo
143 SVGFEDisplacementMapElement::GetNumberInfo()
145 return NumberAttributesInfo(mNumberAttributes
, sNumberInfo
,
146 ArrayLength(sNumberInfo
));
149 nsSVGElement::EnumAttributesInfo
150 SVGFEDisplacementMapElement::GetEnumInfo()
152 return EnumAttributesInfo(mEnumAttributes
, sEnumInfo
,
153 ArrayLength(sEnumInfo
));
156 nsSVGElement::StringAttributesInfo
157 SVGFEDisplacementMapElement::GetStringInfo()
159 return StringAttributesInfo(mStringAttributes
, sStringInfo
,
160 ArrayLength(sStringInfo
));
164 } // namespace mozilla