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

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

Issue 1154853007: Move toClipPath to SVGGeometryElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Draft 12 Created 5 years, 6 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
« no previous file with comments | « no previous file | Source/core/svg/SVGGeometryElement.h » ('j') | Source/core/svg/SVGUseElement.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
5 * Copyright (C) 2011 Dirk Schulze <krit@webkit.org> 5 * Copyright (C) 2011 Dirk Schulze <krit@webkit.org>
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 14 matching lines...) Expand all
25 25
26 #include "core/SVGNames.h" 26 #include "core/SVGNames.h"
27 #include "core/dom/ElementTraversal.h" 27 #include "core/dom/ElementTraversal.h"
28 #include "core/layout/HitTestResult.h" 28 #include "core/layout/HitTestResult.h"
29 #include "core/layout/svg/SVGLayoutSupport.h" 29 #include "core/layout/svg/SVGLayoutSupport.h"
30 #include "core/layout/svg/SVGResources.h" 30 #include "core/layout/svg/SVGResources.h"
31 #include "core/layout/svg/SVGResourcesCache.h" 31 #include "core/layout/svg/SVGResourcesCache.h"
32 #include "core/paint/CompositingRecorder.h" 32 #include "core/paint/CompositingRecorder.h"
33 #include "core/paint/PaintInfo.h" 33 #include "core/paint/PaintInfo.h"
34 #include "core/paint/TransformRecorder.h" 34 #include "core/paint/TransformRecorder.h"
35 #include "core/svg/SVGGeometryElement.h"
35 #include "core/svg/SVGUseElement.h" 36 #include "core/svg/SVGUseElement.h"
36 #include "platform/RuntimeEnabledFeatures.h" 37 #include "platform/RuntimeEnabledFeatures.h"
37 #include "platform/graphics/paint/ClipPathDisplayItem.h" 38 #include "platform/graphics/paint/ClipPathDisplayItem.h"
38 #include "platform/graphics/paint/CompositingDisplayItem.h" 39 #include "platform/graphics/paint/CompositingDisplayItem.h"
39 #include "platform/graphics/paint/DisplayItemList.h" 40 #include "platform/graphics/paint/DisplayItemList.h"
40 #include "platform/graphics/paint/DrawingDisplayItem.h" 41 #include "platform/graphics/paint/DrawingDisplayItem.h"
41 #include "platform/graphics/paint/SkPictureBuilder.h" 42 #include "platform/graphics/paint/SkPictureBuilder.h"
42 #include "third_party/skia/include/core/SkPicture.h" 43 #include "third_party/skia/include/core/SkPicture.h"
43 #include "third_party/skia/include/pathops/SkPathOps.h" 44 #include "third_party/skia/include/pathops/SkPathOps.h"
44 45
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 80
80 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) { 81 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) {
81 LayoutObject* childLayoutObject = childElement->layoutObject(); 82 LayoutObject* childLayoutObject = childElement->layoutObject();
82 if (!childLayoutObject) 83 if (!childLayoutObject)
83 continue; 84 continue;
84 // Only shapes or paths are supported for direct clipping. We need to fa llback to masking for texts. 85 // Only shapes or paths are supported for direct clipping. We need to fa llback to masking for texts.
85 if (childLayoutObject->isSVGText()) 86 if (childLayoutObject->isSVGText())
86 return false; 87 return false;
87 if (!childElement->isSVGGraphicsElement()) 88 if (!childElement->isSVGGraphicsElement())
88 continue; 89 continue;
89 SVGGraphicsElement* styled = toSVGGraphicsElement(childElement); 90 SVGGraphicsElement* styled = toSVGGraphicsElement(childElement);
fs 2015/06/22 10:57:44 Could drop this variable, and just use |childEleme
90 const ComputedStyle* style = childLayoutObject->style(); 91 const ComputedStyle* style = childLayoutObject->style();
91 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 92 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
92 continue; 93 continue;
93 const SVGComputedStyle& svgStyle = style->svgStyle(); 94 const SVGComputedStyle& svgStyle = style->svgStyle();
94 // Current shape in clip-path gets clipped too. Fallback to masking. 95 // Current shape in clip-path gets clipped too. Fallback to masking.
95 if (!svgStyle.clipperResource().isEmpty()) 96 if (!svgStyle.clipperResource().isEmpty())
96 return false; 97 return false;
97 98
98 // First clip shape. 99 // First clip shape.
99 if (clipPath.isEmpty()) { 100 if (clipPath.isEmpty()) {
100 styled->toClipPath(clipPath); 101 if (isSVGGeometryElement(styled))
102 toSVGGeometryElement(styled)->toClipPath(clipPath);
103 else if (isSVGUseElement(styled))
104 toSVGUseElement(styled)->toClipPath(clipPath);
101 105
102 continue; 106 continue;
103 } 107 }
104 108
105 // Multiple shapes require PathOps. 109 // Multiple shapes require PathOps.
106 if (!RuntimeEnabledFeatures::pathOpsSVGClippingEnabled()) 110 if (!RuntimeEnabledFeatures::pathOpsSVGClippingEnabled())
107 return false; 111 return false;
108 112
109 // Second clip shape => start using the builder. 113 // Second clip shape => start using the builder.
110 if (!usingBuilder) { 114 if (!usingBuilder) {
111 clipPathBuilder.add(clipPath.skPath(), kUnion_SkPathOp); 115 clipPathBuilder.add(clipPath.skPath(), kUnion_SkPathOp);
112 usingBuilder = true; 116 usingBuilder = true;
113 } 117 }
114 118
115 Path subPath; 119 Path subPath;
116 styled->toClipPath(subPath); 120 if (isSVGGeometryElement(styled))
121 toSVGGeometryElement(styled)->toClipPath(subPath);
122 else if (isSVGUseElement(styled))
123 toSVGUseElement(styled)->toClipPath(subPath);
124
117 clipPathBuilder.add(subPath.skPath(), kUnion_SkPathOp); 125 clipPathBuilder.add(subPath.skPath(), kUnion_SkPathOp);
118 } 126 }
119 127
120 if (usingBuilder) { 128 if (usingBuilder) {
121 SkPath resolvedPath; 129 SkPath resolvedPath;
122 clipPathBuilder.resolve(&resolvedPath); 130 clipPathBuilder.resolve(&resolvedPath);
123 clipPath = resolvedPath; 131 clipPath = resolvedPath;
124 } 132 }
125 133
126 // We are able to represent the clip as a path. Continue with direct clippin g, 134 // We are able to represent the clip as a path. Continue with direct clippin g,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 LayoutObject* layoutObject = childElement->layoutObject(); 180 LayoutObject* layoutObject = childElement->layoutObject();
173 if (!layoutObject) 181 if (!layoutObject)
174 continue; 182 continue;
175 183
176 const ComputedStyle* style = layoutObject->style(); 184 const ComputedStyle* style = layoutObject->style();
177 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 185 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
178 continue; 186 continue;
179 187
180 bool isUseElement = isSVGUseElement(*childElement); 188 bool isUseElement = isSVGUseElement(*childElement);
181 if (isUseElement) { 189 if (isUseElement) {
182 layoutObject = toSVGUseElement(*childElement).layoutObjectClipChild( ); 190 const SVGGraphicsElement* clippingElement = toSVGUseElement(*childEl ement).targetGraphicsElementForClipping();
191 if (!clippingElement) {
192 layoutObject = nullptr;
fs 2015/06/22 10:57:44 This is a dead store (layoutObject will go out of
193 continue;
194 }
195 layoutObject = clippingElement->layoutObject();
183 if (!layoutObject) 196 if (!layoutObject)
184 continue; 197 continue;
185 } 198 }
186 199
187 // Only shapes, paths and texts are allowed for clipping. 200 // Only shapes, paths and texts are allowed for clipping.
188 if (!layoutObject->isSVGShape() && !layoutObject->isSVGText()) 201 if (!layoutObject->isSVGShape() && !layoutObject->isSVGText())
189 continue; 202 continue;
190 203
191 if (isUseElement) 204 if (isUseElement)
192 layoutObject = childElement->layoutObject(); 205 layoutObject = childElement->layoutObject();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 AffineTransform transform; 282 AffineTransform transform;
270 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 283 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
271 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 284 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
272 return transform.mapRect(m_clipBoundaries); 285 return transform.mapRect(m_clipBoundaries);
273 } 286 }
274 287
275 return m_clipBoundaries; 288 return m_clipBoundaries;
276 } 289 }
277 290
278 } 291 }
OLDNEW
« no previous file with comments | « no previous file | Source/core/svg/SVGGeometryElement.h » ('j') | Source/core/svg/SVGUseElement.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698