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..2b0c2af537e031ae8cf96cc8bfcb0aa64c1e0f7c |
--- /dev/null |
+++ b/Source/core/paint/SVGPaintServer.cpp |
@@ -0,0 +1,125 @@ |
+// 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() |
+ : m_color(Color::black) |
+{ |
+} |
+ |
+void SVGPaintServer::setColor(Color color) |
+{ |
+ m_gradient.clear(); |
+ m_pattern.clear(); |
+ m_color = color; |
+} |
+ |
+void SVGPaintServer::setGradient(const PassRefPtr<Gradient> gradient) |
+{ |
+ m_gradient = gradient; |
+ m_pattern.clear(); |
+ m_color = Color::black; |
+} |
+ |
+void SVGPaintServer::setPattern(const PassRefPtr<Pattern> pattern) |
+{ |
+ m_gradient.clear(); |
+ 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); |
+ } |
+} |
+ |
+bool SVGPaintServer::requestForRenderer(RenderObject& renderer, RenderStyle* style, 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
|
+{ |
+ 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 false; |
+ |
+ if (!paintingResource->preparePaintServer(&renderer, style, resourceModeFlags, paintServer)) { |
+ if (!hasFallback) |
+ return false; |
+ |
+ paintServer.setColor(RenderSVGResource::sharedSolidPaintingResource()->color()); |
+ } |
+ return true; |
+} |
+ |
+bool SVGPaintServer::existsForRenderer(RenderObject& renderer, const RenderStyle* style, RenderSVGResourceMode resourceMode) |
+{ |
+ bool hasFallback; |
+ return RenderSVGResource::requestPaintingResource(resourceMode, &renderer, style, hasFallback); |
+} |
+ |
+bool SVGPaintServer::updateGraphicsContext(GraphicsContext* context, RenderStyle* style, RenderObject& renderer, RenderSVGResourceModeFlags resourceModeFlags, GraphicsContextStateSaver& stateSaver) |
+{ |
+ ASSERT(context); |
+ ASSERT(style); |
+ |
+ RenderSVGResourceMode resourceMode = static_cast<RenderSVGResourceMode>(resourceModeFlags & (ApplyToFillMode | ApplyToStrokeMode)); |
+ ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode); |
+ |
+ if (SVGRenderSupport::isRenderingClipPathAsMaskImage(renderer)) { |
+ if (resourceMode == ApplyToStrokeMode) |
+ return false; |
+ context->setAlphaAsFloat(1); |
+ context->setFillColor(SVGRenderStyle::initialFillPaintColor()); |
+ return true; |
+ } |
+ |
+ SVGPaintServer paintServer; |
+ if (!requestForRenderer(renderer, style, resourceModeFlags, 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 |