Home | History | Annotate | Download | only in filters
      1 /*
      2  * Copyright (C) 2008 Alex Mathews <possessedpenguinbob (at) gmail.com>
      3  * Copyright (C) 2009 Dirk Schulze <krit (at) webkit.org>
      4  *
      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.
      9  *
     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.
     14  *
     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.
     19  */
     20 
     21 #ifndef SVGFilterBuilder_h
     22 #define SVGFilterBuilder_h
     23 
     24 #if ENABLE(SVG) && ENABLE(FILTERS)
     25 #include "FilterEffect.h"
     26 #include "PlatformString.h"
     27 #include "RenderObject.h"
     28 
     29 #include <wtf/HashMap.h>
     30 #include <wtf/HashSet.h>
     31 #include <wtf/PassRefPtr.h>
     32 #include <wtf/text/AtomicStringHash.h>
     33 
     34 namespace WebCore {
     35 
     36 class SVGFilterBuilder : public RefCounted<SVGFilterBuilder> {
     37 public:
     38     typedef HashSet<FilterEffect*> FilterEffectSet;
     39 
     40     static PassRefPtr<SVGFilterBuilder> create(Filter* filter) { return adoptRef(new SVGFilterBuilder(filter)); }
     41 
     42     void add(const AtomicString& id, RefPtr<FilterEffect> effect);
     43 
     44     FilterEffect* getEffectById(const AtomicString& id) const;
     45     FilterEffect* lastEffect() const { return m_lastEffect.get(); }
     46 
     47     void appendEffectToEffectReferences(RefPtr<FilterEffect>, RenderObject*);
     48 
     49     inline FilterEffectSet& effectReferences(FilterEffect* effect)
     50     {
     51         // Only allowed for effects belongs to this builder.
     52         ASSERT(m_effectReferences.contains(effect));
     53         return m_effectReferences.find(effect)->second;
     54     }
     55 
     56     // Required to change the attributes of a filter during an svgAttributeChanged.
     57     inline FilterEffect* effectByRenderer(RenderObject* object) { return m_effectRenderer.get(object); }
     58 
     59     void clearEffects();
     60     void clearResultsRecursive(FilterEffect*);
     61 
     62 private:
     63     SVGFilterBuilder(Filter*);
     64 
     65     inline void addBuiltinEffects()
     66     {
     67         HashMap<AtomicString, RefPtr<FilterEffect> >::iterator end = m_builtinEffects.end();
     68         for (HashMap<AtomicString, RefPtr<FilterEffect> >::iterator iterator = m_builtinEffects.begin(); iterator != end; ++iterator)
     69              m_effectReferences.add(iterator->second, FilterEffectSet());
     70     }
     71 
     72     HashMap<AtomicString, RefPtr<FilterEffect> > m_builtinEffects;
     73     HashMap<AtomicString, RefPtr<FilterEffect> > m_namedEffects;
     74     // The value is a list, which contains those filter effects,
     75     // which depends on the key filter effect.
     76     HashMap<RefPtr<FilterEffect>, FilterEffectSet> m_effectReferences;
     77     HashMap<RenderObject*, FilterEffect*> m_effectRenderer;
     78 
     79     RefPtr<FilterEffect> m_lastEffect;
     80 };
     81 
     82 } // namespace WebCore
     83 
     84 #endif // ENABLE(SVG) && ENABLE(FILTERS)
     85 #endif // SVGFilterBuilder_h
     86