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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 markAllClientsForInvalidation(markForInvalidation ? RepaintInvalidation : Pa
rentOnlyInvalidation); | 48 markAllClientsForInvalidation(markForInvalidation ? RepaintInvalidation : Pa
rentOnlyInvalidation); |
49 } | 49 } |
50 | 50 |
51 void RenderSVGResourcePattern::removeClientFromCache(RenderObject* client, bool
markForInvalidation) | 51 void RenderSVGResourcePattern::removeClientFromCache(RenderObject* client, bool
markForInvalidation) |
52 { | 52 { |
53 ASSERT(client); | 53 ASSERT(client); |
54 m_patternMap.remove(client); | 54 m_patternMap.remove(client); |
55 markClientForInvalidation(client, markForInvalidation ? RepaintInvalidation
: ParentOnlyInvalidation); | 55 markClientForInvalidation(client, markForInvalidation ? RepaintInvalidation
: ParentOnlyInvalidation); |
56 } | 56 } |
57 | 57 |
58 bool RenderSVGResourcePattern::applyResource(RenderObject* object, RenderStyle*
style, GraphicsContext*& context, unsigned short resourceMode) | 58 PatternData* RenderSVGResourcePattern::buildPattern(RenderObject* object, unsign
ed short resourceMode) |
59 { | 59 { |
60 ASSERT(object); | 60 PatternData* currentData = m_patternMap.get(object); |
61 ASSERT(style); | 61 if (currentData && currentData->pattern) |
62 ASSERT(context); | 62 return currentData; |
63 ASSERT(resourceMode != ApplyToDefaultMode); | |
64 | 63 |
65 // Be sure to synchronize all SVG properties on the patternElement _before_
processing any further. | |
66 // Otherwhise the call to collectPatternAttributes() below, may cause the SV
G DOM property | |
67 // synchronization to kick in, which causes removeAllClientsFromCache() to b
e called, which in turn deletes our | |
68 // PatternData object! Leaving out the line below will cause svg/dynamic-upd
ates/SVGPatternElement-svgdom* to crash. | |
69 SVGPatternElement* patternElement = static_cast<SVGPatternElement*>(node()); | 64 SVGPatternElement* patternElement = static_cast<SVGPatternElement*>(node()); |
70 if (!patternElement) | 65 if (!patternElement) |
71 return false; | 66 return 0; |
72 | 67 |
73 if (m_shouldCollectPatternAttributes) { | 68 if (m_shouldCollectPatternAttributes) { |
74 patternElement->updateAnimatedSVGAttribute(anyQName()); | 69 patternElement->updateAnimatedSVGAttribute(anyQName()); |
75 | 70 |
76 m_attributes = PatternAttributes(); | 71 m_attributes = PatternAttributes(); |
77 patternElement->collectPatternAttributes(m_attributes); | 72 patternElement->collectPatternAttributes(m_attributes); |
78 m_shouldCollectPatternAttributes = false; | 73 m_shouldCollectPatternAttributes = false; |
79 } | 74 } |
80 | 75 |
| 76 // If we couldn't determine the pattern content element root, stop here. |
| 77 if (!m_attributes.patternContentElement()) |
| 78 return 0; |
| 79 |
| 80 // Compute all necessary transformations to build the tile image & the patte
rn. |
| 81 FloatRect tileBoundaries; |
| 82 AffineTransform tileImageTransform; |
| 83 if (!buildTileImageTransform(object, m_attributes, patternElement, tileBound
aries, tileImageTransform)) |
| 84 return 0; |
| 85 |
| 86 AffineTransform absoluteTransformIgnoringRotation; |
| 87 SVGRenderingContext::calculateTransformationToOutermostSVGCoordinateSystem(o
bject, absoluteTransformIgnoringRotation); |
| 88 |
| 89 // Ignore 2D rotation, as it doesn't affect the size of the tile. |
| 90 SVGRenderingContext::clear2DRotation(absoluteTransformIgnoringRotation); |
| 91 FloatRect absoluteTileBoundaries = absoluteTransformIgnoringRotation.mapRect
(tileBoundaries); |
| 92 FloatRect clampedAbsoluteTileBoundaries; |
| 93 |
| 94 // Scale the tile size to match the scale level of the patternTransform. |
| 95 absoluteTileBoundaries.scale(static_cast<float>(m_attributes.patternTransfor
m().xScale()), |
| 96 static_cast<float>(m_attributes.patternTransform().yScale())); |
| 97 |
| 98 // Build tile image. |
| 99 OwnPtr<ImageBuffer> tileImage = createTileImage(m_attributes, tileBoundaries
, absoluteTileBoundaries, tileImageTransform, clampedAbsoluteTileBoundaries); |
| 100 if (!tileImage) |
| 101 return 0; |
| 102 |
| 103 RefPtr<Image> copiedImage = tileImage->copyImage(CopyBackingStore); |
| 104 if (!copiedImage) |
| 105 return 0; |
| 106 |
| 107 // Build pattern. |
| 108 OwnPtr<PatternData> patternData = adoptPtr(new PatternData); |
| 109 patternData->pattern = Pattern::create(copiedImage, true, true); |
| 110 |
| 111 // Compute pattern space transformation. |
| 112 const IntSize tileImageSize = tileImage->logicalSize(); |
| 113 patternData->transform.translate(tileBoundaries.x(), tileBoundaries.y()); |
| 114 patternData->transform.scale(tileBoundaries.width() / tileImageSize.width(),
tileBoundaries.height() / tileImageSize.height()); |
| 115 |
| 116 AffineTransform patternTransform = m_attributes.patternTransform(); |
| 117 if (!patternTransform.isIdentity()) |
| 118 patternData->transform = patternTransform * patternData->transform; |
| 119 |
| 120 // Account for text drawing resetting the context to non-scaled, see SVGInli
neTextBox::paintTextWithShadows. |
| 121 if (resourceMode & ApplyToTextMode) { |
| 122 AffineTransform additionalTextTransformation; |
| 123 if (shouldTransformOnTextPainting(object, additionalTextTransformation)) |
| 124 patternData->transform *= additionalTextTransformation; |
| 125 } |
| 126 patternData->pattern->setPatternSpaceTransform(patternData->transform); |
| 127 |
| 128 // Various calls above may trigger invalidations in some fringe cases (Image
Buffer allocation |
| 129 // failures in the SVG image cache for example). To avoid having our Pattern
Data deleted by |
| 130 // removeAllClientsFromCache(), we only make it visible in the cache at the
very end. |
| 131 return m_patternMap.set(object, patternData.release()).iterator->value.get()
; |
| 132 } |
| 133 |
| 134 bool RenderSVGResourcePattern::applyResource(RenderObject* object, RenderStyle*
style, GraphicsContext*& context, unsigned short resourceMode) |
| 135 { |
| 136 ASSERT(object); |
| 137 ASSERT(style); |
| 138 ASSERT(context); |
| 139 ASSERT(resourceMode != ApplyToDefaultMode); |
| 140 |
81 // Spec: When the geometry of the applicable element has no width or height
and objectBoundingBox is specified, | 141 // Spec: When the geometry of the applicable element has no width or height
and objectBoundingBox is specified, |
82 // then the given effect (e.g. a gradient or a filter) will be ignored. | 142 // then the given effect (e.g. a gradient or a filter) will be ignored. |
83 FloatRect objectBoundingBox = object->objectBoundingBox(); | 143 FloatRect objectBoundingBox = object->objectBoundingBox(); |
84 if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDIN
GBOX && objectBoundingBox.isEmpty()) | 144 if (m_attributes.patternUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDIN
GBOX && objectBoundingBox.isEmpty()) |
85 return false; | 145 return false; |
86 | 146 |
87 OwnPtr<PatternData>& patternData = m_patternMap.add(object, nullptr).iterato
r->value; | 147 PatternData* patternData = buildPattern(object, resourceMode); |
88 if (!patternData) | 148 if (!patternData) |
89 patternData = adoptPtr(new PatternData); | 149 return false; |
90 | |
91 if (!patternData->pattern) { | |
92 // If we couldn't determine the pattern content element root, stop here. | |
93 if (!m_attributes.patternContentElement()) | |
94 return false; | |
95 | |
96 // Compute all necessary transformations to build the tile image & the p
attern. | |
97 FloatRect tileBoundaries; | |
98 AffineTransform tileImageTransform; | |
99 if (!buildTileImageTransform(object, m_attributes, patternElement, tileB
oundaries, tileImageTransform)) | |
100 return false; | |
101 | |
102 AffineTransform absoluteTransformIgnoringRotation; | |
103 SVGRenderingContext::calculateTransformationToOutermostSVGCoordinateSyst
em(object, absoluteTransformIgnoringRotation); | |
104 | |
105 // Ignore 2D rotation, as it doesn't affect the size of the tile. | |
106 SVGRenderingContext::clear2DRotation(absoluteTransformIgnoringRotation); | |
107 FloatRect absoluteTileBoundaries = absoluteTransformIgnoringRotation.map
Rect(tileBoundaries); | |
108 FloatRect clampedAbsoluteTileBoundaries; | |
109 | |
110 // Scale the tile size to match the scale level of the patternTransform. | |
111 absoluteTileBoundaries.scale(static_cast<float>(m_attributes.patternTran
sform().xScale()), | |
112 static_cast<float>(m_attributes.patternTransform().yScale())); | |
113 | |
114 // Build tile image. | |
115 OwnPtr<ImageBuffer> tileImage = createTileImage(m_attributes, tileBounda
ries, absoluteTileBoundaries, tileImageTransform, clampedAbsoluteTileBoundaries)
; | |
116 if (!tileImage) | |
117 return false; | |
118 | |
119 RefPtr<Image> copiedImage = tileImage->copyImage(CopyBackingStore); | |
120 if (!copiedImage) | |
121 return false; | |
122 | |
123 // Build pattern. | |
124 patternData->pattern = Pattern::create(copiedImage, true, true); | |
125 if (!patternData->pattern) | |
126 return false; | |
127 | |
128 // Compute pattern space transformation. | |
129 const IntSize tileImageSize = tileImage->logicalSize(); | |
130 patternData->transform.translate(tileBoundaries.x(), tileBoundaries.y())
; | |
131 patternData->transform.scale(tileBoundaries.width() / tileImageSize.widt
h(), tileBoundaries.height() / tileImageSize.height()); | |
132 | |
133 AffineTransform patternTransform = m_attributes.patternTransform(); | |
134 if (!patternTransform.isIdentity()) | |
135 patternData->transform = patternTransform * patternData->transform; | |
136 | |
137 // Account for text drawing resetting the context to non-scaled, see SVG
InlineTextBox::paintTextWithShadows. | |
138 if (resourceMode & ApplyToTextMode) { | |
139 AffineTransform additionalTextTransformation; | |
140 if (shouldTransformOnTextPainting(object, additionalTextTransformati
on)) | |
141 patternData->transform *= additionalTextTransformation; | |
142 } | |
143 patternData->pattern->setPatternSpaceTransform(patternData->transform); | |
144 } | |
145 | 150 |
146 // Draw pattern | 151 // Draw pattern |
147 context->save(); | 152 context->save(); |
148 | 153 |
149 const SVGRenderStyle* svgStyle = style->svgStyle(); | 154 const SVGRenderStyle* svgStyle = style->svgStyle(); |
150 ASSERT(svgStyle); | 155 ASSERT(svgStyle); |
151 | 156 |
152 if (resourceMode & ApplyToFillMode) { | 157 if (resourceMode & ApplyToFillMode) { |
153 context->setAlpha(svgStyle->fillOpacity()); | 158 context->setAlpha(svgStyle->fillOpacity()); |
154 context->setFillPattern(patternData->pattern); | 159 context->setFillPattern(patternData->pattern); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return nullptr; | 275 return nullptr; |
271 SVGRenderingContext::renderSubtreeToImageBuffer(tileImage.get(), node->r
enderer(), contentTransformation); | 276 SVGRenderingContext::renderSubtreeToImageBuffer(tileImage.get(), node->r
enderer(), contentTransformation); |
272 } | 277 } |
273 | 278 |
274 return tileImage.release(); | 279 return tileImage.release(); |
275 } | 280 } |
276 | 281 |
277 } | 282 } |
278 | 283 |
279 #endif | 284 #endif |
OLD | NEW |