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.
22 #if ENABLE(SVG) && ENABLE(FILTERS)
23 #include "SVGFilterBuilder.h"
25 #include "FilterEffect.h"
26 #include "PlatformString.h"
27 #include "SourceAlpha.h"
28 #include "SourceGraphic.h"
30 #include <wtf/PassRefPtr.h>
34 SVGFilterBuilder::SVGFilterBuilder(Filter* filter)
36 m_builtinEffects.add(SourceGraphic::effectName(), SourceGraphic::create(filter));
37 m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(filter));
41 void SVGFilterBuilder::add(const AtomicString& id, PassRefPtr<FilterEffect> effect)
44 m_lastEffect = effect;
48 if (m_builtinEffects.contains(id))
51 m_lastEffect = effect;
52 m_namedEffects.set(id, m_lastEffect);
55 FilterEffect* SVGFilterBuilder::getEffectById(const AtomicString& id) const
59 return m_lastEffect.get();
61 return m_builtinEffects.get(SourceGraphic::effectName()).get();
64 if (m_builtinEffects.contains(id))
65 return m_builtinEffects.get(id).get();
67 return m_namedEffects.get(id).get();
70 void SVGFilterBuilder::appendEffectToEffectReferences(PassRefPtr<FilterEffect> prpEffect, RenderObject* object)
72 RefPtr<FilterEffect> effect = prpEffect;
74 // The effect must be a newly created filter effect.
75 ASSERT(!m_effectReferences.contains(effect));
76 ASSERT(object && !m_effectRenderer.contains(object));
77 m_effectReferences.add(effect, FilterEffectSet());
79 unsigned numberOfInputEffects = effect->inputEffects().size();
81 // It is not possible to add the same value to a set twice.
82 for (unsigned i = 0; i < numberOfInputEffects; ++i)
83 effectReferences(effect->inputEffect(i)).add(effect.get());
84 m_effectRenderer.add(object, effect.get());
87 void SVGFilterBuilder::clearEffects()
90 m_namedEffects.clear();
91 m_effectReferences.clear();
92 m_effectRenderer.clear();
96 void SVGFilterBuilder::clearResultsRecursive(FilterEffect* effect)
98 if (!effect->hasResult())
101 effect->clearResult();
103 HashSet<FilterEffect*>& effectReferences = this->effectReferences(effect);
104 HashSet<FilterEffect*>::iterator end = effectReferences.end();
105 for (HashSet<FilterEffect*>::iterator it = effectReferences.begin(); it != end; ++it)
106 clearResultsRecursive(*it);
109 } // namespace WebCore
111 #endif // ENABLE(SVG) && ENABLE(FILTERS)