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 14 matching lines...) Expand all Loading... |
25 #include "core/paint/SVGPaintContext.h" | 25 #include "core/paint/SVGPaintContext.h" |
26 | 26 |
27 #include "core/frame/FrameHost.h" | 27 #include "core/frame/FrameHost.h" |
28 #include "core/layout/svg/LayoutSVGResourceFilter.h" | 28 #include "core/layout/svg/LayoutSVGResourceFilter.h" |
29 #include "core/layout/svg/LayoutSVGResourceMasker.h" | 29 #include "core/layout/svg/LayoutSVGResourceMasker.h" |
30 #include "core/layout/svg/SVGLayoutSupport.h" | 30 #include "core/layout/svg/SVGLayoutSupport.h" |
31 #include "core/layout/svg/SVGResources.h" | 31 #include "core/layout/svg/SVGResources.h" |
32 #include "core/layout/svg/SVGResourcesCache.h" | 32 #include "core/layout/svg/SVGResourcesCache.h" |
33 #include "core/paint/SVGMaskPainter.h" | 33 #include "core/paint/SVGMaskPainter.h" |
34 #include "platform/FloatConversion.h" | 34 #include "platform/FloatConversion.h" |
35 #include "wtf/PtrUtil.h" | |
36 | 35 |
37 namespace blink { | 36 namespace blink { |
38 | 37 |
39 SVGPaintContext::~SVGPaintContext() | 38 SVGPaintContext::~SVGPaintContext() |
40 { | 39 { |
41 if (m_filter) { | 40 if (m_filter) { |
42 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)); | 41 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)); |
43 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->fil
ter() == m_filter); | 42 ASSERT(SVGResourcesCache::cachedResourcesForLayoutObject(&m_object)->fil
ter() == m_filter); |
44 ASSERT(m_filterRecordingContext); | 43 ASSERT(m_filterRecordingContext); |
45 SVGFilterPainter(*m_filter).finishEffect(m_object, *m_filterRecordingCon
text); | 44 SVGFilterPainter(*m_filter).finishEffect(m_object, *m_filterRecordingCon
text); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (!applyClipIfNecessary(resources)) | 82 if (!applyClipIfNecessary(resources)) |
84 return false; | 83 return false; |
85 | 84 |
86 if (!applyMaskIfNecessary(resources)) | 85 if (!applyMaskIfNecessary(resources)) |
87 return false; | 86 return false; |
88 | 87 |
89 if (!applyFilterIfNecessary(resources)) | 88 if (!applyFilterIfNecessary(resources)) |
90 return false; | 89 return false; |
91 | 90 |
92 if (!isIsolationInstalled() && SVGLayoutSupport::isIsolationRequired(&m_obje
ct)) | 91 if (!isIsolationInstalled() && SVGLayoutSupport::isIsolationRequired(&m_obje
ct)) |
93 m_compositingRecorder = wrapUnique(new CompositingRecorder(paintInfo().c
ontext, m_object, SkXfermode::kSrcOver_Mode, 1)); | 92 m_compositingRecorder = adoptPtr(new CompositingRecorder(paintInfo().con
text, m_object, SkXfermode::kSrcOver_Mode, 1)); |
94 | 93 |
95 return true; | 94 return true; |
96 } | 95 } |
97 | 96 |
98 void SVGPaintContext::applyCompositingIfNecessary() | 97 void SVGPaintContext::applyCompositingIfNecessary() |
99 { | 98 { |
100 ASSERT(!paintInfo().isRenderingClipPathAsMaskImage()); | 99 ASSERT(!paintInfo().isRenderingClipPathAsMaskImage()); |
101 | 100 |
102 // Layer takes care of root opacity and blend mode. | 101 // Layer takes care of root opacity and blend mode. |
103 if (m_object.isSVGRoot()) | 102 if (m_object.isSVGRoot()) |
104 return; | 103 return; |
105 | 104 |
106 const ComputedStyle& style = m_object.styleRef(); | 105 const ComputedStyle& style = m_object.styleRef(); |
107 float opacity = style.opacity(); | 106 float opacity = style.opacity(); |
108 WebBlendMode blendMode = style.hasBlendMode() && m_object.isBlendingAllowed(
) ? | 107 WebBlendMode blendMode = style.hasBlendMode() && m_object.isBlendingAllowed(
) ? |
109 style.blendMode() : WebBlendModeNormal; | 108 style.blendMode() : WebBlendModeNormal; |
110 if (opacity < 1 || blendMode != WebBlendModeNormal) { | 109 if (opacity < 1 || blendMode != WebBlendModeNormal) { |
111 const FloatRect compositingBounds = m_object.paintInvalidationRectInLoca
lSVGCoordinates(); | 110 const FloatRect compositingBounds = m_object.paintInvalidationRectInLoca
lSVGCoordinates(); |
112 m_compositingRecorder = wrapUnique(new CompositingRecorder(paintInfo().c
ontext, m_object, | 111 m_compositingRecorder = adoptPtr(new CompositingRecorder(paintInfo().con
text, m_object, |
113 WebCoreCompositeToSkiaComposite(CompositeSourceOver, blendMode), opa
city, &compositingBounds)); | 112 WebCoreCompositeToSkiaComposite(CompositeSourceOver, blendMode), opa
city, &compositingBounds)); |
114 } | 113 } |
115 } | 114 } |
116 | 115 |
117 bool SVGPaintContext::applyClipIfNecessary(SVGResources* resources) | 116 bool SVGPaintContext::applyClipIfNecessary(SVGResources* resources) |
118 { | 117 { |
119 // resources->clipper() corresponds to the non-prefixed 'clip-path' whereas | 118 // resources->clipper() corresponds to the non-prefixed 'clip-path' whereas |
120 // m_object.style()->clipPath() corresponds to '-webkit-clip-path'. | 119 // m_object.style()->clipPath() corresponds to '-webkit-clip-path'. |
121 // FIXME: We should unify the clip-path and -webkit-clip-path codepaths. | 120 // FIXME: We should unify the clip-path and -webkit-clip-path codepaths. |
122 if (LayoutSVGResourceClipper* clipper = resources ? resources->clipper() : n
ullptr) { | 121 if (LayoutSVGResourceClipper* clipper = resources ? resources->clipper() : n
ullptr) { |
123 if (!SVGClipPainter(*clipper).prepareEffect(m_object, m_object.objectBou
ndingBox(), m_object.paintInvalidationRectInLocalSVGCoordinates(), paintInfo().c
ontext, m_clipperState)) | 122 if (!SVGClipPainter(*clipper).prepareEffect(m_object, m_object.objectBou
ndingBox(), m_object.paintInvalidationRectInLocalSVGCoordinates(), paintInfo().c
ontext, m_clipperState)) |
124 return false; | 123 return false; |
125 m_clipper = clipper; | 124 m_clipper = clipper; |
126 } else { | 125 } else { |
127 ClipPathOperation* clipPathOperation = m_object.style()->clipPath(); | 126 ClipPathOperation* clipPathOperation = m_object.style()->clipPath(); |
128 if (clipPathOperation && clipPathOperation->type() == ClipPathOperation:
:SHAPE) { | 127 if (clipPathOperation && clipPathOperation->type() == ClipPathOperation:
:SHAPE) { |
129 ShapeClipPathOperation* clipPath = toShapeClipPathOperation(clipPath
Operation); | 128 ShapeClipPathOperation* clipPath = toShapeClipPathOperation(clipPath
Operation); |
130 if (!clipPath->isValid()) | 129 if (!clipPath->isValid()) |
131 return false; | 130 return false; |
132 m_clipPathRecorder = wrapUnique(new ClipPathRecorder(paintInfo().con
text, m_object, clipPath->path(m_object.objectBoundingBox()))); | 131 m_clipPathRecorder = adoptPtr(new ClipPathRecorder(paintInfo().conte
xt, m_object, clipPath->path(m_object.objectBoundingBox()))); |
133 } | 132 } |
134 } | 133 } |
135 return true; | 134 return true; |
136 } | 135 } |
137 | 136 |
138 bool SVGPaintContext::applyMaskIfNecessary(SVGResources* resources) | 137 bool SVGPaintContext::applyMaskIfNecessary(SVGResources* resources) |
139 { | 138 { |
140 if (LayoutSVGResourceMasker* masker = resources ? resources->masker() : null
ptr) { | 139 if (LayoutSVGResourceMasker* masker = resources ? resources->masker() : null
ptr) { |
141 if (!SVGMaskPainter(*masker).prepareEffect(m_object, paintInfo().context
)) | 140 if (!SVGMaskPainter(*masker).prepareEffect(m_object, paintInfo().context
)) |
142 return false; | 141 return false; |
143 m_masker = masker; | 142 m_masker = masker; |
144 } | 143 } |
145 return true; | 144 return true; |
146 } | 145 } |
147 | 146 |
148 bool SVGPaintContext::applyFilterIfNecessary(SVGResources* resources) | 147 bool SVGPaintContext::applyFilterIfNecessary(SVGResources* resources) |
149 { | 148 { |
150 if (!resources) { | 149 if (!resources) { |
151 if (m_object.style()->svgStyle().hasFilter()) | 150 if (m_object.style()->svgStyle().hasFilter()) |
152 return false; | 151 return false; |
153 } else if (LayoutSVGResourceFilter* filter = resources->filter()) { | 152 } else if (LayoutSVGResourceFilter* filter = resources->filter()) { |
154 m_filterRecordingContext = wrapUnique(new SVGFilterRecordingContext(pain
tInfo().context)); | 153 m_filterRecordingContext = adoptPtr(new SVGFilterRecordingContext(paintI
nfo().context)); |
155 m_filter = filter; | 154 m_filter = filter; |
156 GraphicsContext* filterContext = SVGFilterPainter(*filter).prepareEffect
(m_object, *m_filterRecordingContext); | 155 GraphicsContext* filterContext = SVGFilterPainter(*filter).prepareEffect
(m_object, *m_filterRecordingContext); |
157 if (!filterContext) | 156 if (!filterContext) |
158 return false; | 157 return false; |
159 | 158 |
160 // Because the filter needs to cache its contents we replace the context | 159 // Because the filter needs to cache its contents we replace the context |
161 // during filtering with the filter's context. | 160 // during filtering with the filter's context. |
162 m_filterPaintInfo = wrapUnique(new PaintInfo(*filterContext, m_paintInfo
)); | 161 m_filterPaintInfo = adoptPtr(new PaintInfo(*filterContext, m_paintInfo))
; |
163 | 162 |
164 // Because we cache the filter contents and do not invalidate on paint | 163 // Because we cache the filter contents and do not invalidate on paint |
165 // invalidation rect changes, we need to paint the entire filter region | 164 // invalidation rect changes, we need to paint the entire filter region |
166 // so elements outside the initial paint (due to scrolling, etc) paint. | 165 // so elements outside the initial paint (due to scrolling, etc) paint. |
167 m_filterPaintInfo->m_cullRect.m_rect = LayoutRect::infiniteIntRect(); | 166 m_filterPaintInfo->m_cullRect.m_rect = LayoutRect::infiniteIntRect(); |
168 } | 167 } |
169 return true; | 168 return true; |
170 } | 169 } |
171 | 170 |
172 bool SVGPaintContext::isIsolationInstalled() const | 171 bool SVGPaintContext::isIsolationInstalled() const |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // though. | 222 // though. |
224 // Additionally, it's not really safe/guaranteed to be correct, as | 223 // Additionally, it's not really safe/guaranteed to be correct, as |
225 // something down the paint pipe may want to farther tweak the color | 224 // something down the paint pipe may want to farther tweak the color |
226 // filter, which could yield incorrect results. (Consider just using | 225 // filter, which could yield incorrect results. (Consider just using |
227 // saveLayer() w/ this color filter explicitly instead.) | 226 // saveLayer() w/ this color filter explicitly instead.) |
228 paint.setColorFilter(sk_ref_sp(paintInfo.context.colorFilter())); | 227 paint.setColorFilter(sk_ref_sp(paintInfo.context.colorFilter())); |
229 return true; | 228 return true; |
230 } | 229 } |
231 | 230 |
232 } // namespace blink | 231 } // namespace blink |
OLD | NEW |