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