Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / dom / svg / SVGFEDisplacementMapElement.cpp
blobc8dae4b40c7e536710adfe97f49485bcac9adc82
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;
16 namespace mozilla {
17 namespace dom {
19 JSObject*
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},
35 {nullptr, 0}
38 nsSVGElement::EnumInfo SVGFEDisplacementMapElement::sEnumInfo[2] =
40 { &nsGkAtoms::xChannelSelector,
41 sChannelMap,
42 SVG_CHANNEL_A
44 { &nsGkAtoms::yChannelSelector,
45 sChannelMap,
46 SVG_CHANNEL_A
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 //----------------------------------------------------------------------
58 // nsIDOMNode methods
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));
105 return descr;
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);
116 return descr;
119 bool
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));
132 void
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));
163 } // namespace dom
164 } // namespace mozilla