2 * Copyright (C) 2008 Alex Mathews <possessedpenguinbob@gmail.com>
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef SVGFilterBuilder_h
22 #define SVGFilterBuilder_h
24 #include "platform/graphics/filters/FilterEffect.h"
25 #include "wtf/HashMap.h"
26 #include "wtf/HashSet.h"
27 #include "wtf/PassRefPtr.h"
28 #include "wtf/text/AtomicStringHash.h"
29 #include "wtf/text/WTFString.h"
35 class SVGFilterBuilder : public RefCounted<SVGFilterBuilder> {
37 typedef HashSet<FilterEffect*> FilterEffectSet;
39 static PassRefPtr<SVGFilterBuilder> create(PassRefPtr<FilterEffect> sourceGraphic, PassRefPtr<FilterEffect> sourceAlpha) { return adoptRef(new SVGFilterBuilder(sourceGraphic, sourceAlpha)); }
41 void add(const AtomicString& id, PassRefPtr<FilterEffect>);
43 FilterEffect* getEffectById(const AtomicString& id) const;
44 FilterEffect* lastEffect() const { return m_lastEffect.get(); }
46 void appendEffectToEffectReferences(PassRefPtr<FilterEffect>, RenderObject*);
48 inline FilterEffectSet& effectReferences(FilterEffect* effect)
50 // Only allowed for effects belongs to this builder.
51 ASSERT(m_effectReferences.contains(effect));
52 return m_effectReferences.find(effect)->value;
55 // Required to change the attributes of a filter during an svgAttributeChanged.
56 inline FilterEffect* effectByRenderer(RenderObject* object) { return m_effectRenderer.get(object); }
59 void clearResultsRecursive(FilterEffect*);
62 SVGFilterBuilder(PassRefPtr<FilterEffect> sourceGraphic, PassRefPtr<FilterEffect> sourceAlpha);
64 inline void addBuiltinEffects()
66 HashMap<AtomicString, RefPtr<FilterEffect> >::iterator end = m_builtinEffects.end();
67 for (HashMap<AtomicString, RefPtr<FilterEffect> >::iterator iterator = m_builtinEffects.begin(); iterator != end; ++iterator)
68 m_effectReferences.add(iterator->value, FilterEffectSet());
71 HashMap<AtomicString, RefPtr<FilterEffect> > m_builtinEffects;
72 HashMap<AtomicString, RefPtr<FilterEffect> > m_namedEffects;
73 // The value is a list, which contains those filter effects,
74 // which depends on the key filter effect.
75 HashMap<RefPtr<FilterEffect>, FilterEffectSet> m_effectReferences;
76 HashMap<RenderObject*, FilterEffect*> m_effectRenderer;
78 RefPtr<FilterEffect> m_lastEffect;
83 #endif // SVGFilterBuilder_h