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

Unified Diff: Source/core/paint/SVGPaintServer.cpp

Issue 638933002: Introduce SVGPaintServer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Extra sure about manual shadow-restore. 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698