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

Side by Side Diff: Source/core/paint/SVGPaintServer.cpp

Issue 638933002: Introduce SVGPaintServer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Pass GCSS only - not GCSS and GC. Created 6 years, 2 months 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 | Annotate | Revision Log
OLDNEW
(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(Color color)
18 : m_color(color)
19 {
20 }
21
22 SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient)
23 : m_gradient(gradient)
24 , m_color(Color::black)
25 {
26 }
27
28 SVGPaintServer::SVGPaintServer(PassRefPtr<Pattern> pattern)
29 : m_pattern(pattern)
30 , m_color(Color::black)
31 {
32 }
33
34 void SVGPaintServer::apply(GraphicsContext& context, RenderSVGResourceMode resou rceMode, GraphicsContextStateSaver* stateSaver)
35 {
36 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
37 if (stateSaver && (m_gradient || m_pattern))
38 stateSaver->saveIfNeeded();
39
40 if (resourceMode == ApplyToFillMode) {
41 if (m_pattern)
42 context.setFillPattern(m_pattern);
43 else if (m_gradient)
44 context.setFillGradient(m_gradient);
45 else
46 context.setFillColor(m_color);
47 } else {
48 if (m_pattern)
49 context.setStrokePattern(m_pattern);
50 else if (m_gradient)
51 context.setStrokeGradient(m_gradient);
52 else
53 context.setStrokeColor(m_color);
54 }
55 }
56
57 PassOwnPtr<SVGPaintServer> SVGPaintServer::requestForRenderer(RenderObject& rend erer, RenderStyle* style, RenderSVGResourceModeFlags resourceModeFlags)
58 {
59 ASSERT(style);
60 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode));
61 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
62
63 bool hasFallback = false;
64 RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingReso urce(resourceMode, &renderer, style, hasFallback);
65 if (!paintingResource)
66 return nullptr;
67
68 OwnPtr<SVGPaintServer> paintServer = paintingResource->preparePaintServer(&r enderer, style, resourceModeFlags);
69 if (paintServer)
70 return paintServer.release();
71 if (hasFallback)
72 return adoptPtr(new SVGPaintServer(RenderSVGResource::sharedSolidPaintin gResource()->color()));
73 return nullptr;
74 }
75
76 bool SVGPaintServer::updateGraphicsContext(GraphicsContextStateSaver& stateSaver , RenderStyle* style, RenderObject& renderer, RenderSVGResourceModeFlags resourc eModeFlags)
77 {
78 ASSERT(style);
79
80 RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(reso urceModeFlags & (ApplyToFillMode | ApplyToStrokeMode));
81 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode) ;
82
83 GraphicsContext* context = stateSaver.context();
84 if (SVGRenderSupport::isRenderingClipPathAsMaskImage(renderer)) {
85 if (resourceMode == ApplyToStrokeMode)
86 return false;
87 context->setAlphaAsFloat(1);
88 context->setFillColor(SVGRenderStyle::initialFillPaintColor());
89 return true;
90 }
91
92 OwnPtr<SVGPaintServer> paintServer = requestForRenderer(renderer, style, res ourceModeFlags);
f(malita) 2014/10/10 15:49:07 If we're not caching these, it seems wasteful to a
fs 2014/10/10 16:10:23 Aha! Reviewer inconsistency detected - parity erro
fs 2014/10/10 16:44:41 Can be found in PS7+ - I went with an explicit isV
93 if (!paintServer)
94 return false;
95 paintServer->apply(*context, resourceMode, &stateSaver);
96
97 const SVGRenderStyle& svgStyle = style->svgStyle();
98
99 if (resourceMode == ApplyToFillMode) {
100 context->setAlphaAsFloat(svgStyle.fillOpacity());
101 context->setFillRule(svgStyle.fillRule());
102 } else {
103 context->setAlphaAsFloat(svgStyle.strokeOpacity());
104 SVGRenderSupport::applyStrokeStyleToContext(context, style, &renderer);
105 }
106 return true;
107 }
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698