Chromium Code Reviews| 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) Research In Motion Limited 2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "config.h" | 21 #include "config.h" |
| 22 | |
| 23 #include "core/rendering/svg/RenderSVGResourcePattern.h" | 22 #include "core/rendering/svg/RenderSVGResourcePattern.h" |
| 24 | 23 |
| 25 #include "core/dom/ElementTraversal.h" | 24 #include "core/dom/ElementTraversal.h" |
| 26 #include "core/rendering/svg/SVGRenderSupport.h" | 25 #include "core/paint/SVGPaintServer.h" |
| 27 #include "core/rendering/svg/SVGRenderingContext.h" | 26 #include "core/rendering/svg/SVGRenderingContext.h" |
| 28 #include "core/svg/SVGFitToViewBox.h" | 27 #include "core/svg/SVGFitToViewBox.h" |
| 29 #include "platform/graphics/GraphicsContext.h" | 28 #include "platform/graphics/GraphicsContext.h" |
| 30 | 29 |
| 31 namespace blink { | 30 namespace blink { |
| 32 | 31 |
| 33 const RenderSVGResourceType RenderSVGResourcePattern::s_resourceType = PatternRe sourceType; | 32 const RenderSVGResourceType RenderSVGResourcePattern::s_resourceType = PatternRe sourceType; |
| 34 | 33 |
| 35 RenderSVGResourcePattern::RenderSVGResourcePattern(SVGPatternElement* node) | 34 RenderSVGResourcePattern::RenderSVGResourcePattern(SVGPatternElement* node) |
| 36 : RenderSVGResourceContainer(node) | 35 : RenderSVGResourceContainer(node) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 AffineTransform patternTransform = m_attributes.patternTransform(); | 104 AffineTransform patternTransform = m_attributes.patternTransform(); |
| 106 if (!patternTransform.isIdentity()) | 105 if (!patternTransform.isIdentity()) |
| 107 patternData->transform = patternTransform * patternData->transform; | 106 patternData->transform = patternTransform * patternData->transform; |
| 108 | 107 |
| 109 // Various calls above may trigger invalidations in some fringe cases (Image Buffer allocation | 108 // Various calls above may trigger invalidations in some fringe cases (Image Buffer allocation |
| 110 // failures in the SVG image cache for example). To avoid having our Pattern Data deleted by | 109 // failures in the SVG image cache for example). To avoid having our Pattern Data deleted by |
| 111 // removeAllClientsFromCache(), we only make it visible in the cache at the very end. | 110 // removeAllClientsFromCache(), we only make it visible in the cache at the very end. |
| 112 return m_patternMap.set(object, patternData.release()).storedValue->value.ge t(); | 111 return m_patternMap.set(object, patternData.release()).storedValue->value.ge t(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 bool RenderSVGResourcePattern::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext* context, RenderSVGResourceModeFlags resourceMode) | 114 SVGPaintServer RenderSVGResourcePattern::preparePaintServer(RenderObject* object , RenderStyle* style, RenderSVGResourceModeFlags resourceMode) |
| 116 { | 115 { |
| 117 ASSERT(object); | 116 ASSERT(object); |
| 118 ASSERT(style); | 117 ASSERT(style); |
| 119 ASSERT(context); | |
| 120 | 118 |
| 121 clearInvalidationMask(); | 119 clearInvalidationMask(); |
| 122 | 120 |
| 123 SVGPatternElement* patternElement = toSVGPatternElement(element()); | 121 SVGPatternElement* patternElement = toSVGPatternElement(element()); |
| 124 if (!patternElement) | 122 if (!patternElement) |
| 125 return false; | 123 return SVGPaintServer::invalid(); |
| 126 | 124 |
| 127 if (m_shouldCollectPatternAttributes) { | 125 if (m_shouldCollectPatternAttributes) { |
| 128 patternElement->synchronizeAnimatedSVGAttribute(anyQName()); | 126 patternElement->synchronizeAnimatedSVGAttribute(anyQName()); |
| 129 | 127 |
| 130 m_attributes = PatternAttributes(); | 128 m_attributes = PatternAttributes(); |
| 131 patternElement->collectPatternAttributes(m_attributes); | 129 patternElement->collectPatternAttributes(m_attributes); |
| 132 m_shouldCollectPatternAttributes = false; | 130 m_shouldCollectPatternAttributes = false; |
| 133 } | 131 } |
| 134 | 132 |
| 135 // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified, | 133 // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified, |
| 136 // then the given effect (e.g. a gradient or a filter) will be ignored. | 134 // then the given effect (e.g. a gradient or a filter) will be ignored. |
| 137 FloatRect objectBoundingBox = object->objectBoundingBox(); | 135 FloatRect objectBoundingBox = object->objectBoundingBox(); |
| 138 if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDIN GBOX && objectBoundingBox.isEmpty()) | 136 if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDIN GBOX && objectBoundingBox.isEmpty()) |
| 139 return false; | 137 return SVGPaintServer::invalid(); |
| 140 | 138 |
| 141 PatternData* patternData = buildPattern(object, patternElement); | 139 PatternData* patternData = buildPattern(object, patternElement); |
| 142 if (!patternData) | 140 if (!patternData) |
| 143 return false; | 141 return SVGPaintServer::invalid(); |
| 144 | 142 |
| 145 const SVGRenderStyle& svgStyle = style->svgStyle(); | 143 const SVGRenderStyle& svgStyle = style->svgStyle(); |
| 146 | 144 |
| 147 AffineTransform computedPatternSpaceTransform = computeResourceSpaceTransfor m(object, patternData->transform, svgStyle, resourceMode); | 145 AffineTransform computedPatternSpaceTransform = computeResourceSpaceTransfor m(object, patternData->transform, svgStyle, resourceMode); |
| 148 patternData->pattern->setPatternSpaceTransform(computedPatternSpaceTransform ); | 146 patternData->pattern->setPatternSpaceTransform(computedPatternSpaceTransform ); |
| 149 | 147 |
| 150 // Draw pattern | 148 return SVGPaintServer(patternData->pattern); |
|
chrishtr
2014/10/10 16:59:20
Why not just have a method that exposes the data n
fs
2014/10/11 12:05:50
Then I'd have to think, that it'd be better to jus
| |
| 151 context->save(); | |
| 152 | |
| 153 if (resourceMode & ApplyToFillMode) | |
| 154 context->setFillPattern(patternData->pattern); | |
| 155 else if (resourceMode & ApplyToStrokeMode) | |
| 156 context->setStrokePattern(patternData->pattern); | |
| 157 | |
| 158 updateGraphicsContext(context, style, *object, resourceMode); | |
| 159 return true; | |
| 160 } | |
| 161 | |
| 162 void RenderSVGResourcePattern::postApplyResource(GraphicsContext* context) | |
| 163 { | |
| 164 ASSERT(context); | |
| 165 context->restore(); | |
| 166 } | 149 } |
| 167 | 150 |
| 168 static inline FloatRect calculatePatternBoundaries(const PatternAttributes& attr ibutes, | 151 static inline FloatRect calculatePatternBoundaries(const PatternAttributes& attr ibutes, |
| 169 const FloatRect& objectBoundi ngBox, | 152 const FloatRect& objectBoundi ngBox, |
| 170 const SVGPatternElement* patt ernElement) | 153 const SVGPatternElement* patt ernElement) |
| 171 { | 154 { |
| 172 ASSERT(patternElement); | 155 ASSERT(patternElement); |
| 173 return SVGLengthContext::resolveRectangle(patternElement, attributes.pattern Units(), objectBoundingBox, attributes.x(), attributes.y(), attributes.width(), attributes.height()); | 156 return SVGLengthContext::resolveRectangle(patternElement, attributes.pattern Units(), objectBoundingBox, attributes.x(), attributes.y(), attributes.width(), attributes.height()); |
| 174 } | 157 } |
| 175 | 158 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 continue; | 219 continue; |
| 237 if (element->renderer()->needsLayout()) | 220 if (element->renderer()->needsLayout()) |
| 238 return nullptr; | 221 return nullptr; |
| 239 SVGRenderingContext::renderSubtree(tileImage->context(), element->render er(), contentTransformation); | 222 SVGRenderingContext::renderSubtree(tileImage->context(), element->render er(), contentTransformation); |
| 240 } | 223 } |
| 241 | 224 |
| 242 return tileImage.release(); | 225 return tileImage.release(); |
| 243 } | 226 } |
| 244 | 227 |
| 245 } | 228 } |
| OLD | NEW |