/src/mozilla-central/dom/svg/SVGFEDisplacementMapElement.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "mozilla/dom/SVGFEDisplacementMapElement.h" |
8 | | #include "mozilla/dom/SVGFEDisplacementMapElementBinding.h" |
9 | | #include "nsSVGFilterInstance.h" |
10 | | #include "nsSVGUtils.h" |
11 | | |
12 | | NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(FEDisplacementMap) |
13 | | |
14 | | using namespace mozilla::gfx; |
15 | | |
16 | | namespace mozilla { |
17 | | namespace dom { |
18 | | |
19 | | JSObject* |
20 | | SVGFEDisplacementMapElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
21 | 0 | { |
22 | 0 | return SVGFEDisplacementMapElement_Binding::Wrap(aCx, this, aGivenProto); |
23 | 0 | } |
24 | | |
25 | | nsSVGElement::NumberInfo SVGFEDisplacementMapElement::sNumberInfo[1] = |
26 | | { |
27 | | { &nsGkAtoms::scale, 0, false }, |
28 | | }; |
29 | | |
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} |
36 | | }; |
37 | | |
38 | | nsSVGElement::EnumInfo SVGFEDisplacementMapElement::sEnumInfo[2] = |
39 | | { |
40 | | { &nsGkAtoms::xChannelSelector, |
41 | | sChannelMap, |
42 | | SVG_CHANNEL_A |
43 | | }, |
44 | | { &nsGkAtoms::yChannelSelector, |
45 | | sChannelMap, |
46 | | SVG_CHANNEL_A |
47 | | } |
48 | | }; |
49 | | |
50 | | nsSVGElement::StringInfo SVGFEDisplacementMapElement::sStringInfo[3] = |
51 | | { |
52 | | { &nsGkAtoms::result, kNameSpaceID_None, true }, |
53 | | { &nsGkAtoms::in, kNameSpaceID_None, true }, |
54 | | { &nsGkAtoms::in2, kNameSpaceID_None, true } |
55 | | }; |
56 | | |
57 | | //---------------------------------------------------------------------- |
58 | | // nsINode methods |
59 | | |
60 | | NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGFEDisplacementMapElement) |
61 | | |
62 | | //---------------------------------------------------------------------- |
63 | | |
64 | | already_AddRefed<SVGAnimatedString> |
65 | | SVGFEDisplacementMapElement::In1() |
66 | 0 | { |
67 | 0 | return mStringAttributes[IN1].ToDOMAnimatedString(this); |
68 | 0 | } |
69 | | |
70 | | already_AddRefed<SVGAnimatedString> |
71 | | SVGFEDisplacementMapElement::In2() |
72 | 0 | { |
73 | 0 | return mStringAttributes[IN2].ToDOMAnimatedString(this); |
74 | 0 | } |
75 | | |
76 | | already_AddRefed<SVGAnimatedNumber> |
77 | | SVGFEDisplacementMapElement::Scale() |
78 | 0 | { |
79 | 0 | return mNumberAttributes[SCALE].ToDOMAnimatedNumber(this); |
80 | 0 | } |
81 | | |
82 | | already_AddRefed<SVGAnimatedEnumeration> |
83 | | SVGFEDisplacementMapElement::XChannelSelector() |
84 | 0 | { |
85 | 0 | return mEnumAttributes[CHANNEL_X].ToDOMAnimatedEnum(this); |
86 | 0 | } |
87 | | |
88 | | already_AddRefed<SVGAnimatedEnumeration> |
89 | | SVGFEDisplacementMapElement::YChannelSelector() |
90 | 0 | { |
91 | 0 | return mEnumAttributes[CHANNEL_Y].ToDOMAnimatedEnum(this); |
92 | 0 | } |
93 | | |
94 | | FilterPrimitiveDescription |
95 | | SVGFEDisplacementMapElement::GetPrimitiveDescription(nsSVGFilterInstance* aInstance, |
96 | | const IntRect& aFilterSubregion, |
97 | | const nsTArray<bool>& aInputsAreTainted, |
98 | | nsTArray<RefPtr<SourceSurface>>& aInputImages) |
99 | 0 | { |
100 | 0 | if (aInputsAreTainted[1]) { |
101 | 0 | // If the map is tainted, refuse to apply the effect and act as a |
102 | 0 | // pass-through filter instead, as required by the spec. |
103 | 0 | OffsetAttributes atts; |
104 | 0 | atts.mValue = IntPoint(0, 0); |
105 | 0 | return FilterPrimitiveDescription(AsVariant(std::move(atts))); |
106 | 0 | } |
107 | 0 | |
108 | 0 | float scale = aInstance->GetPrimitiveNumber(SVGContentUtils::XY, |
109 | 0 | &mNumberAttributes[SCALE]); |
110 | 0 | uint32_t xChannel = mEnumAttributes[CHANNEL_X].GetAnimValue(); |
111 | 0 | uint32_t yChannel = mEnumAttributes[CHANNEL_Y].GetAnimValue(); |
112 | 0 | DisplacementMapAttributes atts; |
113 | 0 | atts.mScale = scale; |
114 | 0 | atts.mXChannel = xChannel; |
115 | 0 | atts.mYChannel = yChannel; |
116 | 0 | return FilterPrimitiveDescription(AsVariant(std::move(atts))); |
117 | 0 | } |
118 | | |
119 | | bool |
120 | | SVGFEDisplacementMapElement::AttributeAffectsRendering(int32_t aNameSpaceID, |
121 | | nsAtom* aAttribute) const |
122 | 0 | { |
123 | 0 | return SVGFEDisplacementMapElementBase::AttributeAffectsRendering(aNameSpaceID, aAttribute) || |
124 | 0 | (aNameSpaceID == kNameSpaceID_None && |
125 | 0 | (aAttribute == nsGkAtoms::in || |
126 | 0 | aAttribute == nsGkAtoms::in2 || |
127 | 0 | aAttribute == nsGkAtoms::scale || |
128 | 0 | aAttribute == nsGkAtoms::xChannelSelector || |
129 | 0 | aAttribute == nsGkAtoms::yChannelSelector)); |
130 | 0 | } |
131 | | |
132 | | void |
133 | | SVGFEDisplacementMapElement::GetSourceImageNames(nsTArray<nsSVGStringInfo>& aSources) |
134 | 0 | { |
135 | 0 | aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN1], this)); |
136 | 0 | aSources.AppendElement(nsSVGStringInfo(&mStringAttributes[IN2], this)); |
137 | 0 | } |
138 | | |
139 | | //---------------------------------------------------------------------- |
140 | | // nsSVGElement methods |
141 | | |
142 | | nsSVGElement::NumberAttributesInfo |
143 | | SVGFEDisplacementMapElement::GetNumberInfo() |
144 | 0 | { |
145 | 0 | return NumberAttributesInfo(mNumberAttributes, sNumberInfo, |
146 | 0 | ArrayLength(sNumberInfo)); |
147 | 0 | } |
148 | | |
149 | | nsSVGElement::EnumAttributesInfo |
150 | | SVGFEDisplacementMapElement::GetEnumInfo() |
151 | 0 | { |
152 | 0 | return EnumAttributesInfo(mEnumAttributes, sEnumInfo, |
153 | 0 | ArrayLength(sEnumInfo)); |
154 | 0 | } |
155 | | |
156 | | nsSVGElement::StringAttributesInfo |
157 | | SVGFEDisplacementMapElement::GetStringInfo() |
158 | 0 | { |
159 | 0 | return StringAttributesInfo(mStringAttributes, sStringInfo, |
160 | 0 | ArrayLength(sStringInfo)); |
161 | 0 | } |
162 | | |
163 | | } // namespace dom |
164 | | } // namespace mozilla |