2 * Copyright (C) 2006 Oliver Hunt <oliver@nerget.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "core/svg/SVGFEDisplacementMapElement.h"
24 #include "core/SVGNames.h"
25 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
26 #include "platform/graphics/filters/FilterEffect.h"
30 template<> const SVGEnumerationStringEntries
& getStaticStringEntries
<ChannelSelectorType
>()
32 DEFINE_STATIC_LOCAL(SVGEnumerationStringEntries
, entries
, ());
33 if (entries
.isEmpty()) {
34 entries
.append(std::make_pair(CHANNEL_R
, "R"));
35 entries
.append(std::make_pair(CHANNEL_G
, "G"));
36 entries
.append(std::make_pair(CHANNEL_B
, "B"));
37 entries
.append(std::make_pair(CHANNEL_A
, "A"));
42 inline SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(Document
& document
)
43 : SVGFilterPrimitiveStandardAttributes(SVGNames::feDisplacementMapTag
, document
)
44 , m_scale(SVGAnimatedNumber::create(this, SVGNames::scaleAttr
, SVGNumber::create(0)))
45 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr
, SVGString::create()))
46 , m_in2(SVGAnimatedString::create(this, SVGNames::in2Attr
, SVGString::create()))
47 , m_xChannelSelector(SVGAnimatedEnumeration
<ChannelSelectorType
>::create(this, SVGNames::xChannelSelectorAttr
, CHANNEL_A
))
48 , m_yChannelSelector(SVGAnimatedEnumeration
<ChannelSelectorType
>::create(this, SVGNames::yChannelSelectorAttr
, CHANNEL_A
))
50 addToPropertyMap(m_scale
);
51 addToPropertyMap(m_in1
);
52 addToPropertyMap(m_in2
);
53 addToPropertyMap(m_xChannelSelector
);
54 addToPropertyMap(m_yChannelSelector
);
57 DEFINE_TRACE(SVGFEDisplacementMapElement
)
59 visitor
->trace(m_scale
);
60 visitor
->trace(m_in1
);
61 visitor
->trace(m_in2
);
62 visitor
->trace(m_xChannelSelector
);
63 visitor
->trace(m_yChannelSelector
);
64 SVGFilterPrimitiveStandardAttributes::trace(visitor
);
67 DEFINE_NODE_FACTORY(SVGFEDisplacementMapElement
)
69 bool SVGFEDisplacementMapElement::setFilterEffectAttribute(FilterEffect
* effect
, const QualifiedName
& attrName
)
71 FEDisplacementMap
* displacementMap
= static_cast<FEDisplacementMap
*>(effect
);
72 if (attrName
== SVGNames::xChannelSelectorAttr
)
73 return displacementMap
->setXChannelSelector(m_xChannelSelector
->currentValue()->enumValue());
74 if (attrName
== SVGNames::yChannelSelectorAttr
)
75 return displacementMap
->setYChannelSelector(m_yChannelSelector
->currentValue()->enumValue());
76 if (attrName
== SVGNames::scaleAttr
)
77 return displacementMap
->setScale(m_scale
->currentValue()->value());
83 void SVGFEDisplacementMapElement::svgAttributeChanged(const QualifiedName
& attrName
)
85 if (attrName
== SVGNames::xChannelSelectorAttr
|| attrName
== SVGNames::yChannelSelectorAttr
|| attrName
== SVGNames::scaleAttr
) {
86 SVGElement::InvalidationGuard
invalidationGuard(this);
87 primitiveAttributeChanged(attrName
);
91 if (attrName
== SVGNames::inAttr
|| attrName
== SVGNames::in2Attr
) {
92 SVGElement::InvalidationGuard
invalidationGuard(this);
97 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName
);
100 PassRefPtrWillBeRawPtr
<FilterEffect
> SVGFEDisplacementMapElement::build(SVGFilterBuilder
* filterBuilder
, Filter
* filter
)
102 FilterEffect
* input1
= filterBuilder
->getEffectById(AtomicString(m_in1
->currentValue()->value()));
103 FilterEffect
* input2
= filterBuilder
->getEffectById(AtomicString(m_in2
->currentValue()->value()));
105 if (!input1
|| !input2
)
108 RefPtrWillBeRawPtr
<FilterEffect
> effect
= FEDisplacementMap::create(filter
, m_xChannelSelector
->currentValue()->enumValue(), m_yChannelSelector
->currentValue()->enumValue(), m_scale
->currentValue()->value());
109 FilterEffectVector
& inputEffects
= effect
->inputEffects();
110 inputEffects
.reserveCapacity(2);
111 inputEffects
.append(input1
);
112 inputEffects
.append(input2
);
113 return effect
.release();