2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
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.
21 #include "SVGFilterBuilder.h"
23 #include "FilterEffect.h"
24 #include "SourceAlpha.h"
25 #include "SourceGraphic.h"
26 #include <wtf/text/StringConcatenateNumbers.h>
30 SVGFilterBuilder::SVGFilterBuilder(RefPtr<FilterEffect> sourceGraphic)
32 m_builtinEffects.add(SourceGraphic::effectName(), sourceGraphic);
33 m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(*sourceGraphic));
37 void SVGFilterBuilder::add(const AtomString& id, RefPtr<FilterEffect> effect)
40 m_lastEffect = effect;
44 if (m_builtinEffects.contains(id))
47 m_lastEffect = effect;
48 m_namedEffects.set(id, m_lastEffect);
51 RefPtr<FilterEffect> SVGFilterBuilder::getEffectById(const AtomString& id) const
57 return m_builtinEffects.get(SourceGraphic::effectName());
60 if (m_builtinEffects.contains(id))
61 return m_builtinEffects.get(id);
63 return m_namedEffects.get(id);
66 void SVGFilterBuilder::appendEffectToEffectReferences(RefPtr<FilterEffect>&& effect, RenderObject* object)
68 // The effect must be a newly created filter effect.
69 ASSERT(!m_effectReferences.contains(effect));
70 ASSERT(!object || !m_effectRenderer.contains(object));
71 m_effectReferences.add(effect, FilterEffectSet());
73 unsigned numberOfInputEffects = effect->inputEffects().size();
75 // It is not possible to add the same value to a set twice.
76 for (unsigned i = 0; i < numberOfInputEffects; ++i)
77 effectReferences(effect->inputEffect(i)).add(effect.get());
79 // If object is null, that means the element isn't attached for some
80 // reason, which in turn mean that certain types of invalidation will not
81 // work (the LayoutObject -> FilterEffect mapping will not be defined).
83 m_effectRenderer.add(object, effect.get());
86 void SVGFilterBuilder::clearEffects()
88 m_lastEffect = nullptr;
89 m_namedEffects.clear();
90 m_effectReferences.clear();
91 m_effectRenderer.clear();
95 void SVGFilterBuilder::clearResultsRecursive(FilterEffect* effect)
97 if (!effect->hasResult())
100 effect->clearResult();
102 for (auto& reference : effectReferences(effect))
103 clearResultsRecursive(reference);
106 } // namespace WebCore