OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
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. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "core/rendering/svg/RenderSVGResource.h" | 24 #include "core/rendering/svg/RenderSVGResource.h" |
25 | 25 |
26 #include "core/rendering/svg/RenderSVGResourceClipper.h" | 26 #include "core/rendering/svg/RenderSVGResourceClipper.h" |
27 #include "core/rendering/svg/RenderSVGResourceFilter.h" | 27 #include "core/rendering/svg/RenderSVGResourceFilter.h" |
28 #include "core/rendering/svg/RenderSVGResourceMasker.h" | 28 #include "core/rendering/svg/RenderSVGResourceMasker.h" |
29 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" | |
30 #include "core/rendering/svg/SVGRenderSupport.h" | |
31 #include "core/rendering/svg/SVGResources.h" | 29 #include "core/rendering/svg/SVGResources.h" |
32 #include "core/rendering/svg/SVGResourcesCache.h" | 30 #include "core/rendering/svg/SVGResourcesCache.h" |
33 #include "platform/graphics/GraphicsContext.h" | 31 #include "platform/graphics/GraphicsContext.h" |
34 #include "platform/graphics/GraphicsContextStateSaver.h" | 32 #include "platform/graphics/GraphicsContextStateSaver.h" |
35 | 33 |
36 namespace blink { | 34 namespace blink { |
37 | 35 |
38 SVGPaintServer::SVGPaintServer(Color color) | 36 SVGPaintServer::SVGPaintServer(Color color) |
39 : m_color(color) | 37 : m_color(color) |
40 { | 38 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT
ransform()); | 80 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT
ransform()); |
83 else | 81 else |
84 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp
aceTransform()); | 82 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp
aceTransform()); |
85 } | 83 } |
86 | 84 |
87 SVGPaintServer SVGPaintServer::requestForRenderer(const RenderObject& renderer,
const RenderStyle* style, RenderSVGResourceMode resourceMode) | 85 SVGPaintServer SVGPaintServer::requestForRenderer(const RenderObject& renderer,
const RenderStyle* style, RenderSVGResourceMode resourceMode) |
88 { | 86 { |
89 ASSERT(style); | 87 ASSERT(style); |
90 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode)
; | 88 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode)
; |
91 | 89 |
92 bool hasFallback = false; | 90 RenderSVGResource::PaintDescription paintDescription = RenderSVGResource::re
questPaint(resourceMode, renderer, style); |
93 RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingReso
urce(resourceMode, renderer, style, hasFallback); | 91 if (!paintDescription.isValid) |
94 if (!paintingResource) | |
95 return invalid(); | 92 return invalid(); |
96 | 93 if (!paintDescription.resource) |
97 SVGPaintServer paintServer = paintingResource->preparePaintServer(renderer); | 94 return SVGPaintServer(paintDescription.color); |
| 95 SVGPaintServer paintServer = paintDescription.resource->preparePaintServer(r
enderer); |
98 if (paintServer.isValid()) | 96 if (paintServer.isValid()) |
99 return paintServer; | 97 return paintServer; |
100 if (hasFallback) | 98 if (paintDescription.hasFallback) |
101 return SVGPaintServer(RenderSVGResource::sharedSolidPaintingResource()->
color()); | 99 return SVGPaintServer(paintDescription.color); |
102 return invalid(); | 100 return invalid(); |
103 } | 101 } |
104 | 102 |
105 SVGPaintServer RenderSVGResource::preparePaintServer(const RenderObject&) | 103 SVGPaintServer RenderSVGResource::preparePaintServer(const RenderObject&) |
106 { | 104 { |
107 ASSERT_NOT_REACHED(); | 105 ASSERT_NOT_REACHED(); |
108 return SVGPaintServer::invalid(); | 106 return SVGPaintServer::invalid(); |
109 } | 107 } |
110 | 108 |
111 RenderSVGResource* RenderSVGResource::requestPaintingResource(RenderSVGResourceM
ode mode, const RenderObject& object, const RenderStyle* style, bool& hasFallbac
k) | 109 RenderSVGResource::PaintDescription RenderSVGResource::requestPaint(RenderSVGRes
ourceMode mode, const RenderObject& object, const RenderStyle* style) |
112 { | 110 { |
113 ASSERT(style); | 111 ASSERT(style); |
114 | 112 |
115 hasFallback = false; | |
116 | |
117 // If we have no style at all, ignore it. | 113 // If we have no style at all, ignore it. |
118 const SVGRenderStyle& svgStyle = style->svgStyle(); | 114 const SVGRenderStyle& svgStyle = style->svgStyle(); |
119 | 115 |
120 // If we have no fill/stroke, return 0. | 116 // If we have no fill/stroke, return 0. |
121 if (mode == ApplyToFillMode) { | 117 if (mode == ApplyToFillMode) { |
122 if (!svgStyle.hasFill()) | 118 if (!svgStyle.hasFill()) |
123 return 0; | 119 return PaintDescription(); |
124 } else { | 120 } else { |
125 if (!svgStyle.hasStroke()) | 121 if (!svgStyle.hasStroke()) |
126 return 0; | 122 return PaintDescription(); |
127 } | 123 } |
128 | 124 |
129 bool applyToFill = mode == ApplyToFillMode; | 125 bool applyToFill = mode == ApplyToFillMode; |
130 SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.s
trokePaintType(); | 126 SVGPaintType paintType = applyToFill ? svgStyle.fillPaintType() : svgStyle.s
trokePaintType(); |
131 ASSERT(paintType != SVG_PAINTTYPE_NONE); | 127 ASSERT(paintType != SVG_PAINTTYPE_NONE); |
132 | 128 |
133 Color color; | 129 Color color; |
134 bool hasColor = false; | 130 bool hasColor = false; |
135 switch (paintType) { | 131 switch (paintType) { |
136 case SVG_PAINTTYPE_CURRENTCOLOR: | 132 case SVG_PAINTTYPE_CURRENTCOLOR: |
(...skipping 12 matching lines...) Expand all Loading... |
149 | 145 |
150 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited
Color'. | 146 // For SVG_PAINTTYPE_CURRENTCOLOR, 'color' already contains the 'visited
Color'. |
151 if (visitedPaintType < SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVG
_PAINTTYPE_CURRENTCOLOR) { | 147 if (visitedPaintType < SVG_PAINTTYPE_URI_NONE && visitedPaintType != SVG
_PAINTTYPE_CURRENTCOLOR) { |
152 const Color& visitedColor = applyToFill ? svgStyle.visitedLinkFillPa
intColor() : svgStyle.visitedLinkStrokePaintColor(); | 148 const Color& visitedColor = applyToFill ? svgStyle.visitedLinkFillPa
intColor() : svgStyle.visitedLinkStrokePaintColor(); |
153 color = Color(visitedColor.red(), visitedColor.green(), visitedColor
.blue(), color.alpha()); | 149 color = Color(visitedColor.red(), visitedColor.green(), visitedColor
.blue(), color.alpha()); |
154 hasColor = true; | 150 hasColor = true; |
155 } | 151 } |
156 } | 152 } |
157 | 153 |
158 // If the primary resource is just a color, return immediately. | 154 // If the primary resource is just a color, return immediately. |
159 RenderSVGResourceSolidColor* colorResource = RenderSVGResource::sharedSolidP
aintingResource(); | |
160 if (paintType < SVG_PAINTTYPE_URI_NONE) { | 155 if (paintType < SVG_PAINTTYPE_URI_NONE) { |
161 // |paintType| will be either <current-color> or <rgb-color> here - both
of which will have a color. | 156 // |paintType| will be either <current-color> or <rgb-color> here - both
of which will have a color. |
162 ASSERT(hasColor); | 157 ASSERT(hasColor); |
163 colorResource->setColor(color); | 158 return PaintDescription(color); |
164 return colorResource; | |
165 } | 159 } |
166 | 160 |
167 RenderSVGResource* uriResource = 0; | 161 RenderSVGResource* uriResource = 0; |
168 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(&object)) | 162 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(&object)) |
169 uriResource = applyToFill ? resources->fill() : resources->stroke(); | 163 uriResource = applyToFill ? resources->fill() : resources->stroke(); |
170 | 164 |
171 // If the requested resource is not available, return the color resource or
'none'. | 165 // If the requested resource is not available, return the color resource or
'none'. |
172 if (!uriResource) { | 166 if (!uriResource) { |
173 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback
is specified.) | 167 // The fallback is 'none'. (SVG2 say 'none' is implied when no fallback
is specified.) |
174 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor) | 168 if (paintType == SVG_PAINTTYPE_URI_NONE || !hasColor) |
175 return 0; | 169 return PaintDescription(); |
176 | 170 |
177 colorResource->setColor(color); | 171 return PaintDescription(color); |
178 return colorResource; | |
179 } | 172 } |
180 | 173 |
181 // The paint server resource exists, though it may be invalid (pattern with
width/height=0). Pass the fallback color to our caller | 174 // The paint server resource exists, though it may be invalid (pattern with
width/height=0). |
182 // via sharedSolidPaintingResource so it can use the solid color painting re
source, if applyResource() on the URI resource failed. | 175 // Return the fallback color to our caller so it can use it, if |
183 if (hasColor) { | 176 // preparePaintServer() on the resource container failed. |
184 colorResource->setColor(color); | 177 if (hasColor) |
185 hasFallback = true; | 178 return PaintDescription(uriResource, color); |
186 } | |
187 return uriResource; | |
188 } | |
189 | 179 |
190 RenderSVGResourceSolidColor* RenderSVGResource::sharedSolidPaintingResource() | 180 return PaintDescription(uriResource); |
191 { | |
192 static RenderSVGResourceSolidColor* s_sharedSolidPaintingResource = 0; | |
193 if (!s_sharedSolidPaintingResource) | |
194 s_sharedSolidPaintingResource = new RenderSVGResourceSolidColor; | |
195 return s_sharedSolidPaintingResource; | |
196 } | 181 } |
197 | 182 |
198 static inline void removeFromCacheAndInvalidateDependencies(RenderObject* object
, bool needsLayout) | 183 static inline void removeFromCacheAndInvalidateDependencies(RenderObject* object
, bool needsLayout) |
199 { | 184 { |
200 ASSERT(object); | 185 ASSERT(object); |
201 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(object)) { | 186 if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObj
ect(object)) { |
202 if (RenderSVGResourceFilter* filter = resources->filter()) | 187 if (RenderSVGResourceFilter* filter = resources->filter()) |
203 filter->removeClientFromCache(object); | 188 filter->removeClientFromCache(object); |
204 | 189 |
205 if (RenderSVGResourceMasker* masker = resources->masker()) | 190 if (RenderSVGResourceMasker* masker = resources->masker()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // This will process the rest of the ancestors. | 240 // This will process the rest of the ancestors. |
256 toRenderSVGResourceContainer(current)->removeAllClientsFromCache(); | 241 toRenderSVGResourceContainer(current)->removeAllClientsFromCache(); |
257 break; | 242 break; |
258 } | 243 } |
259 | 244 |
260 current = current->parent(); | 245 current = current->parent(); |
261 } | 246 } |
262 } | 247 } |
263 | 248 |
264 } | 249 } |
OLD | NEW |