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(LayoutObject* object, PassRefPtrWillBeR
awPtr<FilterEffect> prpEffect) |
| 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<FilterEffect> sourceGraphic, |
| 83 PassRefPtrWillBeRawPtr<SVGFilterGraphNodeMap> nodeMap) |
| 84 : m_nodeMap(nodeMap) |
29 { | 85 { |
30 RefPtrWillBeRawPtr<FilterEffect> sourceGraphicRef = sourceGraphic; | 86 RefPtrWillBeRawPtr<FilterEffect> sourceGraphicRef = sourceGraphic; |
31 m_builtinEffects.add(SourceGraphic::effectName(), sourceGraphicRef); | 87 m_builtinEffects.add(SourceGraphic::effectName(), sourceGraphicRef); |
32 m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(sourceGr
aphicRef.get())); | 88 m_builtinEffects.add(SourceAlpha::effectName(), SourceAlpha::create(sourceGr
aphicRef.get())); |
33 addBuiltinEffects(); | 89 addBuiltinEffects(); |
34 } | 90 } |
35 | 91 |
36 DEFINE_TRACE(SVGFilterBuilder) | 92 void SVGFilterBuilder::addBuiltinEffects() |
37 { | 93 { |
38 #if ENABLE(OILPAN) | 94 if (!m_nodeMap) |
39 visitor->trace(m_builtinEffects); | 95 return; |
40 visitor->trace(m_namedEffects); | 96 for (const auto& entry : m_builtinEffects) |
41 visitor->trace(m_effectRenderer); | 97 m_nodeMap->addBuiltinEffect(entry.value.get()); |
42 visitor->trace(m_effectReferences); | 98 } |
43 visitor->trace(m_lastEffect); | 99 |
44 #endif | 100 // Returns the color-interpolation-filters property of the element. |
| 101 static EColorInterpolation colorInterpolationForElement(SVGElement& element, ECo
lorInterpolation parentColorInterpolation) |
| 102 { |
| 103 if (const LayoutObject* layoutObject = element.layoutObject()) |
| 104 return layoutObject->styleRef().svgStyle().colorInterpolationFilters(); |
| 105 |
| 106 // No layout has been performed, try to determine the property value |
| 107 // "manually" (used by external SVG files.) |
| 108 if (const StylePropertySet* propertySet = element.presentationAttributeStyle
()) { |
| 109 RefPtrWillBeRawPtr<CSSValue> cssValue = propertySet->getPropertyCSSValue
(CSSPropertyColorInterpolationFilters); |
| 110 if (cssValue && cssValue->isPrimitiveValue()) { |
| 111 const CSSPrimitiveValue& primitiveValue = *((CSSPrimitiveValue*)cssV
alue.get()); |
| 112 return static_cast<EColorInterpolation>(primitiveValue); |
| 113 } |
| 114 } |
| 115 // 'auto' is the default (per Filter Effects), but since the property is |
| 116 // inherited, propagate the parent's value. |
| 117 return parentColorInterpolation; |
| 118 } |
| 119 |
| 120 void SVGFilterBuilder::buildGraph(Filter* filter, SVGFilterElement& filterElemen
t, const FloatRect& referenceBox) |
| 121 { |
| 122 EColorInterpolation filterColorInterpolation = colorInterpolationForElement(
filterElement, CI_AUTO); |
| 123 |
| 124 for (SVGElement* element = Traversal<SVGElement>::firstChild(filterElement);
element; element = Traversal<SVGElement>::nextSibling(*element)) { |
| 125 if (!element->isFilterEffect()) |
| 126 continue; |
| 127 |
| 128 SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFil
terPrimitiveStandardAttributes*>(element); |
| 129 RefPtrWillBeRawPtr<FilterEffect> effect = effectElement->build(this, fil
ter); |
| 130 if (!effect) |
| 131 continue; |
| 132 |
| 133 if (m_nodeMap && effectElement->layoutObject()) |
| 134 m_nodeMap->addPrimitive(effectElement->layoutObject(), effect); |
| 135 effectElement->setStandardAttributes(effect.get()); |
| 136 effect->setEffectBoundaries(SVGLengthContext::resolveRectangle<SVGFilter
PrimitiveStandardAttributes>(effectElement, filterElement.primitiveUnits()->curr
entValue()->enumValue(), referenceBox)); |
| 137 EColorInterpolation colorInterpolation = colorInterpolationForElement(*e
ffectElement, filterColorInterpolation); |
| 138 effect->setOperatingColorSpace(colorInterpolation == CI_LINEARRGB ? Colo
rSpaceLinearRGB : ColorSpaceDeviceRGB); |
| 139 |
| 140 add(AtomicString(effectElement->result()->currentValue()->value()), effe
ct); |
| 141 } |
45 } | 142 } |
46 | 143 |
47 void SVGFilterBuilder::add(const AtomicString& id, PassRefPtrWillBeRawPtr<Filter
Effect> effect) | 144 void SVGFilterBuilder::add(const AtomicString& id, PassRefPtrWillBeRawPtr<Filter
Effect> effect) |
48 { | 145 { |
49 if (id.isEmpty()) { | 146 if (id.isEmpty()) { |
50 m_lastEffect = effect; | 147 m_lastEffect = effect; |
51 return; | 148 return; |
52 } | 149 } |
53 | 150 |
54 if (m_builtinEffects.contains(id)) | 151 if (m_builtinEffects.contains(id)) |
(...skipping 12 matching lines...) Expand all Loading... |
67 if (FilterEffect* namedEffect = m_namedEffects.get(id)) | 164 if (FilterEffect* namedEffect = m_namedEffects.get(id)) |
68 return namedEffect; | 165 return namedEffect; |
69 } | 166 } |
70 | 167 |
71 if (m_lastEffect) | 168 if (m_lastEffect) |
72 return m_lastEffect.get(); | 169 return m_lastEffect.get(); |
73 | 170 |
74 return m_builtinEffects.get(SourceGraphic::effectName()); | 171 return m_builtinEffects.get(SourceGraphic::effectName()); |
75 } | 172 } |
76 | 173 |
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 | 174 } // namespace blink |
OLD | NEW |