| 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, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 markAllClientsForInvalidation(markForInvalidation ? PaintInvalidation : Pare
ntOnlyInvalidation); | 43 markAllClientsForInvalidation(markForInvalidation ? PaintInvalidation : Pare
ntOnlyInvalidation); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void RenderSVGResourcePattern::removeClientFromCache(RenderObject* client, bool
markForInvalidation) | 46 void RenderSVGResourcePattern::removeClientFromCache(RenderObject* client, bool
markForInvalidation) |
| 47 { | 47 { |
| 48 ASSERT(client); | 48 ASSERT(client); |
| 49 m_patternMap.remove(client); | 49 m_patternMap.remove(client); |
| 50 markClientForInvalidation(client, markForInvalidation ? PaintInvalidation :
ParentOnlyInvalidation); | 50 markClientForInvalidation(client, markForInvalidation ? PaintInvalidation :
ParentOnlyInvalidation); |
| 51 } | 51 } |
| 52 | 52 |
| 53 PatternData* RenderSVGResourcePattern::buildPattern(RenderObject* object, const
SVGPatternElement* patternElement) | 53 PatternData* RenderSVGResourcePattern::buildPattern(const RenderObject& object,
const SVGPatternElement* patternElement) |
| 54 { | 54 { |
| 55 ASSERT(object); | 55 PatternData* currentData = m_patternMap.get(&object); |
| 56 PatternData* currentData = m_patternMap.get(object); | |
| 57 if (currentData && currentData->pattern) | 56 if (currentData && currentData->pattern) |
| 58 return currentData; | 57 return currentData; |
| 59 | 58 |
| 60 // If we couldn't determine the pattern content element root, stop here. | 59 // If we couldn't determine the pattern content element root, stop here. |
| 61 if (!m_attributes.patternContentElement()) | 60 if (!m_attributes.patternContentElement()) |
| 62 return 0; | 61 return 0; |
| 63 | 62 |
| 64 // An empty viewBox disables rendering. | 63 // An empty viewBox disables rendering. |
| 65 if (m_attributes.hasViewBox() && m_attributes.viewBox().isEmpty()) | 64 if (m_attributes.hasViewBox() && m_attributes.viewBox().isEmpty()) |
| 66 return 0; | 65 return 0; |
| 67 | 66 |
| 68 // Compute all necessary transformations to build the tile image & the patte
rn. | 67 // Compute all necessary transformations to build the tile image & the patte
rn. |
| 69 FloatRect tileBoundaries; | 68 FloatRect tileBoundaries; |
| 70 AffineTransform tileImageTransform; | 69 AffineTransform tileImageTransform; |
| 71 if (!buildTileImageTransform(object, m_attributes, patternElement, tileBound
aries, tileImageTransform)) | 70 if (!buildTileImageTransform(object, m_attributes, patternElement, tileBound
aries, tileImageTransform)) |
| 72 return 0; | 71 return 0; |
| 73 | 72 |
| 74 AffineTransform absoluteTransformIgnoringRotation; | 73 AffineTransform absoluteTransformIgnoringRotation; |
| 75 SVGRenderingContext::calculateDeviceSpaceTransformation(object, absoluteTran
sformIgnoringRotation); | 74 SVGRenderingContext::calculateDeviceSpaceTransformation(&object, absoluteTra
nsformIgnoringRotation); |
| 76 | 75 |
| 77 // Ignore 2D rotation, as it doesn't affect the size of the tile. | 76 // Ignore 2D rotation, as it doesn't affect the size of the tile. |
| 78 SVGRenderingContext::clear2DRotation(absoluteTransformIgnoringRotation); | 77 SVGRenderingContext::clear2DRotation(absoluteTransformIgnoringRotation); |
| 79 FloatRect absoluteTileBoundaries = absoluteTransformIgnoringRotation.mapRect
(tileBoundaries); | 78 FloatRect absoluteTileBoundaries = absoluteTransformIgnoringRotation.mapRect
(tileBoundaries); |
| 80 | 79 |
| 81 // Scale the tile size to match the scale level of the patternTransform. | 80 // Scale the tile size to match the scale level of the patternTransform. |
| 82 absoluteTileBoundaries.scale(static_cast<float>(m_attributes.patternTransfor
m().xScale()), | 81 absoluteTileBoundaries.scale(static_cast<float>(m_attributes.patternTransfor
m().xScale()), |
| 83 static_cast<float>(m_attributes.patternTransform().yScale())); | 82 static_cast<float>(m_attributes.patternTransform().yScale())); |
| 84 | 83 |
| 85 // Build tile image. | 84 // Build tile image. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 100 patternData->transform.translate(tileBoundaries.x(), tileBoundaries.y()); | 99 patternData->transform.translate(tileBoundaries.x(), tileBoundaries.y()); |
| 101 patternData->transform.scale(tileBoundaries.width() / tileImageSize.width(),
tileBoundaries.height() / tileImageSize.height()); | 100 patternData->transform.scale(tileBoundaries.width() / tileImageSize.width(),
tileBoundaries.height() / tileImageSize.height()); |
| 102 | 101 |
| 103 AffineTransform patternTransform = m_attributes.patternTransform(); | 102 AffineTransform patternTransform = m_attributes.patternTransform(); |
| 104 if (!patternTransform.isIdentity()) | 103 if (!patternTransform.isIdentity()) |
| 105 patternData->transform = patternTransform * patternData->transform; | 104 patternData->transform = patternTransform * patternData->transform; |
| 106 | 105 |
| 107 // Various calls above may trigger invalidations in some fringe cases (Image
Buffer allocation | 106 // Various calls above may trigger invalidations in some fringe cases (Image
Buffer allocation |
| 108 // failures in the SVG image cache for example). To avoid having our Pattern
Data deleted by | 107 // failures in the SVG image cache for example). To avoid having our Pattern
Data deleted by |
| 109 // removeAllClientsFromCache(), we only make it visible in the cache at the
very end. | 108 // removeAllClientsFromCache(), we only make it visible in the cache at the
very end. |
| 110 return m_patternMap.set(object, patternData.release()).storedValue->value.ge
t(); | 109 return m_patternMap.set(&object, patternData.release()).storedValue->value.g
et(); |
| 111 } | 110 } |
| 112 | 111 |
| 113 SVGPaintServer RenderSVGResourcePattern::preparePaintServer(RenderObject* object
) | 112 SVGPaintServer RenderSVGResourcePattern::preparePaintServer(const RenderObject&
object) |
| 114 { | 113 { |
| 115 ASSERT(object); | |
| 116 | |
| 117 clearInvalidationMask(); | 114 clearInvalidationMask(); |
| 118 | 115 |
| 119 SVGPatternElement* patternElement = toSVGPatternElement(element()); | 116 SVGPatternElement* patternElement = toSVGPatternElement(element()); |
| 120 if (!patternElement) | 117 if (!patternElement) |
| 121 return SVGPaintServer::invalid(); | 118 return SVGPaintServer::invalid(); |
| 122 | 119 |
| 123 if (m_shouldCollectPatternAttributes) { | 120 if (m_shouldCollectPatternAttributes) { |
| 124 patternElement->synchronizeAnimatedSVGAttribute(anyQName()); | 121 patternElement->synchronizeAnimatedSVGAttribute(anyQName()); |
| 125 | 122 |
| 126 m_attributes = PatternAttributes(); | 123 m_attributes = PatternAttributes(); |
| 127 patternElement->collectPatternAttributes(m_attributes); | 124 patternElement->collectPatternAttributes(m_attributes); |
| 128 m_shouldCollectPatternAttributes = false; | 125 m_shouldCollectPatternAttributes = false; |
| 129 } | 126 } |
| 130 | 127 |
| 131 // Spec: When the geometry of the applicable element has no width or height
and objectBoundingBox is specified, | 128 // Spec: When the geometry of the applicable element has no width or height
and objectBoundingBox is specified, |
| 132 // then the given effect (e.g. a gradient or a filter) will be ignored. | 129 // then the given effect (e.g. a gradient or a filter) will be ignored. |
| 133 FloatRect objectBoundingBox = object->objectBoundingBox(); | 130 FloatRect objectBoundingBox = object.objectBoundingBox(); |
| 134 if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDIN
GBOX && objectBoundingBox.isEmpty()) | 131 if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDIN
GBOX && objectBoundingBox.isEmpty()) |
| 135 return SVGPaintServer::invalid(); | 132 return SVGPaintServer::invalid(); |
| 136 | 133 |
| 137 PatternData* patternData = buildPattern(object, patternElement); | 134 PatternData* patternData = buildPattern(object, patternElement); |
| 138 if (!patternData) | 135 if (!patternData) |
| 139 return SVGPaintServer::invalid(); | 136 return SVGPaintServer::invalid(); |
| 140 | 137 |
| 141 patternData->pattern->setPatternSpaceTransform(patternData->transform); | 138 patternData->pattern->setPatternSpaceTransform(patternData->transform); |
| 142 | 139 |
| 143 return SVGPaintServer(patternData->pattern); | 140 return SVGPaintServer(patternData->pattern); |
| 144 } | 141 } |
| 145 | 142 |
| 146 static inline FloatRect calculatePatternBoundaries(const PatternAttributes& attr
ibutes, | 143 static inline FloatRect calculatePatternBoundaries(const PatternAttributes& attr
ibutes, |
| 147 const FloatRect& objectBoundi
ngBox, | 144 const FloatRect& objectBoundi
ngBox, |
| 148 const SVGPatternElement* patt
ernElement) | 145 const SVGPatternElement* patt
ernElement) |
| 149 { | 146 { |
| 150 ASSERT(patternElement); | 147 ASSERT(patternElement); |
| 151 return SVGLengthContext::resolveRectangle(patternElement, attributes.pattern
Units(), objectBoundingBox, attributes.x(), attributes.y(), attributes.width(),
attributes.height()); | 148 return SVGLengthContext::resolveRectangle(patternElement, attributes.pattern
Units(), objectBoundingBox, attributes.x(), attributes.y(), attributes.width(),
attributes.height()); |
| 152 } | 149 } |
| 153 | 150 |
| 154 bool RenderSVGResourcePattern::buildTileImageTransform(RenderObject* renderer, | 151 bool RenderSVGResourcePattern::buildTileImageTransform(const RenderObject& rende
rer, |
| 155 const PatternAttributes&
attributes, | 152 const PatternAttributes&
attributes, |
| 156 const SVGPatternElement*
patternElement, | 153 const SVGPatternElement*
patternElement, |
| 157 FloatRect& patternBoundar
ies, | 154 FloatRect& patternBoundar
ies, |
| 158 AffineTransform& tileImag
eTransform) const | 155 AffineTransform& tileImag
eTransform) const |
| 159 { | 156 { |
| 160 ASSERT(renderer); | |
| 161 ASSERT(patternElement); | 157 ASSERT(patternElement); |
| 162 | 158 |
| 163 FloatRect objectBoundingBox = renderer->objectBoundingBox(); | 159 FloatRect objectBoundingBox = renderer.objectBoundingBox(); |
| 164 patternBoundaries = calculatePatternBoundaries(attributes, objectBoundingBox
, patternElement); | 160 patternBoundaries = calculatePatternBoundaries(attributes, objectBoundingBox
, patternElement); |
| 165 if (patternBoundaries.width() <= 0 || patternBoundaries.height() <= 0) | 161 if (patternBoundaries.width() <= 0 || patternBoundaries.height() <= 0) |
| 166 return false; | 162 return false; |
| 167 | 163 |
| 168 AffineTransform viewBoxCTM = SVGFitToViewBox::viewBoxToViewTransform(attribu
tes.viewBox(), attributes.preserveAspectRatio(), patternBoundaries.width(), patt
ernBoundaries.height()); | 164 AffineTransform viewBoxCTM = SVGFitToViewBox::viewBoxToViewTransform(attribu
tes.viewBox(), attributes.preserveAspectRatio(), patternBoundaries.width(), patt
ernBoundaries.height()); |
| 169 | 165 |
| 170 // Apply viewBox/objectBoundingBox transformations. | 166 // Apply viewBox/objectBoundingBox transformations. |
| 171 if (!viewBoxCTM.isIdentity()) | 167 if (!viewBoxCTM.isIdentity()) |
| 172 tileImageTransform = viewBoxCTM; | 168 tileImageTransform = viewBoxCTM; |
| 173 else if (attributes.patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJ
ECTBOUNDINGBOX) | 169 else if (attributes.patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJ
ECTBOUNDINGBOX) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 continue; | 210 continue; |
| 215 if (element->renderer()->needsLayout()) | 211 if (element->renderer()->needsLayout()) |
| 216 return nullptr; | 212 return nullptr; |
| 217 SVGRenderingContext::renderSubtree(tileImage->context(), element->render
er(), contentTransformation); | 213 SVGRenderingContext::renderSubtree(tileImage->context(), element->render
er(), contentTransformation); |
| 218 } | 214 } |
| 219 | 215 |
| 220 return tileImage.release(); | 216 return tileImage.release(); |
| 221 } | 217 } |
| 222 | 218 |
| 223 } | 219 } |
| OLD | NEW |