OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/paint/SVGImagePainter.h" |
| 7 |
| 8 #include "core/paint/ObjectPainter.h" |
| 9 #include "core/rendering/GraphicsContextAnnotator.h" |
| 10 #include "core/rendering/ImageQualityController.h" |
| 11 #include "core/rendering/PaintInfo.h" |
| 12 #include "core/rendering/RenderImageResource.h" |
| 13 #include "core/rendering/svg/RenderSVGImage.h" |
| 14 #include "core/rendering/svg/SVGRenderSupport.h" |
| 15 #include "core/rendering/svg/SVGRenderingContext.h" |
| 16 #include "core/svg/SVGImageElement.h" |
| 17 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 18 |
| 19 namespace blink { |
| 20 |
| 21 void SVGImagePainter::paint(PaintInfo& paintInfo) |
| 22 { |
| 23 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderSVGImage); |
| 24 |
| 25 if (paintInfo.phase != PaintPhaseForeground |
| 26 || m_renderSVGImage.style()->visibility() == HIDDEN |
| 27 || !m_renderSVGImage.imageResource()->hasImage()) |
| 28 return; |
| 29 |
| 30 FloatRect boundingBox = m_renderSVGImage.paintInvalidationRectInLocalCoordin
ates(); |
| 31 if (!SVGRenderSupport::paintInfoIntersectsPaintInvalidationRect(boundingBox,
m_renderSVGImage.localToParentTransform(), paintInfo)) |
| 32 return; |
| 33 |
| 34 PaintInfo childPaintInfo(paintInfo); |
| 35 GraphicsContextStateSaver stateSaver(*childPaintInfo.context, false); |
| 36 |
| 37 if (!m_renderSVGImage.localToParentTransform().isIdentity()) { |
| 38 stateSaver.save(); |
| 39 childPaintInfo.applyTransform(m_renderSVGImage.localToParentTransform(),
false); |
| 40 } |
| 41 if (!m_renderSVGImage.objectBoundingBox().isEmpty()) { |
| 42 // SVGRenderingContext may taint the state - make sure we're always savi
ng. |
| 43 SVGRenderingContext renderingContext(&m_renderSVGImage, childPaintInfo,
stateSaver.saved() ? |
| 44 SVGRenderingContext::DontSaveGraphicsContext : SVGRenderingContext::
SaveGraphicsContext); |
| 45 |
| 46 if (renderingContext.isRenderingPrepared()) { |
| 47 if (m_renderSVGImage.style()->svgStyle().bufferedRendering() == BR_S
TATIC && renderingContext.bufferForeground(m_renderSVGImage.bufferedForeground()
)) |
| 48 return; |
| 49 |
| 50 paintForeground(m_renderSVGImage, childPaintInfo); |
| 51 } |
| 52 } |
| 53 |
| 54 if (m_renderSVGImage.style()->outlineWidth()) |
| 55 ObjectPainter(m_renderSVGImage).paintOutline(childPaintInfo, IntRect(bou
ndingBox)); |
| 56 } |
| 57 |
| 58 void SVGImagePainter::paintForeground(RenderSVGImage& renderer, PaintInfo& paint
Info) |
| 59 { |
| 60 RefPtr<Image> image = renderer.imageResource()->image(); |
| 61 FloatRect destRect = renderer.objectBoundingBox(); |
| 62 FloatRect srcRect(0, 0, image->width(), image->height()); |
| 63 |
| 64 SVGImageElement* imageElement = toSVGImageElement(renderer.element()); |
| 65 imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect,
srcRect); |
| 66 |
| 67 InterpolationQuality interpolationQuality = InterpolationDefault; |
| 68 if (renderer.style()->svgStyle().bufferedRendering() != BR_STATIC) |
| 69 interpolationQuality = ImageQualityController::imageQualityController()-
>chooseInterpolationQuality(paintInfo.context, &renderer, image.get(), image.get
(), LayoutSize(destRect.size())); |
| 70 |
| 71 InterpolationQuality previousInterpolationQuality = paintInfo.context->image
InterpolationQuality(); |
| 72 paintInfo.context->setImageInterpolationQuality(interpolationQuality); |
| 73 paintInfo.context->drawImage(image.get(), destRect, srcRect, CompositeSource
Over); |
| 74 paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality
); |
| 75 } |
| 76 |
| 77 } // namespace blink |
OLD | NEW |