1 | /* |
2 | * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 | * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 | * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved. |
5 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
6 | * |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Library General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Library General Public License |
18 | * along with this library; see the file COPYING.LIB. If not, write to |
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #include "config.h" |
24 | #include "SVGFEBlendElement.h" |
25 | |
26 | #include "FEBlend.h" |
27 | #include "FilterEffect.h" |
28 | #include "SVGFilterBuilder.h" |
29 | #include "SVGNames.h" |
30 | #include <wtf/IsoMallocInlines.h> |
31 | |
32 | namespace WebCore { |
33 | |
34 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFEBlendElement); |
35 | |
36 | inline SVGFEBlendElement::SVGFEBlendElement(const QualifiedName& tagName, Document& document) |
37 | : SVGFilterPrimitiveStandardAttributes(tagName, document) |
38 | { |
39 | ASSERT(hasTagName(SVGNames::feBlendTag)); |
40 | |
41 | static std::once_flag onceFlag; |
42 | std::call_once(onceFlag, [] { |
43 | PropertyRegistry::registerProperty<SVGNames::modeAttr, BlendMode, &SVGFEBlendElement::m_mode>(); |
44 | PropertyRegistry::registerProperty<SVGNames::inAttr, &SVGFEBlendElement::m_in1>(); |
45 | PropertyRegistry::registerProperty<SVGNames::in2Attr, &SVGFEBlendElement::m_in2>(); |
46 | }); |
47 | } |
48 | |
49 | Ref<SVGFEBlendElement> SVGFEBlendElement::create(const QualifiedName& tagName, Document& document) |
50 | { |
51 | return adoptRef(*new SVGFEBlendElement(tagName, document)); |
52 | } |
53 | |
54 | void SVGFEBlendElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
55 | { |
56 | if (name == SVGNames::modeAttr) { |
57 | BlendMode mode = BlendMode::Normal; |
58 | if (parseBlendMode(value, mode)) |
59 | m_mode->setBaseValInternal<BlendMode>(mode); |
60 | return; |
61 | } |
62 | |
63 | if (name == SVGNames::inAttr) { |
64 | m_in1->setBaseValInternal(value); |
65 | return; |
66 | } |
67 | |
68 | if (name == SVGNames::in2Attr) { |
69 | m_in2->setBaseValInternal(value); |
70 | return; |
71 | } |
72 | |
73 | SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); |
74 | } |
75 | |
76 | bool SVGFEBlendElement::setFilterEffectAttribute(FilterEffect* effect, const QualifiedName& attrName) |
77 | { |
78 | FEBlend* blend = static_cast<FEBlend*>(effect); |
79 | if (attrName == SVGNames::modeAttr) |
80 | return blend->setBlendMode(mode()); |
81 | |
82 | ASSERT_NOT_REACHED(); |
83 | return false; |
84 | } |
85 | |
86 | void SVGFEBlendElement::svgAttributeChanged(const QualifiedName& attrName) |
87 | { |
88 | if (attrName == SVGNames::modeAttr) { |
89 | InstanceInvalidationGuard guard(*this); |
90 | primitiveAttributeChanged(attrName); |
91 | return; |
92 | } |
93 | |
94 | if (attrName == SVGNames::inAttr || attrName == SVGNames::in2Attr) { |
95 | InstanceInvalidationGuard guard(*this); |
96 | invalidate(); |
97 | return; |
98 | } |
99 | |
100 | SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName); |
101 | } |
102 | |
103 | RefPtr<FilterEffect> SVGFEBlendElement::build(SVGFilterBuilder* filterBuilder, Filter& filter) const |
104 | { |
105 | auto input1 = filterBuilder->getEffectById(in1()); |
106 | auto input2 = filterBuilder->getEffectById(in2()); |
107 | |
108 | if (!input1 || !input2) |
109 | return nullptr; |
110 | |
111 | auto effect = FEBlend::create(filter, mode()); |
112 | FilterEffectVector& inputEffects = effect->inputEffects(); |
113 | inputEffects.reserveCapacity(2); |
114 | inputEffects.append(input1); |
115 | inputEffects.append(input2); |
116 | return effect; |
117 | } |
118 | |
119 | } |
120 | |