OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/paint/SVGPaintServer.h" | |
7 | |
8 #include "core/rendering/style/RenderStyle.h" | |
9 #include "core/rendering/style/SVGRenderStyle.h" | |
10 #include "core/rendering/svg/RenderSVGResourceSolidColor.h" | |
11 #include "core/rendering/svg/SVGRenderSupport.h" | |
12 #include "platform/graphics/GraphicsContext.h" | |
13 #include "platform/graphics/GraphicsContextStateSaver.h" | |
14 | |
15 namespace blink { | |
16 | |
17 SVGPaintServer::SVGPaintServer() | |
18 : m_color(Color::black) | |
19 { | |
20 } | |
21 | |
22 void SVGPaintServer::setColor(Color color) | |
23 { | |
24 m_gradient.clear(); | |
25 m_pattern.clear(); | |
26 m_color = color; | |
27 } | |
28 | |
29 void SVGPaintServer::setGradient(const PassRefPtr<Gradient> gradient) | |
30 { | |
31 m_gradient = gradient; | |
32 m_pattern.clear(); | |
33 m_color = Color::black; | |
34 } | |
35 | |
36 void SVGPaintServer::setPattern(const PassRefPtr<Pattern> pattern) | |
37 { | |
38 m_gradient.clear(); | |
39 m_pattern = pattern; | |
40 m_color = Color::black; | |
41 } | |
42 | |
43 void SVGPaintServer::apply(GraphicsContext& context, RenderSVGResourceMode resou rceMode, GraphicsContextStateSaver* stateSaver) | |
44 { | |
45 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; | |
46 if (stateSaver && (m_gradient || m_pattern)) | |
47 stateSaver->saveIfNeeded(); | |
48 | |
49 if (resourceMode == ApplyToFillMode) { | |
50 if (m_pattern) | |
51 context.setFillPattern(m_pattern); | |
52 else if (m_gradient) | |
53 context.setFillGradient(m_gradient); | |
54 else | |
55 context.setFillColor(m_color); | |
56 } else { | |
57 if (m_pattern) | |
58 context.setStrokePattern(m_pattern); | |
59 else if (m_gradient) | |
60 context.setStrokeGradient(m_gradient); | |
61 else | |
62 context.setStrokeColor(m_color); | |
63 } | |
64 } | |
65 | |
66 bool SVGPaintServer::requestForRenderer(RenderObject& renderer, RenderStyle* sty le, RenderSVGResourceModeFlags resourceModeFlags, SVGPaintServer& paintServer) | |
pdr.
2014/10/09 01:00:50
Can we create and return the paintserver from this
fs
2014/10/09 07:23:08
Definitely possible.
fs
2014/10/10 13:08:58
Made SVGPaintServer more RAII (per ~above), and st
| |
67 { | |
68 ASSERT(style); | |
69 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); | |
70 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; | |
71 | |
72 bool hasFallback = false; | |
73 RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingReso urce(resourceMode, &renderer, style, hasFallback); | |
74 if (!paintingResource) | |
75 return false; | |
76 | |
77 if (!paintingResource->preparePaintServer(&renderer, style, resourceModeFlag s, paintServer)) { | |
78 if (!hasFallback) | |
79 return false; | |
80 | |
81 paintServer.setColor(RenderSVGResource::sharedSolidPaintingResource()->c olor()); | |
82 } | |
83 return true; | |
84 } | |
85 | |
86 bool SVGPaintServer::existsForRenderer(RenderObject& renderer, const RenderStyle * style, RenderSVGResourceMode resourceMode) | |
87 { | |
88 bool hasFallback; | |
89 return RenderSVGResource::requestPaintingResource(resourceMode, &renderer, s tyle, hasFallback); | |
90 } | |
91 | |
92 bool SVGPaintServer::updateGraphicsContext(GraphicsContext* context, RenderStyle * style, RenderObject& renderer, RenderSVGResourceModeFlags resourceModeFlags, G raphicsContextStateSaver& stateSaver) | |
93 { | |
94 ASSERT(context); | |
95 ASSERT(style); | |
96 | |
97 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); | |
98 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ; | |
99 | |
100 if (SVGRenderSupport::isRenderingClipPathAsMaskImage(renderer)) { | |
101 if (resourceMode == ApplyToStrokeMode) | |
102 return false; | |
103 context->setAlphaAsFloat(1); | |
104 context->setFillColor(SVGRenderStyle::initialFillPaintColor()); | |
105 return true; | |
106 } | |
107 | |
108 SVGPaintServer paintServer; | |
109 if (!requestForRenderer(renderer, style, resourceModeFlags, paintServer)) | |
110 return false; | |
111 paintServer.apply(*context, resourceMode, &stateSaver); | |
112 | |
113 const SVGRenderStyle& svgStyle = style->svgStyle(); | |
114 | |
115 if (resourceMode == ApplyToFillMode) { | |
116 context->setAlphaAsFloat(svgStyle.fillOpacity()); | |
117 context->setFillRule(svgStyle.fillRule()); | |
118 } else { | |
119 context->setAlphaAsFloat(svgStyle.strokeOpacity()); | |
120 SVGRenderSupport::applyStrokeStyleToContext(context, style, &renderer); | |
121 } | |
122 return true; | |
123 } | |
124 | |
125 } // namespace blink | |
OLD | NEW |