Chromium Code Reviews| Index: Source/core/paint/SVGPaintServer.cpp |
| diff --git a/Source/core/paint/SVGPaintServer.cpp b/Source/core/paint/SVGPaintServer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d122f276c5cb6dd953085ff35b37ad9310b5c75f |
| --- /dev/null |
| +++ b/Source/core/paint/SVGPaintServer.cpp |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/paint/SVGPaintServer.h" |
| + |
| +#include "core/rendering/style/RenderStyle.h" |
| +#include "core/rendering/style/SVGRenderStyle.h" |
| +#include "core/rendering/svg/RenderSVGResourceSolidColor.h" |
| +#include "core/rendering/svg/SVGRenderSupport.h" |
| +#include "platform/graphics/GraphicsContext.h" |
| +#include "platform/graphics/GraphicsContextStateSaver.h" |
| + |
| +namespace blink { |
| + |
| +SVGPaintServer::SVGPaintServer(Color color) |
| + : m_color(color) |
| +{ |
| +} |
| + |
| +SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient) |
| + : m_gradient(gradient) |
| + , m_color(Color::black) |
| +{ |
| +} |
| + |
| +SVGPaintServer::SVGPaintServer(PassRefPtr<Pattern> pattern) |
| + : m_pattern(pattern) |
| + , m_color(Color::black) |
| +{ |
| +} |
| + |
| +void SVGPaintServer::apply(GraphicsContext& context, RenderSVGResourceMode resourceMode, GraphicsContextStateSaver* stateSaver) |
| +{ |
| + ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode); |
| + if (stateSaver && (m_gradient || m_pattern)) |
| + stateSaver->saveIfNeeded(); |
| + |
| + if (resourceMode == ApplyToFillMode) { |
| + if (m_pattern) |
| + context.setFillPattern(m_pattern); |
| + else if (m_gradient) |
| + context.setFillGradient(m_gradient); |
| + else |
| + context.setFillColor(m_color); |
| + } else { |
| + if (m_pattern) |
| + context.setStrokePattern(m_pattern); |
| + else if (m_gradient) |
| + context.setStrokeGradient(m_gradient); |
| + else |
| + context.setStrokeColor(m_color); |
| + } |
| +} |
| + |
| +PassOwnPtr<SVGPaintServer> SVGPaintServer::requestForRenderer(RenderObject& renderer, RenderStyle* style, RenderSVGResourceModeFlags resourceModeFlags) |
| +{ |
| + ASSERT(style); |
| + RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(resourceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); |
| + ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode); |
| + |
| + bool hasFallback = false; |
| + RenderSVGResource* paintingResource = RenderSVGResource::requestPaintingResource(resourceMode, &renderer, style, hasFallback); |
| + if (!paintingResource) |
| + return nullptr; |
| + |
| + OwnPtr<SVGPaintServer> paintServer = paintingResource->preparePaintServer(&renderer, style, resourceModeFlags); |
| + if (paintServer) |
| + return paintServer.release(); |
| + if (hasFallback) |
| + return adoptPtr(new SVGPaintServer(RenderSVGResource::sharedSolidPaintingResource()->color())); |
| + return nullptr; |
| +} |
| + |
| +bool SVGPaintServer::updateGraphicsContext(GraphicsContextStateSaver& stateSaver, RenderStyle* style, RenderObject& renderer, RenderSVGResourceModeFlags resourceModeFlags) |
| +{ |
| + ASSERT(style); |
| + |
| + RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(resourceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); |
| + ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode); |
| + |
| + GraphicsContext* context = stateSaver.context(); |
| + if (SVGRenderSupport::isRenderingClipPathAsMaskImage(renderer)) { |
| + if (resourceMode == ApplyToStrokeMode) |
| + return false; |
| + context->setAlphaAsFloat(1); |
| + context->setFillColor(SVGRenderStyle::initialFillPaintColor()); |
| + return true; |
| + } |
| + |
| + OwnPtr<SVGPaintServer> paintServer = requestForRenderer(renderer, style, resourceModeFlags); |
|
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
|
| + if (!paintServer) |
| + return false; |
| + paintServer->apply(*context, resourceMode, &stateSaver); |
| + |
| + const SVGRenderStyle& svgStyle = style->svgStyle(); |
| + |
| + if (resourceMode == ApplyToFillMode) { |
| + context->setAlphaAsFloat(svgStyle.fillOpacity()); |
| + context->setFillRule(svgStyle.fillRule()); |
| + } else { |
| + context->setAlphaAsFloat(svgStyle.strokeOpacity()); |
| + SVGRenderSupport::applyStrokeStyleToContext(context, style, &renderer); |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace blink |