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

Side by Side Diff: third_party/WebKit/Source/core/paint/SVGPaintContext.cpp

Issue 2322343003: Add support for <basic-shape> to 'clip-path' on SVG elements (Closed)
Patch Set: Update SPv2 expectations Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved. 5 * Copyright (C) 2009 Google, Inc. All rights reserved.
6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 // Reset the paint info after the filter effect has been completed. 47 // Reset the paint info after the filter effect has been completed.
48 m_filterPaintInfo = nullptr; 48 m_filterPaintInfo = nullptr;
49 } 49 }
50 50
51 if (m_masker) { 51 if (m_masker) {
52 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)); 52 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object));
53 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->mas ker() == m_masker); 53 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->mas ker() == m_masker);
54 SVGMaskPainter(*m_masker).finishEffect(m_object, paintInfo().context); 54 SVGMaskPainter(*m_masker).finishEffect(m_object, paintInfo().context);
55 } 55 }
56
57 if (m_clipper) {
58 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object));
59 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->cli pper() == m_clipper);
60 SVGClipPainter(*m_clipper).finishEffect(m_object, paintInfo().context, m _clipperState);
61 }
62 } 56 }
63 57
64 bool SVGPaintContext::applyClipMaskAndFilterIfNecessary() 58 bool SVGPaintContext::applyClipMaskAndFilterIfNecessary()
65 { 59 {
66 #if ENABLE(ASSERT) 60 #if ENABLE(ASSERT)
67 ASSERT(!m_applyClipMaskAndFilterIfNecessaryCalled); 61 ASSERT(!m_applyClipMaskAndFilterIfNecessaryCalled);
68 m_applyClipMaskAndFilterIfNecessaryCalled = true; 62 m_applyClipMaskAndFilterIfNecessaryCalled = true;
69 #endif 63 #endif
70 64
71 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject( &m_object);
72
73 // When rendering clip paths as masks, only geometric operations should be i ncluded so skip 65 // When rendering clip paths as masks, only geometric operations should be i ncluded so skip
74 // non-geometric operations such as compositing, masking, and filtering. 66 // non-geometric operations such as compositing, masking, and filtering.
75 if (paintInfo().isRenderingClipPathAsMaskImage()) { 67 if (paintInfo().isRenderingClipPathAsMaskImage()) {
76 if (!applyClipIfNecessary(resources)) 68 applyClipIfNecessary();
77 return false;
78 return true; 69 return true;
79 } 70 }
80 71
81 bool isSVGRoot = m_object.isSVGRoot(); 72 bool isSVGRoot = m_object.isSVGRoot();
82 73
83 // Layer takes care of root opacity and blend mode. 74 // Layer takes care of root opacity and blend mode.
84 if (isSVGRoot) { 75 if (isSVGRoot) {
85 DCHECK(!(m_object.isTransparent() || m_object.styleRef().hasBlendMode()) || m_object.hasLayer()); 76 DCHECK(!(m_object.isTransparent() || m_object.styleRef().hasBlendMode()) || m_object.hasLayer());
86 } else { 77 } else {
87 applyCompositingIfNecessary(); 78 applyCompositingIfNecessary();
88 } 79 }
89 80
90 if (!applyClipIfNecessary(resources)) 81 applyClipIfNecessary();
91 return false; 82
83 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject( &m_object);
92 84
93 if (!applyMaskIfNecessary(resources)) 85 if (!applyMaskIfNecessary(resources))
94 return false; 86 return false;
95 87
96 if (isSVGRoot) { 88 if (isSVGRoot) {
97 DCHECK(!m_object.styleRef().hasFilter() || m_object.hasLayer()); 89 DCHECK(!m_object.styleRef().hasFilter() || m_object.hasLayer());
98 } else if (!applyFilterIfNecessary(resources)) { 90 } else if (!applyFilterIfNecessary(resources)) {
99 return false; 91 return false;
100 } 92 }
101 93
(...skipping 11 matching lines...) Expand all
113 float opacity = style.opacity(); 105 float opacity = style.opacity();
114 WebBlendMode blendMode = style.hasBlendMode() && m_object.isBlendingAllowed( ) ? 106 WebBlendMode blendMode = style.hasBlendMode() && m_object.isBlendingAllowed( ) ?
115 style.blendMode() : WebBlendModeNormal; 107 style.blendMode() : WebBlendModeNormal;
116 if (opacity < 1 || blendMode != WebBlendModeNormal) { 108 if (opacity < 1 || blendMode != WebBlendModeNormal) {
117 const FloatRect compositingBounds = m_object.paintInvalidationRectInLoca lSVGCoordinates(); 109 const FloatRect compositingBounds = m_object.paintInvalidationRectInLoca lSVGCoordinates();
118 m_compositingRecorder = wrapUnique(new CompositingRecorder(paintInfo().c ontext, m_object, 110 m_compositingRecorder = wrapUnique(new CompositingRecorder(paintInfo().c ontext, m_object,
119 WebCoreCompositeToSkiaComposite(CompositeSourceOver, blendMode), opa city, &compositingBounds)); 111 WebCoreCompositeToSkiaComposite(CompositeSourceOver, blendMode), opa city, &compositingBounds));
120 } 112 }
121 } 113 }
122 114
123 bool SVGPaintContext::applyClipIfNecessary(SVGResources* resources) 115 void SVGPaintContext::applyClipIfNecessary()
124 { 116 {
125 // resources->clipper() corresponds to the non-prefixed 'clip-path' whereas 117 ClipPathOperation* clipPathOperation = m_object.styleRef().svgStyle().clipPa th();
126 // m_object.style()->clipPath() corresponds to '-webkit-clip-path'. 118 // If no 'clip-path' is specified, try '-webkit-clip-path'.
127 // FIXME: We should unify the clip-path and -webkit-clip-path codepaths. 119 if (!clipPathOperation) {
128 if (LayoutSVGResourceClipper* clipper = resources ? resources->clipper() : n ullptr) { 120 clipPathOperation = m_object.styleRef().clipPath();
129 if (!SVGClipPainter(*clipper).prepareEffect(m_object, m_object.objectBou ndingBox(), 121 // We don't support URL references in '-webkit-clip-path'.
130 m_object.paintInvalidationRectInLocalSVGCoordinates(), FloatPoint(), paintInfo().context, m_clipperState)) 122 if (clipPathOperation && clipPathOperation->type() == ClipPathOperation: :REFERENCE)
131 return false; 123 clipPathOperation = nullptr;
132 m_clipper = clipper;
133 } else {
134 ClipPathOperation* clipPathOperation = m_object.style()->clipPath();
135 if (clipPathOperation && clipPathOperation->type() == ClipPathOperation: :SHAPE) {
136 ShapeClipPathOperation* clipPath = toShapeClipPathOperation(clipPath Operation);
137 if (!clipPath->isValid())
138 return false;
139 m_clipPathRecorder = wrapUnique(new ClipPathRecorder(paintInfo().con text, m_object, clipPath->path(m_object.objectBoundingBox())));
140 }
141 } 124 }
142 return true; 125 if (!clipPathOperation)
126 return;
127 m_clipPathClipper.emplace(paintInfo().context, *clipPathOperation, m_object, m_object.objectBoundingBox(), FloatPoint());
143 } 128 }
144 129
145 bool SVGPaintContext::applyMaskIfNecessary(SVGResources* resources) 130 bool SVGPaintContext::applyMaskIfNecessary(SVGResources* resources)
146 { 131 {
147 if (LayoutSVGResourceMasker* masker = resources ? resources->masker() : null ptr) { 132 if (LayoutSVGResourceMasker* masker = resources ? resources->masker() : null ptr) {
148 if (!SVGMaskPainter(*masker).prepareEffect(m_object, paintInfo().context )) 133 if (!SVGMaskPainter(*masker).prepareEffect(m_object, paintInfo().context ))
149 return false; 134 return false;
150 m_masker = masker; 135 m_masker = masker;
151 } 136 }
152 return true; 137 return true;
(...skipping 22 matching lines...) Expand all
175 } 160 }
176 return true; 161 return true;
177 } 162 }
178 163
179 bool SVGPaintContext::isIsolationInstalled() const 164 bool SVGPaintContext::isIsolationInstalled() const
180 { 165 {
181 if (m_compositingRecorder) 166 if (m_compositingRecorder)
182 return true; 167 return true;
183 if (m_masker || m_filter) 168 if (m_masker || m_filter)
184 return true; 169 return true;
185 if (m_clipper && m_clipperState == SVGClipPainter::ClipperAppliedMask) 170 if (m_clipPathClipper && m_clipPathClipper->usingMask())
186 return true; 171 return true;
187 return false; 172 return false;
188 } 173 }
189 174
190 void SVGPaintContext::paintSubtree(GraphicsContext& context, const LayoutObject* item) 175 void SVGPaintContext::paintSubtree(GraphicsContext& context, const LayoutObject* item)
191 { 176 {
192 ASSERT(item); 177 ASSERT(item);
193 ASSERT(!item->needsLayout()); 178 ASSERT(!item->needsLayout());
194 179
195 PaintInfo info(context, LayoutRect::infiniteIntRect(), PaintPhaseForeground, GlobalPaintNormalPhase, PaintLayerNoFlag); 180 PaintInfo info(context, LayoutRect::infiniteIntRect(), PaintPhaseForeground, GlobalPaintNormalPhase, PaintLayerNoFlag);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // though. 215 // though.
231 // Additionally, it's not really safe/guaranteed to be correct, as 216 // Additionally, it's not really safe/guaranteed to be correct, as
232 // something down the paint pipe may want to farther tweak the color 217 // something down the paint pipe may want to farther tweak the color
233 // filter, which could yield incorrect results. (Consider just using 218 // filter, which could yield incorrect results. (Consider just using
234 // saveLayer() w/ this color filter explicitly instead.) 219 // saveLayer() w/ this color filter explicitly instead.)
235 paint.setColorFilter(sk_ref_sp(paintInfo.context.getColorFilter())); 220 paint.setColorFilter(sk_ref_sp(paintInfo.context.getColorFilter()));
236 return true; 221 return true;
237 } 222 }
238 223
239 } // namespace blink 224 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/SVGPaintContext.h ('k') | third_party/WebKit/Source/core/style/SVGComputedStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698