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.
23 #include "FilterEffect.h"
24 #include "SVGUnitTypes.h"
25 #include <wtf/HashMap.h>
26 #include <wtf/HashSet.h>
27 #include <wtf/text/AtomStringHash.h>
28 #include <wtf/text/WTFString.h>
33 class SVGFilterElement;
35 class SVGFilterBuilder {
36 WTF_MAKE_FAST_ALLOCATED;
38 typedef HashSet<FilterEffect*> FilterEffectSet;
40 SVGFilterBuilder(RefPtr<FilterEffect> sourceGraphic);
42 void setTargetBoundingBox(const FloatRect& r) { m_targetBoundingBox = r; }
43 FloatRect targetBoundingBox() const { return m_targetBoundingBox; }
45 SVGUnitTypes::SVGUnitType primitiveUnits() const { return m_primitiveUnits; }
46 void setPrimitiveUnits(SVGUnitTypes::SVGUnitType units) { m_primitiveUnits = units; }
48 void add(const AtomString& id, RefPtr<FilterEffect>);
50 RefPtr<FilterEffect> getEffectById(const AtomString&) const;
51 FilterEffect* lastEffect() const { return m_lastEffect.get(); }
53 void appendEffectToEffectReferences(RefPtr<FilterEffect>&&, RenderObject*);
55 inline FilterEffectSet& effectReferences(FilterEffect* effect)
57 // Only allowed for effects belongs to this builder.
58 ASSERT(m_effectReferences.contains(effect));
59 return m_effectReferences.find(effect)->value;
62 // Required to change the attributes of a filter during an svgAttributeChanged.
63 inline FilterEffect* effectByRenderer(RenderObject* object) { return m_effectRenderer.get(object); }
66 void clearResultsRecursive(FilterEffect*);
69 inline void addBuiltinEffects()
71 for (auto& effect : m_builtinEffects.values())
72 m_effectReferences.add(effect, FilterEffectSet());
75 HashMap<AtomString, RefPtr<FilterEffect>> m_builtinEffects;
76 HashMap<AtomString, RefPtr<FilterEffect>> m_namedEffects;
77 // The value is a list, which contains those filter effects,
78 // which depends on the key filter effect.
79 HashMap<RefPtr<FilterEffect>, FilterEffectSet> m_effectReferences;
80 HashMap<RenderObject*, FilterEffect*> m_effectRenderer;
82 RefPtr<FilterEffect> m_lastEffect;
83 FloatRect m_targetBoundingBox;
84 SVGUnitTypes::SVGUnitType m_primitiveUnits { SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE };
87 } // namespace WebCore