| 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) 2008 Eric Seidel <eric@webkit.org> | 3 * Copyright (C) 2008 Eric Seidel <eric@webkit.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 | |
| 25 #include "core/rendering/svg/RenderSVGResourceGradient.h" | 24 #include "core/rendering/svg/RenderSVGResourceGradient.h" |
| 26 | 25 |
| 27 #include "core/rendering/svg/RenderSVGShape.h" | 26 #include "core/paint/SVGPaintServer.h" |
| 28 #include "core/rendering/svg/SVGRenderSupport.h" | |
| 29 #include "platform/graphics/GraphicsContext.h" | |
| 30 | 27 |
| 31 namespace blink { | 28 namespace blink { |
| 32 | 29 |
| 33 RenderSVGResourceGradient::RenderSVGResourceGradient(SVGGradientElement* node) | 30 RenderSVGResourceGradient::RenderSVGResourceGradient(SVGGradientElement* node) |
| 34 : RenderSVGResourceContainer(node) | 31 : RenderSVGResourceContainer(node) |
| 35 , m_shouldCollectGradientAttributes(true) | 32 , m_shouldCollectGradientAttributes(true) |
| 36 { | 33 { |
| 37 } | 34 } |
| 38 | 35 |
| 39 void RenderSVGResourceGradient::removeAllClientsFromCache(bool markForInvalidati
on) | 36 void RenderSVGResourceGradient::removeAllClientsFromCache(bool markForInvalidati
on) |
| 40 { | 37 { |
| 41 m_gradientMap.clear(); | 38 m_gradientMap.clear(); |
| 42 m_shouldCollectGradientAttributes = true; | 39 m_shouldCollectGradientAttributes = true; |
| 43 markAllClientsForInvalidation(markForInvalidation ? PaintInvalidation : Pare
ntOnlyInvalidation); | 40 markAllClientsForInvalidation(markForInvalidation ? PaintInvalidation : Pare
ntOnlyInvalidation); |
| 44 } | 41 } |
| 45 | 42 |
| 46 void RenderSVGResourceGradient::removeClientFromCache(RenderObject* client, bool
markForInvalidation) | 43 void RenderSVGResourceGradient::removeClientFromCache(RenderObject* client, bool
markForInvalidation) |
| 47 { | 44 { |
| 48 ASSERT(client); | 45 ASSERT(client); |
| 49 m_gradientMap.remove(client); | 46 m_gradientMap.remove(client); |
| 50 markClientForInvalidation(client, markForInvalidation ? PaintInvalidation :
ParentOnlyInvalidation); | 47 markClientForInvalidation(client, markForInvalidation ? PaintInvalidation :
ParentOnlyInvalidation); |
| 51 } | 48 } |
| 52 | 49 |
| 53 bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle*
style, GraphicsContext* context, RenderSVGResourceModeFlags resourceMode) | 50 PassOwnPtr<SVGPaintServer> RenderSVGResourceGradient::preparePaintServer(RenderO
bject* object, RenderStyle* style, RenderSVGResourceModeFlags resourceMode) |
| 54 { | 51 { |
| 55 ASSERT(object); | 52 ASSERT(object); |
| 56 ASSERT(style); | 53 ASSERT(style); |
| 57 ASSERT(context); | |
| 58 | 54 |
| 59 clearInvalidationMask(); | 55 clearInvalidationMask(); |
| 60 | 56 |
| 61 // Be sure to synchronize all SVG properties on the gradientElement _before_
processing any further. | 57 // Be sure to synchronize all SVG properties on the gradientElement _before_
processing any further. |
| 62 // Otherwhise the call to collectGradientAttributes() in createTileImage(),
may cause the SVG DOM property | 58 // Otherwhise the call to collectGradientAttributes() in createTileImage(),
may cause the SVG DOM property |
| 63 // synchronization to kick in, which causes removeAllClientsFromCache() to b
e called, which in turn deletes our | 59 // synchronization to kick in, which causes removeAllClientsFromCache() to b
e called, which in turn deletes our |
| 64 // GradientData object! Leaving out the line below will cause svg/dynamic-up
dates/SVG*GradientElement-svgdom* to crash. | 60 // GradientData object! Leaving out the line below will cause svg/dynamic-up
dates/SVG*GradientElement-svgdom* to crash. |
| 65 SVGGradientElement* gradientElement = toSVGGradientElement(element()); | 61 SVGGradientElement* gradientElement = toSVGGradientElement(element()); |
| 66 if (!gradientElement) | 62 if (!gradientElement) |
| 67 return false; | 63 return nullptr; |
| 68 | 64 |
| 69 if (m_shouldCollectGradientAttributes) { | 65 if (m_shouldCollectGradientAttributes) { |
| 70 gradientElement->synchronizeAnimatedSVGAttribute(anyQName()); | 66 gradientElement->synchronizeAnimatedSVGAttribute(anyQName()); |
| 71 if (!collectGradientAttributes(gradientElement)) | 67 if (!collectGradientAttributes(gradientElement)) |
| 72 return false; | 68 return nullptr; |
| 73 | 69 |
| 74 m_shouldCollectGradientAttributes = false; | 70 m_shouldCollectGradientAttributes = false; |
| 75 } | 71 } |
| 76 | 72 |
| 77 // Spec: When the geometry of the applicable element has no width or height
and objectBoundingBox is specified, | 73 // Spec: When the geometry of the applicable element has no width or height
and objectBoundingBox is specified, |
| 78 // then the given effect (e.g. a gradient or a filter) will be ignored. | 74 // then the given effect (e.g. a gradient or a filter) will be ignored. |
| 79 FloatRect objectBoundingBox = object->objectBoundingBox(); | 75 FloatRect objectBoundingBox = object->objectBoundingBox(); |
| 80 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && obje
ctBoundingBox.isEmpty()) | 76 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && obje
ctBoundingBox.isEmpty()) |
| 81 return false; | 77 return nullptr; |
| 82 | 78 |
| 83 OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).stor
edValue->value; | 79 OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).stor
edValue->value; |
| 84 if (!gradientData) | 80 if (!gradientData) |
| 85 gradientData = adoptPtr(new GradientData); | 81 gradientData = adoptPtr(new GradientData); |
| 86 | 82 |
| 87 // Create gradient object | 83 // Create gradient object |
| 88 if (!gradientData->gradient) { | 84 if (!gradientData->gradient) { |
| 89 buildGradient(gradientData.get()); | 85 buildGradient(gradientData.get()); |
| 90 | 86 |
| 91 // We want the text bounding box applied to the gradient space transform
now, so the gradient shader can use it. | 87 // We want the text bounding box applied to the gradient space transform
now, so the gradient shader can use it. |
| 92 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX &&
!objectBoundingBox.isEmpty()) { | 88 if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX &&
!objectBoundingBox.isEmpty()) { |
| 93 gradientData->userspaceTransform.translate(objectBoundingBox.x(), ob
jectBoundingBox.y()); | 89 gradientData->userspaceTransform.translate(objectBoundingBox.x(), ob
jectBoundingBox.y()); |
| 94 gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.w
idth(), objectBoundingBox.height()); | 90 gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.w
idth(), objectBoundingBox.height()); |
| 95 } | 91 } |
| 96 | 92 |
| 97 AffineTransform gradientTransform; | 93 AffineTransform gradientTransform; |
| 98 calculateGradientTransform(gradientTransform); | 94 calculateGradientTransform(gradientTransform); |
| 99 | 95 |
| 100 gradientData->userspaceTransform *= gradientTransform; | 96 gradientData->userspaceTransform *= gradientTransform; |
| 101 } | 97 } |
| 102 | 98 |
| 103 if (!gradientData->gradient) | 99 if (!gradientData->gradient) |
| 104 return false; | 100 return nullptr; |
| 105 | 101 |
| 106 const SVGRenderStyle& svgStyle = style->svgStyle(); | 102 const SVGRenderStyle& svgStyle = style->svgStyle(); |
| 107 | 103 |
| 108 AffineTransform computedGradientSpaceTransform = computeResourceSpaceTransfo
rm(object, gradientData->userspaceTransform, svgStyle, resourceMode); | 104 AffineTransform computedGradientSpaceTransform = computeResourceSpaceTransfo
rm(object, gradientData->userspaceTransform, svgStyle, resourceMode); |
| 109 gradientData->gradient->setGradientSpaceTransform(computedGradientSpaceTrans
form); | 105 gradientData->gradient->setGradientSpaceTransform(computedGradientSpaceTrans
form); |
| 110 | 106 |
| 111 // Draw gradient | 107 return adoptPtr(new SVGPaintServer(gradientData->gradient)); |
| 112 context->save(); | |
| 113 | |
| 114 if (resourceMode & ApplyToFillMode) | |
| 115 context->setFillGradient(gradientData->gradient); | |
| 116 else if (resourceMode & ApplyToStrokeMode) | |
| 117 context->setStrokeGradient(gradientData->gradient); | |
| 118 | |
| 119 updateGraphicsContext(context, style, *object, resourceMode); | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 void RenderSVGResourceGradient::postApplyResource(GraphicsContext* context) | |
| 124 { | |
| 125 ASSERT(context); | |
| 126 context->restore(); | |
| 127 } | 108 } |
| 128 | 109 |
| 129 bool RenderSVGResourceGradient::isChildAllowed(RenderObject* child, RenderStyle*
) const | 110 bool RenderSVGResourceGradient::isChildAllowed(RenderObject* child, RenderStyle*
) const |
| 130 { | 111 { |
| 131 if (child->isSVGGradientStop()) | 112 if (child->isSVGGradientStop()) |
| 132 return true; | 113 return true; |
| 133 | 114 |
| 134 if (!child->isSVGResourceContainer()) | 115 if (!child->isSVGResourceContainer()) |
| 135 return false; | 116 return false; |
| 136 | 117 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 159 return SpreadMethodReflect; | 140 return SpreadMethodReflect; |
| 160 case SVGSpreadMethodRepeat: | 141 case SVGSpreadMethodRepeat: |
| 161 return SpreadMethodRepeat; | 142 return SpreadMethodRepeat; |
| 162 } | 143 } |
| 163 | 144 |
| 164 ASSERT_NOT_REACHED(); | 145 ASSERT_NOT_REACHED(); |
| 165 return SpreadMethodPad; | 146 return SpreadMethodPad; |
| 166 } | 147 } |
| 167 | 148 |
| 168 } | 149 } |
| OLD | NEW |