Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: Source/core/layout/svg/ReferenceFilterBuilder.cpp

Issue 1326183002: Merge ReferenceFilter into Filter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Touchups; Rebase. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Adobe Systems Inc. All rights reserved. 2 * Copyright (C) 2013 Adobe Systems Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Copyright (C) 2011 Apple Inc. All rights reserved. 4 * Copyright (C) 2011 Apple Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "config.h" 28 #include "config.h"
29
30 #include "core/layout/svg/ReferenceFilterBuilder.h" 29 #include "core/layout/svg/ReferenceFilterBuilder.h"
31 30
32 #include "core/css/CSSPrimitiveValue.h" 31 #include "core/css/CSSPrimitiveValue.h"
33 #include "core/css/CSSPrimitiveValueMappings.h" 32 #include "core/css/CSSPrimitiveValueMappings.h"
34 #include "core/css/StylePropertySet.h" 33 #include "core/css/StylePropertySet.h"
35 #include "core/dom/Element.h" 34 #include "core/dom/Element.h"
36 #include "core/dom/ElementTraversal.h" 35 #include "core/dom/ElementTraversal.h"
37 #include "core/fetch/DocumentResource.h" 36 #include "core/fetch/DocumentResource.h"
38 #include "core/layout/LayoutBox.h" 37 #include "core/layout/LayoutBox.h"
39 #include "core/layout/svg/LayoutSVGResourceFilter.h" 38 #include "core/layout/svg/LayoutSVGResourceFilter.h"
40 #include "core/svg/SVGDocumentExtensions.h" 39 #include "core/svg/SVGDocumentExtensions.h"
41 #include "core/svg/SVGFilterPrimitiveStandardAttributes.h" 40 #include "core/svg/SVGFilterPrimitiveStandardAttributes.h"
42 #include "core/svg/graphics/filters/SVGFilterBuilder.h" 41 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
43 #include "platform/graphics/filters/ReferenceFilter.h" 42 #include "platform/graphics/filters/Filter.h"
44 #include "platform/graphics/filters/SourceGraphic.h" 43 #include "platform/graphics/filters/SourceGraphic.h"
45 44
46 namespace blink { 45 namespace blink {
47 46
48 HashMap<const FilterOperation*, OwnPtr<DocumentResourceReference>>* ReferenceFil terBuilder::documentResourceReferences = nullptr; 47 HashMap<const FilterOperation*, OwnPtr<DocumentResourceReference>>* ReferenceFil terBuilder::documentResourceReferences = nullptr;
49 48
50 DocumentResourceReference* ReferenceFilterBuilder::documentResourceReference(con st FilterOperation* filterOperation) 49 DocumentResourceReference* ReferenceFilterBuilder::documentResourceReference(con st FilterOperation* filterOperation)
51 { 50 {
52 if (!documentResourceReferences) 51 if (!documentResourceReferences)
53 return nullptr; 52 return nullptr;
(...skipping 29 matching lines...) Expand all
83 if (cssValue && cssValue->isPrimitiveValue()) { 82 if (cssValue && cssValue->isPrimitiveValue()) {
84 const CSSPrimitiveValue& primitiveValue = *((CSSPrimitiveValue*)cssV alue.get()); 83 const CSSPrimitiveValue& primitiveValue = *((CSSPrimitiveValue*)cssV alue.get());
85 return static_cast<EColorInterpolation>(primitiveValue); 84 return static_cast<EColorInterpolation>(primitiveValue);
86 } 85 }
87 } 86 }
88 // 'auto' is the default (per Filter Effects), but since the property is 87 // 'auto' is the default (per Filter Effects), but since the property is
89 // inherited, propagate the parent's value. 88 // inherited, propagate the parent's value.
90 return parentColorInterpolation; 89 return parentColorInterpolation;
91 } 90 }
92 91
93 PassRefPtrWillBeRawPtr<ReferenceFilter> ReferenceFilterBuilder::build(float zoom , Element* element, FilterEffect* previousEffect, const ReferenceFilterOperation & filterOperation) 92 PassRefPtrWillBeRawPtr<Filter> ReferenceFilterBuilder::build(float zoom, Element * element, FilterEffect* previousEffect, const ReferenceFilterOperation& filterO peration)
94 { 93 {
95 TreeScope* treeScope = &element->treeScope(); 94 TreeScope* treeScope = &element->treeScope();
96 95
97 if (DocumentResourceReference* documentResourceRef = documentResourceReferen ce(&filterOperation)) { 96 if (DocumentResourceReference* documentResourceRef = documentResourceReferen ce(&filterOperation)) {
98 DocumentResource* cachedSVGDocument = documentResourceRef->document(); 97 DocumentResource* cachedSVGDocument = documentResourceRef->document();
99 98
100 // If we have an SVG document, this is an external reference. Otherwise 99 // If we have an SVG document, this is an external reference. Otherwise
101 // we look up the referenced node in the current document. 100 // we look up the referenced node in the current document.
102 if (cachedSVGDocument) 101 if (cachedSVGDocument)
103 treeScope = cachedSVGDocument->document(); 102 treeScope = cachedSVGDocument->document();
104 } 103 }
105 104
106 if (!treeScope) 105 if (!treeScope)
107 return nullptr; 106 return nullptr;
108 107
109 Element* filter = treeScope->getElementById(filterOperation.fragment()); 108 Element* filter = treeScope->getElementById(filterOperation.fragment());
110 109
111 if (!filter) { 110 if (!filter) {
112 // Although we did not find the referenced filter, it might exist later 111 // Although we did not find the referenced filter, it might exist later
113 // in the document. 112 // in the document.
114 treeScope->document().accessSVGExtensions().addPendingResource(filterOpe ration.fragment(), element); 113 treeScope->document().accessSVGExtensions().addPendingResource(filterOpe ration.fragment(), element);
115 return nullptr; 114 return nullptr;
116 } 115 }
117 116
118 if (!isSVGFilterElement(*filter)) 117 if (!isSVGFilterElement(*filter))
119 return nullptr; 118 return nullptr;
120 119
121 SVGFilterElement& filterElement = toSVGFilterElement(*filter); 120 SVGFilterElement& filterElement = toSVGFilterElement(*filter);
122 121
123 FloatRect targetBoundingBox; 122 FloatRect referenceBox;
124 if (element->inDocument() && element->layoutObject() && element->layoutObjec t()->isBoxModelObject()) 123 if (element->inDocument() && element->layoutObject() && element->layoutObjec t()->isBoxModelObject())
125 targetBoundingBox = toLayoutBoxModelObject(element->layoutObject())->bor derBoundingBox(); 124 referenceBox = toLayoutBoxModelObject(element->layoutObject())->borderBo undingBox();
126 targetBoundingBox.scale(1.0f / zoom); 125 referenceBox.scale(1.0f / zoom);
127 FloatRect filterRegion = SVGLengthContext::resolveRectangle<SVGFilterElement >(&filterElement, filterElement.filterUnits()->currentValue()->enumValue(), targ etBoundingBox); 126 FloatRect filterRegion = SVGLengthContext::resolveRectangle<SVGFilterElement >(&filterElement, filterElement.filterUnits()->currentValue()->enumValue(), refe renceBox);
128 RefPtrWillBeRawPtr<ReferenceFilter> result(ReferenceFilter::create(targetBou ndingBox, filterRegion, zoom)); 127 RefPtrWillBeRawPtr<Filter> result(Filter::create(referenceBox, filterRegion, zoom));
129 if (!previousEffect) 128 if (!previousEffect)
130 previousEffect = result->sourceGraphic(); 129 previousEffect = result->sourceGraphic();
131 RefPtrWillBeRawPtr<SVGFilterBuilder> builder = SVGFilterBuilder::create(prev iousEffect); 130 RefPtrWillBeRawPtr<SVGFilterBuilder> builder = SVGFilterBuilder::create(prev iousEffect);
132 131
133 EColorInterpolation filterColorInterpolation = colorInterpolationForElement( filterElement, CI_AUTO); 132 EColorInterpolation filterColorInterpolation = colorInterpolationForElement( filterElement, CI_AUTO);
134 133
135 for (SVGElement* element = Traversal<SVGElement>::firstChild(filterElement); element; element = Traversal<SVGElement>::nextSibling(*element)) { 134 for (SVGElement* element = Traversal<SVGElement>::firstChild(filterElement); element; element = Traversal<SVGElement>::nextSibling(*element)) {
136 if (!element->isFilterEffect()) 135 if (!element->isFilterEffect())
137 continue; 136 continue;
138 137
139 SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFil terPrimitiveStandardAttributes*>(element); 138 SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFil terPrimitiveStandardAttributes*>(element);
140 RefPtrWillBeRawPtr<FilterEffect> effect = effectElement->build(builder.g et(), result.get()); 139 RefPtrWillBeRawPtr<FilterEffect> effect = effectElement->build(builder.g et(), result.get());
141 if (!effect) 140 if (!effect)
142 continue; 141 continue;
143 142
144 effectElement->setStandardAttributes(effect.get()); 143 effectElement->setStandardAttributes(effect.get());
145 effect->setEffectBoundaries(SVGLengthContext::resolveRectangle<SVGFilter PrimitiveStandardAttributes>(effectElement, filterElement.primitiveUnits()->curr entValue()->enumValue(), targetBoundingBox)); 144 effect->setEffectBoundaries(SVGLengthContext::resolveRectangle<SVGFilter PrimitiveStandardAttributes>(effectElement, filterElement.primitiveUnits()->curr entValue()->enumValue(), referenceBox));
146 EColorInterpolation colorInterpolation = colorInterpolationForElement(*e ffectElement, filterColorInterpolation); 145 EColorInterpolation colorInterpolation = colorInterpolationForElement(*e ffectElement, filterColorInterpolation);
147 effect->setOperatingColorSpace(colorInterpolation == CI_LINEARRGB ? Colo rSpaceLinearRGB : ColorSpaceDeviceRGB); 146 effect->setOperatingColorSpace(colorInterpolation == CI_LINEARRGB ? Colo rSpaceLinearRGB : ColorSpaceDeviceRGB);
148 builder->add(AtomicString(effectElement->result()->currentValue()->value ()), effect); 147 builder->add(AtomicString(effectElement->result()->currentValue()->value ()), effect);
149 } 148 }
150 result->setLastEffect(builder->lastEffect()); 149 result->setLastEffect(builder->lastEffect());
151 return result.release(); 150 return result.release();
152 } 151 }
153 152
154 } // namespace blink 153 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/svg/ReferenceFilterBuilder.h ('k') | Source/core/paint/DeprecatedPaintLayer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698