| 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 | 22 |
| 23 #include "core/rendering/svg/RenderSVGResourcePattern.h" | 23 #include "core/rendering/svg/RenderSVGResourcePattern.h" |
| 24 | 24 |
| 25 #include "core/platform/graphics/GraphicsContext.h" | 25 #include "core/platform/graphics/GraphicsContext.h" |
| 26 #include "core/rendering/svg/SVGRenderSupport.h" | 26 #include "core/rendering/svg/SVGRenderSupport.h" |
| 27 #include "core/rendering/svg/SVGRenderingContext.h" | 27 #include "core/rendering/svg/SVGRenderingContext.h" |
| 28 #include "core/svg/SVGFitToViewBox.h" | 28 #include "core/svg/SVGFitToViewBox.h" |
| 29 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 29 | 30 |
| 30 namespace WebCore { | 31 namespace WebCore { |
| 31 | 32 |
| 32 const RenderSVGResourceType RenderSVGResourcePattern::s_resourceType = PatternRe
sourceType; | 33 const RenderSVGResourceType RenderSVGResourcePattern::s_resourceType = PatternRe
sourceType; |
| 33 | 34 |
| 34 RenderSVGResourcePattern::RenderSVGResourcePattern(SVGPatternElement* node) | 35 RenderSVGResourcePattern::RenderSVGResourcePattern(SVGPatternElement* node) |
| 35 : RenderSVGResourceContainer(node) | 36 : RenderSVGResourceContainer(node) |
| 36 , m_shouldCollectPatternAttributes(true) | 37 , m_shouldCollectPatternAttributes(true) |
| 37 { | 38 { |
| 38 } | 39 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 234 } |
| 234 | 235 |
| 235 PassOwnPtr<ImageBuffer> RenderSVGResourcePattern::createTileImage(const PatternA
ttributes& attributes, | 236 PassOwnPtr<ImageBuffer> RenderSVGResourcePattern::createTileImage(const PatternA
ttributes& attributes, |
| 236 const FloatRec
t& tileBoundaries, | 237 const FloatRec
t& tileBoundaries, |
| 237 const FloatRec
t& absoluteTileBoundaries, | 238 const FloatRec
t& absoluteTileBoundaries, |
| 238 const AffineTr
ansform& tileImageTransform, | 239 const AffineTr
ansform& tileImageTransform, |
| 239 FloatRect& cla
mpedAbsoluteTileBoundaries) const | 240 FloatRect& cla
mpedAbsoluteTileBoundaries) const |
| 240 { | 241 { |
| 241 clampedAbsoluteTileBoundaries = SVGRenderingContext::clampedAbsoluteTargetRe
ct(absoluteTileBoundaries); | 242 clampedAbsoluteTileBoundaries = SVGRenderingContext::clampedAbsoluteTargetRe
ct(absoluteTileBoundaries); |
| 242 | 243 |
| 243 OwnPtr<ImageBuffer> tileImage = ImageBuffer::createBufferForTile(absoluteTil
eBoundaries.size(), clampedAbsoluteTileBoundaries.size(), Unaccelerated); | 244 IntSize imageSize(roundedIntSize(clampedAbsoluteTileBoundaries.size())); |
| 244 if (!tileImage) | 245 if (imageSize.isEmpty()) |
| 245 return nullptr; | 246 return nullptr; |
| 247 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu
rface(imageSize)); |
| 248 if (!surface->isValid()) |
| 249 return nullptr; |
| 250 OwnPtr<ImageBuffer> tileImage = adoptPtr(new ImageBuffer(surface.release()))
; |
| 246 | 251 |
| 247 GraphicsContext* tileImageContext = tileImage->context(); | 252 GraphicsContext* tileImageContext = tileImage->context(); |
| 248 ASSERT(tileImageContext); | 253 ASSERT(tileImageContext); |
| 254 IntSize unclampedImageSize(roundedIntSize(absoluteTileBoundaries.size())); |
| 255 tileImageContext->scale(FloatSize(unclampedImageSize.width() / absoluteTileB
oundaries.width(), unclampedImageSize.height() / absoluteTileBoundaries.height()
)); |
| 249 | 256 |
| 250 // The image buffer represents the final rendered size, so the content has t
o be scaled (to avoid pixelation). | 257 // The image buffer represents the final rendered size, so the content has t
o be scaled (to avoid pixelation). |
| 251 tileImageContext->scale(FloatSize(clampedAbsoluteTileBoundaries.width() / ti
leBoundaries.width(), | 258 tileImageContext->scale(FloatSize(clampedAbsoluteTileBoundaries.width() / ti
leBoundaries.width(), |
| 252 clampedAbsoluteTileBoundaries.height() / t
ileBoundaries.height())); | 259 clampedAbsoluteTileBoundaries.height() / t
ileBoundaries.height())); |
| 253 | 260 |
| 254 // Apply tile image transformations. | 261 // Apply tile image transformations. |
| 255 if (!tileImageTransform.isIdentity()) | 262 if (!tileImageTransform.isIdentity()) |
| 256 tileImageContext->concatCTM(tileImageTransform); | 263 tileImageContext->concatCTM(tileImageTransform); |
| 257 | 264 |
| 258 AffineTransform contentTransformation; | 265 AffineTransform contentTransformation; |
| 259 if (attributes.patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBO
UNDINGBOX) | 266 if (attributes.patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBO
UNDINGBOX) |
| 260 contentTransformation = tileImageTransform; | 267 contentTransformation = tileImageTransform; |
| 261 | 268 |
| 262 // Draw the content into the ImageBuffer. | 269 // Draw the content into the ImageBuffer. |
| 263 for (Node* node = attributes.patternContentElement()->firstChild(); node; no
de = node->nextSibling()) { | 270 for (Node* node = attributes.patternContentElement()->firstChild(); node; no
de = node->nextSibling()) { |
| 264 if (!node->isSVGElement() || !node->renderer()) | 271 if (!node->isSVGElement() || !node->renderer()) |
| 265 continue; | 272 continue; |
| 266 if (node->renderer()->needsLayout()) | 273 if (node->renderer()->needsLayout()) |
| 267 return nullptr; | 274 return nullptr; |
| 268 SVGRenderingContext::renderSubtree(tileImage->context(), node->renderer(
), contentTransformation); | 275 SVGRenderingContext::renderSubtree(tileImage->context(), node->renderer(
), contentTransformation); |
| 269 } | 276 } |
| 270 | 277 |
| 271 return tileImage.release(); | 278 return tileImage.release(); |
| 272 } | 279 } |
| 273 | 280 |
| 274 } | 281 } |
| OLD | NEW |