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 #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"
     30 
     31 namespace WebCore {
     32 
     33 class RenderObject;
     34 
     35 class SVGFilterBuilder : public RefCounted<SVGFilterBuilder> {
     36 public:
     37     typedef HashSet<FilterEffect*> FilterEffectSet;
     38 
     39     static PassRefPtr<SVGFilterBuilder> create(PassRefPtr<FilterEffect> sourceGraphic, PassRefPtr<FilterEffect> sourceAlpha) { return adoptRef(new SVGFilterBuilder(sourceGraphic, sourceAlpha)); }
     40 
     41     void add(const AtomicString& id, PassRefPtr<FilterEffect>);
     42 
     43     FilterEffect* getEffectById(const AtomicString& id) const;
     44     FilterEffect* lastEffect() const { return m_lastEffect.get(); }
     45 
     46     void appendEffectToEffectReferences(PassRefPtr<FilterEffect>, RenderObject*);
     47 
     48     inline FilterEffectSet& effectReferences(FilterEffect* effect)
     49     {
     50         // Only allowed for effects belongs to this builder.
     51         ASSERT(m_effectReferences.contains(effect));
     52         return m_effectReferences.find(effect)->value;
     53     }
     54 
     55     // Required to change the attributes of a filter during an svgAttributeChanged.
     56     inline FilterEffect* effectByRenderer(RenderObject* object) { return m_effectRenderer.get(object); }
     57 
     58     void clearEffects();
     59     void clearResultsRecursive(FilterEffect*);
     60 
     61 private:
     62     SVGFilterBuilder(PassRefPtr<FilterEffect> sourceGraphic, PassRefPtr<FilterEffect> sourceAlpha);
     63 
     64     inline void addBuiltinEffects()
     65     {
     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());
     69     }
     70 
     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;
     77 
     78     RefPtr<FilterEffect> m_lastEffect;
     79 };
     80 
     81 } // namespace WebCore
     82 
     83 #endif // SVGFilterBuilder_h
     84