• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  *  Copyright (C) 2009 Dirk Schulze <krit@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  *  aint 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 #include "config.h"
22 
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFilterBuilder.h"
25 
26 #include "FilterEffect.h"
27 #include "PlatformString.h"
28 #include "SourceAlpha.h"
29 #include "SourceGraphic.h"
30 
31 #include <wtf/HashMap.h>
32 #include <wtf/PassRefPtr.h>
33 
34 namespace WebCore {
35 
SVGFilterBuilder()36 SVGFilterBuilder::SVGFilterBuilder()
37 {
38     m_builtinEffects.add(SourceGraphic::effectName(), SourceGraphic::create());
39     m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create());
40 }
41 
add(const AtomicString & id,RefPtr<FilterEffect> effect)42 void SVGFilterBuilder::add(const AtomicString& id, RefPtr<FilterEffect> effect)
43 {
44     if (id.isEmpty()) {
45         m_lastEffect = effect.get();
46         return;
47     }
48 
49     if (m_builtinEffects.contains(id))
50         return;
51 
52     m_lastEffect = effect.get();
53     m_namedEffects.set(id, m_lastEffect);
54 }
55 
getEffectById(const AtomicString & id) const56 FilterEffect* SVGFilterBuilder::getEffectById(const AtomicString& id) const
57 {
58     if (id.isEmpty()) {
59         if (m_lastEffect)
60             return m_lastEffect.get();
61 
62         return m_builtinEffects.get(SourceGraphic::effectName()).get();
63     }
64 
65     if (m_builtinEffects.contains(id))
66         return m_builtinEffects.get(id).get();
67 
68     return m_namedEffects.get(id).get();
69 }
70 
clearEffects()71 void SVGFilterBuilder::clearEffects()
72 {
73     m_lastEffect = 0;
74     m_namedEffects.clear();
75 }
76 
77 } // namespace WebCore
78 
79 #endif // ENABLE(SVG) && ENABLE(FILTERS)
80