OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 2 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "core/svg/graphics/filters/SVGFilterBuilder.h" | 21 #include "core/svg/graphics/filters/SVGFilterBuilder.h" |
22 | 22 |
23 #include "core/css/CSSPrimitiveValue.h" | |
24 #include "core/css/CSSPrimitiveValueMappings.h" | |
25 #include "core/css/StylePropertySet.h" | |
26 #include "core/dom/ElementTraversal.h" | |
27 #include "core/layout/LayoutObject.h" | |
28 #include "core/svg/SVGFilterElement.h" | |
29 #include "core/svg/SVGFilterPrimitiveStandardAttributes.h" | |
30 #include "platform/graphics/filters/Filter.h" | |
23 #include "platform/graphics/filters/SourceAlpha.h" | 31 #include "platform/graphics/filters/SourceAlpha.h" |
24 #include "platform/graphics/filters/SourceGraphic.h" | 32 #include "platform/graphics/filters/SourceGraphic.h" |
25 | 33 |
26 namespace blink { | 34 namespace blink { |
27 | 35 |
28 SVGFilterBuilder::SVGFilterBuilder(PassRefPtrWillBeRawPtr<FilterEffect> sourceGr aphic) | 36 void SVGFilterGraphNodeMap::addBuiltinEffect(FilterEffect* effect) |
37 { | |
38 m_effectReferences.add(effect, FilterEffectSet()); | |
39 } | |
40 | |
41 void SVGFilterGraphNodeMap::addPrimitive(PassRefPtrWillBeRawPtr<FilterEffect> pr pEffect, LayoutObject* object) | |
42 { | |
43 RefPtrWillBeRawPtr<FilterEffect> effect = prpEffect; | |
44 | |
45 // The effect must be a newly created filter effect. | |
46 ASSERT(!m_effectReferences.contains(effect)); | |
47 ASSERT(object && !m_effectRenderer.contains(object)); | |
48 m_effectReferences.add(effect, FilterEffectSet()); | |
49 | |
50 unsigned numberOfInputEffects = effect->inputEffects().size(); | |
51 | |
52 // Add references from the inputs of this effect to the effect itself, to | |
53 // allow determining what effects needs to be invalidated when a certain | |
54 // effect changes. | |
55 for (unsigned i = 0; i < numberOfInputEffects; ++i) | |
56 effectReferences(effect->inputEffect(i)).add(effect.get()); | |
57 | |
58 m_effectRenderer.add(object, effect.get()); | |
59 } | |
60 | |
61 void SVGFilterGraphNodeMap::invalidateDependentEffects(FilterEffect* effect) | |
62 { | |
63 if (!effect->hasImageFilter()) | |
64 return; | |
65 | |
66 effect->clearResult(); | |
67 | |
68 FilterEffectSet& effectReferences = this->effectReferences(effect); | |
69 for (FilterEffect* effectReference : effectReferences) | |
70 invalidateDependentEffects(effectReference); | |
71 } | |
72 | |
73 DEFINE_TRACE(SVGFilterGraphNodeMap) | |
74 { | |
75 #if ENABLE(OILPAN) | |
76 visitor->trace(m_effectRenderer); | |
77 visitor->trace(m_effectReferences); | |
78 #endif | |
79 } | |
80 | |
81 SVGFilterBuilder::SVGFilterBuilder( | |
82 PassRefPtrWillBeRawPtr<Filter> filter, | |
83 PassRefPtrWillBeRawPtr<FilterEffect> sourceGraphic, | |
84 PassRefPtrWillBeRawPtr<SVGFilterGraphNodeMap> nodeMap) | |
85 : m_filter(filter) | |
86 , m_nodeMap(nodeMap) | |
29 { | 87 { |
30 RefPtrWillBeRawPtr<FilterEffect> sourceGraphicRef = sourceGraphic; | 88 RefPtrWillBeRawPtr<FilterEffect> sourceGraphicRef = sourceGraphic; |
31 m_builtinEffects.add(SourceGraphic::effectName(), sourceGraphicRef); | 89 m_builtinEffects.add(SourceGraphic::effectName(), sourceGraphicRef); |
32 m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(sourceGr aphicRef.get())); | 90 m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(sourceGr aphicRef.get())); |
33 addBuiltinEffects(); | 91 addBuiltinEffects(); |
34 } | 92 } |
35 | 93 |
36 DEFINE_TRACE(SVGFilterBuilder) | 94 void SVGFilterBuilder::addBuiltinEffects() |
37 { | 95 { |
38 #if ENABLE(OILPAN) | 96 if (!m_nodeMap) |
39 visitor->trace(m_builtinEffects); | 97 return; |
40 visitor->trace(m_namedEffects); | 98 for (const auto& entry : m_builtinEffects) |
41 visitor->trace(m_effectRenderer); | 99 m_nodeMap->addBuiltinEffect(entry.value.get()); |
42 visitor->trace(m_effectReferences); | 100 } |
43 visitor->trace(m_lastEffect); | 101 |
44 #endif | 102 // Returns the color-interpolation-filters property of the element. |
103 static EColorInterpolation colorInterpolationForElement(SVGElement& element, ECo lorInterpolation parentColorInterpolation) | |
104 { | |
105 if (const LayoutObject* layoutObject = element.layoutObject()) | |
106 return layoutObject->styleRef().svgStyle().colorInterpolationFilters(); | |
107 | |
108 // No layout has been performed, try to determine the property value | |
109 // "manually" (used by external SVG files.) | |
110 if (const StylePropertySet* propertySet = element.presentationAttributeStyle ()) { | |
111 RefPtrWillBeRawPtr<CSSValue> cssValue = propertySet->getPropertyCSSValue (CSSPropertyColorInterpolationFilters); | |
112 if (cssValue && cssValue->isPrimitiveValue()) { | |
113 const CSSPrimitiveValue& primitiveValue = *((CSSPrimitiveValue*)cssV alue.get()); | |
114 return static_cast<EColorInterpolation>(primitiveValue); | |
115 } | |
116 } | |
117 // 'auto' is the default (per Filter Effects), but since the property is | |
118 // inherited, propagate the parent's value. | |
119 return parentColorInterpolation; | |
120 } | |
121 | |
122 void SVGFilterBuilder::buildGraph(SVGFilterElement& filterElement, const FloatRe ct& referenceBox) | |
123 { | |
124 EColorInterpolation filterColorInterpolation = colorInterpolationForElement( filterElement, CI_AUTO); | |
125 | |
126 for (SVGElement* element = Traversal<SVGElement>::firstChild(filterElement); element; element = Traversal<SVGElement>::nextSibling(*element)) { | |
127 if (!element->isFilterEffect()) | |
128 continue; | |
129 | |
130 SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFil terPrimitiveStandardAttributes*>(element); | |
131 RefPtrWillBeRawPtr<FilterEffect> effect = effectElement->build(this, m_f ilter.get()); | |
132 if (!effect) | |
133 continue; | |
134 | |
135 if (m_nodeMap && effectElement->layoutObject()) | |
136 m_nodeMap->addPrimitive(effect, effectElement->layoutObject()); | |
137 effectElement->setStandardAttributes(effect.get()); | |
138 effect->setEffectBoundaries(SVGLengthContext::resolveRectangle<SVGFilter PrimitiveStandardAttributes>(effectElement, filterElement.primitiveUnits()->curr entValue()->enumValue(), referenceBox)); | |
139 EColorInterpolation colorInterpolation = colorInterpolationForElement(*e ffectElement, filterColorInterpolation); | |
140 effect->setOperatingColorSpace(colorInterpolation == CI_LINEARRGB ? Colo rSpaceLinearRGB : ColorSpaceDeviceRGB); | |
141 | |
142 add(AtomicString(effectElement->result()->currentValue()->value()), effe ct); | |
143 } | |
144 m_filter->setLastEffect(m_lastEffect); | |
Stephen White
2015/10/07 19:44:01
It seems a shame to add the Filter as a member of
fs
2015/10/08 10:53:11
We still need it so that we can pass it to SVGFE*E
Stephen White
2015/10/08 18:48:03
Ah yes, I missed that. Definitely better as an arg
| |
45 } | 145 } |
46 | 146 |
47 void SVGFilterBuilder::add(const AtomicString& id, PassRefPtrWillBeRawPtr<Filter Effect> effect) | 147 void SVGFilterBuilder::add(const AtomicString& id, PassRefPtrWillBeRawPtr<Filter Effect> effect) |
48 { | 148 { |
49 if (id.isEmpty()) { | 149 if (id.isEmpty()) { |
50 m_lastEffect = effect; | 150 m_lastEffect = effect; |
51 return; | 151 return; |
52 } | 152 } |
53 | 153 |
54 if (m_builtinEffects.contains(id)) | 154 if (m_builtinEffects.contains(id)) |
(...skipping 12 matching lines...) Expand all Loading... | |
67 if (FilterEffect* namedEffect = m_namedEffects.get(id)) | 167 if (FilterEffect* namedEffect = m_namedEffects.get(id)) |
68 return namedEffect; | 168 return namedEffect; |
69 } | 169 } |
70 | 170 |
71 if (m_lastEffect) | 171 if (m_lastEffect) |
72 return m_lastEffect.get(); | 172 return m_lastEffect.get(); |
73 | 173 |
74 return m_builtinEffects.get(SourceGraphic::effectName()); | 174 return m_builtinEffects.get(SourceGraphic::effectName()); |
75 } | 175 } |
76 | 176 |
77 void SVGFilterBuilder::appendEffectToEffectReferences(PassRefPtrWillBeRawPtr<Fil terEffect> prpEffect, LayoutObject* object) | |
78 { | |
79 RefPtrWillBeRawPtr<FilterEffect> effect = prpEffect; | |
80 | |
81 // The effect must be a newly created filter effect. | |
82 ASSERT(!m_effectReferences.contains(effect)); | |
83 ASSERT(object && !m_effectRenderer.contains(object)); | |
84 m_effectReferences.add(effect, FilterEffectSet()); | |
85 | |
86 unsigned numberOfInputEffects = effect->inputEffects().size(); | |
87 | |
88 // It is not possible to add the same value to a set twice. | |
89 for (unsigned i = 0; i < numberOfInputEffects; ++i) | |
90 effectReferences(effect->inputEffect(i)).add(effect.get()); | |
91 m_effectRenderer.add(object, effect.get()); | |
92 } | |
93 | |
94 void SVGFilterBuilder::clearEffects() | |
95 { | |
96 m_lastEffect = nullptr; | |
97 m_namedEffects.clear(); | |
98 m_effectReferences.clear(); | |
99 m_effectRenderer.clear(); | |
100 addBuiltinEffects(); | |
101 } | |
102 | |
103 void SVGFilterBuilder::clearResultsRecursive(FilterEffect* effect) | |
104 { | |
105 if (!effect->hasImageFilter()) | |
106 return; | |
107 | |
108 effect->clearResult(); | |
109 | |
110 FilterEffectSet& effectReferences = this->effectReferences(effect); | |
111 for (FilterEffect* effectReference : effectReferences) | |
112 clearResultsRecursive(effectReference); | |
113 } | |
114 | |
115 } // namespace blink | 177 } // namespace blink |
OLD | NEW |