| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2007 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 4 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
| 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 5 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "config.h" | 23 #include "config.h" |
| 24 #include "core/layout/svg/LayoutSVGResourcePaintServer.h" | 24 #include "core/layout/svg/LayoutSVGResourcePaintServer.h" |
| 25 | 25 |
| 26 #include "core/style/ComputedStyle.h" | 26 #include "core/style/ComputedStyle.h" |
| 27 #include "core/layout/svg/SVGResources.h" | 27 #include "core/layout/svg/SVGResources.h" |
| 28 #include "core/layout/svg/SVGResourcesCache.h" | 28 #include "core/layout/svg/SVGResourcesCache.h" |
| 29 #include "platform/graphics/GraphicsContext.h" | 29 #include "platform/graphics/skia/SkiaUtils.h" |
| 30 #include "platform/graphics/GraphicsContextStateSaver.h" | |
| 31 #include "third_party/skia/include/core/SkPaint.h" | 30 #include "third_party/skia/include/core/SkPaint.h" |
| 32 | 31 |
| 33 namespace blink { | 32 namespace blink { |
| 34 | 33 |
| 35 SVGPaintServer::SVGPaintServer(Color color) | 34 SVGPaintServer::SVGPaintServer(Color color) |
| 36 : m_color(color) | 35 : m_color(color) |
| 37 { | 36 { |
| 38 } | 37 } |
| 39 | 38 |
| 40 SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient) | 39 SVGPaintServer::SVGPaintServer(PassRefPtr<Gradient> gradient) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 SkColor baseColor = m_gradient || m_pattern ? SK_ColorBLACK : m_color.rgb(); | 53 SkColor baseColor = m_gradient || m_pattern ? SK_ColorBLACK : m_color.rgb(); |
| 55 paint.setColor(scaleAlpha(baseColor, paintAlpha)); | 54 paint.setColor(scaleAlpha(baseColor, paintAlpha)); |
| 56 if (m_pattern) | 55 if (m_pattern) |
| 57 paint.setShader(m_pattern->shader()); | 56 paint.setShader(m_pattern->shader()); |
| 58 else if (m_gradient) | 57 else if (m_gradient) |
| 59 paint.setShader(m_gradient->shader()); | 58 paint.setShader(m_gradient->shader()); |
| 60 else | 59 else |
| 61 paint.setShader(nullptr); | 60 paint.setShader(nullptr); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void SVGPaintServer::apply(GraphicsContext& context, LayoutSVGResourceMode resou
rceMode, float paintAlpha, GraphicsContextStateSaver& stateSaver) | |
| 65 { | |
| 66 ASSERT(resourceMode == ApplyToFillMode || resourceMode == ApplyToStrokeMode)
; | |
| 67 | |
| 68 if (m_gradient || m_pattern) | |
| 69 stateSaver.saveIfNeeded(); | |
| 70 | |
| 71 if (resourceMode == ApplyToFillMode) { | |
| 72 if (m_pattern) | |
| 73 context.setFillPattern(m_pattern, paintAlpha); | |
| 74 else if (m_gradient) | |
| 75 context.setFillGradient(m_gradient, paintAlpha); | |
| 76 else | |
| 77 context.setFillColor(scaleAlpha(m_color.rgb(), paintAlpha)); | |
| 78 } else { | |
| 79 if (m_pattern) | |
| 80 context.setStrokePattern(m_pattern, paintAlpha); | |
| 81 else if (m_gradient) | |
| 82 context.setStrokeGradient(m_gradient, paintAlpha); | |
| 83 else | |
| 84 context.setStrokeColor(scaleAlpha(m_color.rgb(), paintAlpha)); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void SVGPaintServer::prependTransform(const AffineTransform& transform) | 63 void SVGPaintServer::prependTransform(const AffineTransform& transform) |
| 89 { | 64 { |
| 90 ASSERT(m_gradient || m_pattern); | 65 ASSERT(m_gradient || m_pattern); |
| 91 if (m_pattern) | 66 if (m_pattern) |
| 92 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT
ransform()); | 67 m_pattern->setPatternSpaceTransform(transform * m_pattern->patternSpaceT
ransform()); |
| 93 else | 68 else |
| 94 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp
aceTransform()); | 69 m_gradient->setGradientSpaceTransform(transform * m_gradient->gradientSp
aceTransform()); |
| 95 } | 70 } |
| 96 | 71 |
| 97 static SVGPaintDescription requestPaint(const LayoutObject& object, const Comput
edStyle& style, LayoutSVGResourceMode mode) | 72 static SVGPaintDescription requestPaint(const LayoutObject& object, const Comput
edStyle& style, LayoutSVGResourceMode mode) |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 LayoutSVGResourcePaintServer::~LayoutSVGResourcePaintServer() | 171 LayoutSVGResourcePaintServer::~LayoutSVGResourcePaintServer() |
| 197 { | 172 { |
| 198 } | 173 } |
| 199 | 174 |
| 200 SVGPaintDescription LayoutSVGResourcePaintServer::requestPaintDescription(const
LayoutObject& layoutObject, const ComputedStyle& style, LayoutSVGResourceMode re
sourceMode) | 175 SVGPaintDescription LayoutSVGResourcePaintServer::requestPaintDescription(const
LayoutObject& layoutObject, const ComputedStyle& style, LayoutSVGResourceMode re
sourceMode) |
| 201 { | 176 { |
| 202 return requestPaint(layoutObject, style, resourceMode); | 177 return requestPaint(layoutObject, style, resourceMode); |
| 203 } | 178 } |
| 204 | 179 |
| 205 } | 180 } |
| OLD | NEW |