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

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

Issue 1512803004: Use refs for GraphicsContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Created 5 years 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 21 matching lines...) Expand all
32 #include "core/layout/svg/SVGResources.h" 32 #include "core/layout/svg/SVGResources.h"
33 #include "core/layout/svg/SVGResourcesCache.h" 33 #include "core/layout/svg/SVGResourcesCache.h"
34 #include "core/paint/SVGMaskPainter.h" 34 #include "core/paint/SVGMaskPainter.h"
35 #include "platform/FloatConversion.h" 35 #include "platform/FloatConversion.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 SVGPaintContext::~SVGPaintContext() 39 SVGPaintContext::~SVGPaintContext()
40 { 40 {
41 if (m_filter) { 41 if (m_filter) {
42 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(m_object)); 42 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object));
43 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(m_object)->filt er() == m_filter); 43 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->fil ter() == m_filter);
44 ASSERT(m_filterRecordingContext); 44 ASSERT(m_filterRecordingContext);
45 SVGFilterPainter(*m_filter).finishEffect(*m_object, *m_filterRecordingCo ntext); 45 SVGFilterPainter(*m_filter).finishEffect(m_object, *m_filterRecordingCon text);
46 46 m_filterPaintInfo = nullptr;
47 // Reset the paint info after the filter effect has been completed.
Xianzhu 2015/12/10 16:55:36 The next patch set will restore the above line of
48 // This isn't strictly required (e.g., m_paintInfo.rect is not used
49 // after this).
50 m_paintInfo.context = m_originalPaintInfo->context;
51 m_paintInfo.m_cullRect.m_rect = m_originalPaintInfo->m_cullRect.m_rect;
52 } 47 }
53 48
54 if (m_masker) { 49 if (m_masker) {
55 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(m_object)); 50 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object));
56 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(m_object)->mask er() == m_masker); 51 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->mas ker() == m_masker);
57 SVGMaskPainter(*m_masker).finishEffect(*m_object, m_paintInfo.context); 52 SVGMaskPainter(*m_masker).finishEffect(m_object, paintInfo().context);
58 } 53 }
59 54
60 if (m_clipper) { 55 if (m_clipper) {
61 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(m_object)); 56 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object));
62 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(m_object)->clip per() == m_clipper); 57 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->cli pper() == m_clipper);
63 SVGClipPainter(*m_clipper).finishEffect(*m_object, m_paintInfo.context, m_clipperState); 58 SVGClipPainter(*m_clipper).finishEffect(m_object, paintInfo().context, m _clipperState);
64 } 59 }
65 } 60 }
66 61
67 bool SVGPaintContext::applyClipMaskAndFilterIfNecessary() 62 bool SVGPaintContext::applyClipMaskAndFilterIfNecessary()
68 { 63 {
69 #if ENABLE(ASSERT) 64 #if ENABLE(ASSERT)
70 ASSERT(!m_applyClipMaskAndFilterIfNecessaryCalled); 65 ASSERT(!m_applyClipMaskAndFilterIfNecessaryCalled);
71 m_applyClipMaskAndFilterIfNecessaryCalled = true; 66 m_applyClipMaskAndFilterIfNecessaryCalled = true;
72 #endif 67 #endif
73 68
74 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject( m_object); 69 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObject( &m_object);
75 70
76 // When rendering clip paths as masks, only geometric operations should be i ncluded so skip 71 // When rendering clip paths as masks, only geometric operations should be i ncluded so skip
77 // non-geometric operations such as compositing, masking, and filtering. 72 // non-geometric operations such as compositing, masking, and filtering.
78 if (m_paintInfo.isRenderingClipPathAsMaskImage()) { 73 if (paintInfo().isRenderingClipPathAsMaskImage()) {
79 if (!applyClipIfNecessary(resources)) 74 if (!applyClipIfNecessary(resources))
80 return false; 75 return false;
81 return true; 76 return true;
82 } 77 }
83 78
84 applyCompositingIfNecessary(); 79 applyCompositingIfNecessary();
85 80
86 if (!applyClipIfNecessary(resources)) 81 if (!applyClipIfNecessary(resources))
87 return false; 82 return false;
88 83
89 if (!applyMaskIfNecessary(resources)) 84 if (!applyMaskIfNecessary(resources))
90 return false; 85 return false;
91 86
92 if (!applyFilterIfNecessary(resources)) 87 if (!applyFilterIfNecessary(resources))
93 return false; 88 return false;
94 89
95 if (!isIsolationInstalled() && SVGLayoutSupport::isIsolationRequired(m_objec t)) 90 if (!isIsolationInstalled() && SVGLayoutSupport::isIsolationRequired(&m_obje ct))
96 m_compositingRecorder = adoptPtr(new CompositingRecorder(*m_paintInfo.co ntext, *m_object, SkXfermode::kSrcOver_Mode, 1)); 91 m_compositingRecorder = adoptPtr(new CompositingRecorder(paintInfo().con text, m_object, SkXfermode::kSrcOver_Mode, 1));
97 92
98 return true; 93 return true;
99 } 94 }
100 95
101 void SVGPaintContext::applyCompositingIfNecessary() 96 void SVGPaintContext::applyCompositingIfNecessary()
102 { 97 {
103 ASSERT(!m_paintInfo.isRenderingClipPathAsMaskImage()); 98 ASSERT(!paintInfo().isRenderingClipPathAsMaskImage());
104 99
105 // Layer takes care of root opacity and blend mode. 100 // Layer takes care of root opacity and blend mode.
106 if (m_object->isSVGRoot()) 101 if (m_object.isSVGRoot())
107 return; 102 return;
108 103
109 const ComputedStyle& style = m_object->styleRef(); 104 const ComputedStyle& style = m_object.styleRef();
110 float opacity = style.opacity(); 105 float opacity = style.opacity();
111 WebBlendMode blendMode = style.hasBlendMode() && m_object->isBlendingAllowed () ? 106 WebBlendMode blendMode = style.hasBlendMode() && m_object.isBlendingAllowed( ) ?
112 style.blendMode() : WebBlendModeNormal; 107 style.blendMode() : WebBlendModeNormal;
113 if (opacity < 1 || blendMode != WebBlendModeNormal) { 108 if (opacity < 1 || blendMode != WebBlendModeNormal) {
114 const FloatRect compositingBounds = m_object->paintInvalidationRectInLoc alCoordinates(); 109 const FloatRect compositingBounds = m_object.paintInvalidationRectInLoca lCoordinates();
115 m_compositingRecorder = adoptPtr(new CompositingRecorder(*m_paintInfo.co ntext, *m_object, 110 m_compositingRecorder = adoptPtr(new CompositingRecorder(paintInfo().con text, m_object,
116 WebCoreCompositeToSkiaComposite(CompositeSourceOver, blendMode), opa city, &compositingBounds)); 111 WebCoreCompositeToSkiaComposite(CompositeSourceOver, blendMode), opa city, &compositingBounds));
117 } 112 }
118 } 113 }
119 114
120 bool SVGPaintContext::applyClipIfNecessary(SVGResources* resources) 115 bool SVGPaintContext::applyClipIfNecessary(SVGResources* resources)
121 { 116 {
122 // resources->clipper() corresponds to the non-prefixed 'clip-path' whereas 117 // resources->clipper() corresponds to the non-prefixed 'clip-path' whereas
123 // m_object->style()->clipPath() corresponds to '-webkit-clip-path'. 118 // m_object.style()->clipPath() corresponds to '-webkit-clip-path'.
124 // FIXME: We should unify the clip-path and -webkit-clip-path codepaths. 119 // FIXME: We should unify the clip-path and -webkit-clip-path codepaths.
125 if (LayoutSVGResourceClipper* clipper = resources ? resources->clipper() : n ullptr) { 120 if (LayoutSVGResourceClipper* clipper = resources ? resources->clipper() : n ullptr) {
126 if (!SVGClipPainter(*clipper).prepareEffect(*m_object, m_object->objectB oundingBox(), m_object->paintInvalidationRectInLocalCoordinates(), m_paintInfo.c ontext, m_clipperState)) 121 if (!SVGClipPainter(*clipper).prepareEffect(m_object, m_object.objectBou ndingBox(), m_object.paintInvalidationRectInLocalCoordinates(), paintInfo().cont ext, m_clipperState))
127 return false; 122 return false;
128 m_clipper = clipper; 123 m_clipper = clipper;
129 } else { 124 } else {
130 ClipPathOperation* clipPathOperation = m_object->style()->clipPath(); 125 ClipPathOperation* clipPathOperation = m_object.style()->clipPath();
131 if (clipPathOperation && clipPathOperation->type() == ClipPathOperation: :SHAPE) { 126 if (clipPathOperation && clipPathOperation->type() == ClipPathOperation: :SHAPE) {
132 ShapeClipPathOperation* clipPath = toShapeClipPathOperation(clipPath Operation); 127 ShapeClipPathOperation* clipPath = toShapeClipPathOperation(clipPath Operation);
133 if (!clipPath->isValid()) 128 if (!clipPath->isValid())
134 return false; 129 return false;
135 m_clipPathRecorder = adoptPtr(new ClipPathRecorder(*m_paintInfo.cont ext, *m_object, clipPath->path(m_object->objectBoundingBox()))); 130 m_clipPathRecorder = adoptPtr(new ClipPathRecorder(paintInfo().conte xt, m_object, clipPath->path(m_object.objectBoundingBox())));
136 } 131 }
137 } 132 }
138 return true; 133 return true;
139 } 134 }
140 135
141 bool SVGPaintContext::applyMaskIfNecessary(SVGResources* resources) 136 bool SVGPaintContext::applyMaskIfNecessary(SVGResources* resources)
142 { 137 {
143 if (LayoutSVGResourceMasker* masker = resources ? resources->masker() : null ptr) { 138 if (LayoutSVGResourceMasker* masker = resources ? resources->masker() : null ptr) {
144 if (!SVGMaskPainter(*masker).prepareEffect(*m_object, m_paintInfo.contex t)) 139 if (!SVGMaskPainter(*masker).prepareEffect(m_object, paintInfo().context ))
145 return false; 140 return false;
146 m_masker = masker; 141 m_masker = masker;
147 } 142 }
148 return true; 143 return true;
149 } 144 }
150 145
151 bool SVGPaintContext::applyFilterIfNecessary(SVGResources* resources) 146 bool SVGPaintContext::applyFilterIfNecessary(SVGResources* resources)
152 { 147 {
153 if (!resources) { 148 if (!resources) {
154 if (m_object->style()->svgStyle().hasFilter()) 149 if (m_object.style()->svgStyle().hasFilter())
155 return false; 150 return false;
156 } else if (LayoutSVGResourceFilter* filter = resources->filter()) { 151 } else if (LayoutSVGResourceFilter* filter = resources->filter()) {
157 m_filterRecordingContext = adoptPtr(new SVGFilterRecordingContext(m_pain tInfo.context)); 152 m_filterRecordingContext = adoptPtr(new SVGFilterRecordingContext(paintI nfo().context));
158 m_filter = filter; 153 m_filter = filter;
159 GraphicsContext* filterContext = SVGFilterPainter(*filter).prepareEffect (*m_object, *m_filterRecordingContext); 154 GraphicsContext* filterContext = SVGFilterPainter(*filter).prepareEffect (m_object, *m_filterRecordingContext);
160 if (!filterContext) 155 if (!filterContext)
161 return false; 156 return false;
162 157
163 // Because the filter needs to cache its contents we replace the context 158 // Because the filter needs to cache its contents we replace the context
164 // during filtering with the filter's context. 159 // during filtering with the filter's context.
165 m_paintInfo.context = filterContext; 160 m_filterPaintInfo = adoptPtr(new PaintInfo(*filterContext, m_paintInfo)) ;
166 161
167 // Because we cache the filter contents and do not invalidate on paint 162 // Because we cache the filter contents and do not invalidate on paint
168 // invalidation rect changes, we need to paint the entire filter region 163 // invalidation rect changes, we need to paint the entire filter region
169 // so elements outside the initial paint (due to scrolling, etc) paint. 164 // so elements outside the initial paint (due to scrolling, etc) paint.
170 m_paintInfo.m_cullRect.m_rect = LayoutRect::infiniteIntRect(); 165 m_filterPaintInfo->m_cullRect.m_rect = LayoutRect::infiniteIntRect();
171 } 166 }
172 return true; 167 return true;
173 } 168 }
174 169
175 bool SVGPaintContext::isIsolationInstalled() const 170 bool SVGPaintContext::isIsolationInstalled() const
176 { 171 {
177 if (m_compositingRecorder) 172 if (m_compositingRecorder)
178 return true; 173 return true;
179 if (m_masker || m_filter) 174 if (m_masker || m_filter)
180 return true; 175 return true;
181 if (m_clipper && m_clipperState == SVGClipPainter::ClipperAppliedMask) 176 if (m_clipper && m_clipperState == SVGClipPainter::ClipperAppliedMask)
182 return true; 177 return true;
183 return false; 178 return false;
184 } 179 }
185 180
186 void SVGPaintContext::paintSubtree(GraphicsContext* context, const LayoutObject* item) 181 void SVGPaintContext::paintSubtree(GraphicsContext& context, const LayoutObject* item)
187 { 182 {
188 ASSERT(context);
189 ASSERT(item); 183 ASSERT(item);
190 ASSERT(!item->needsLayout()); 184 ASSERT(!item->needsLayout());
191 185
192 PaintInfo info(context, LayoutRect::infiniteIntRect(), PaintPhaseForeground, GlobalPaintNormalPhase, PaintLayerNoFlag); 186 PaintInfo info(context, LayoutRect::infiniteIntRect(), PaintPhaseForeground, GlobalPaintNormalPhase, PaintLayerNoFlag);
193 item->paint(info, IntPoint()); 187 item->paint(info, IntPoint());
194 } 188 }
195 189
196 bool SVGPaintContext::paintForLayoutObject(const PaintInfo& paintInfo, const Com putedStyle& style, const LayoutObject& layoutObject, LayoutSVGResourceMode resou rceMode, SkPaint& paint, const AffineTransform* additionalPaintServerTransform) 190 bool SVGPaintContext::paintForLayoutObject(const PaintInfo& paintInfo, const Com putedStyle& style, const LayoutObject& layoutObject, LayoutSVGResourceMode resou rceMode, SkPaint& paint, const AffineTransform* additionalPaintServerTransform)
197 { 191 {
198 if (paintInfo.isRenderingClipPathAsMaskImage()) { 192 if (paintInfo.isRenderingClipPathAsMaskImage()) {
(...skipping 23 matching lines...) Expand all
222 // TODO(fs): The color filter can set when generating a picture for a mask - 216 // TODO(fs): The color filter can set when generating a picture for a mask -
223 // due to color-interpolation. We could also just apply the 217 // due to color-interpolation. We could also just apply the
224 // color-interpolation property from the the shape itself (which could mean 218 // color-interpolation property from the the shape itself (which could mean
225 // the paintserver if it has it specified), since that would be more in line 219 // the paintserver if it has it specified), since that would be more in line
226 // with the spec for color-interpolation. For now, just steal it from the GC 220 // with the spec for color-interpolation. For now, just steal it from the GC
227 // though. 221 // though.
228 // Additionally, it's not really safe/guaranteed to be correct, as 222 // Additionally, it's not really safe/guaranteed to be correct, as
229 // something down the paint pipe may want to farther tweak the color 223 // something down the paint pipe may want to farther tweak the color
230 // filter, which could yield incorrect results. (Consider just using 224 // filter, which could yield incorrect results. (Consider just using
231 // saveLayer() w/ this color filter explicitly instead.) 225 // saveLayer() w/ this color filter explicitly instead.)
232 paint.setColorFilter(paintInfo.context->colorFilter()); 226 paint.setColorFilter(paintInfo.context.colorFilter());
233 return true; 227 return true;
234 } 228 }
235 229
236 } // namespace blink 230 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698