OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/paint/SVGImagePainter.h" | 6 #include "core/paint/SVGImagePainter.h" |
7 | 7 |
8 #include "core/paint/ObjectPainter.h" | 8 #include "core/paint/ObjectPainter.h" |
9 #include "core/rendering/GraphicsContextAnnotator.h" | 9 #include "core/rendering/GraphicsContextAnnotator.h" |
10 #include "core/rendering/ImageQualityController.h" | 10 #include "core/rendering/ImageQualityController.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 void SVGImagePainter::paint(const PaintInfo& paintInfo) | 23 void SVGImagePainter::paint(const PaintInfo& paintInfo) |
24 { | 24 { |
25 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderSVGImage); | 25 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, &m_renderSVGImage); |
26 | 26 |
27 if (paintInfo.phase != PaintPhaseForeground | 27 if (paintInfo.phase != PaintPhaseForeground |
28 || m_renderSVGImage.style()->visibility() == HIDDEN | 28 || m_renderSVGImage.style()->visibility() == HIDDEN |
29 || !m_renderSVGImage.imageResource()->hasImage()) | 29 || !m_renderSVGImage.imageResource()->hasImage()) |
30 return; | 30 return; |
31 | 31 |
32 FloatRect invalBox = m_renderSVGImage.paintInvalidationRectInLocalCoordinate
s(); | |
33 if (!SVGRenderSupport::paintInfoIntersectsPaintInvalidationRect(invalBox, m_
renderSVGImage.localToParentTransform(), paintInfo)) | |
34 return; | |
35 | |
36 PaintInfo childPaintInfo(paintInfo); | 32 PaintInfo childPaintInfo(paintInfo); |
37 GraphicsContextStateSaver stateSaver(*childPaintInfo.context, false); | 33 GraphicsContextStateSaver stateSaver(*childPaintInfo.context, false); |
38 | 34 |
39 childPaintInfo.applyTransform(m_renderSVGImage.localToParentTransform(), &st
ateSaver); | 35 childPaintInfo.applyTransform(m_renderSVGImage.localToParentTransform(), &st
ateSaver); |
40 | 36 |
41 // SVGRenderingContext may taint the state - make sure we're always saving. | 37 // SVGRenderingContext may taint the state - make sure we're always saving. |
42 stateSaver.saveIfNeeded(); | 38 stateSaver.saveIfNeeded(); |
43 | 39 |
44 SVGRenderingContext renderingContext(&m_renderSVGImage, childPaintInfo); | 40 SVGRenderingContext renderingContext(&m_renderSVGImage, childPaintInfo); |
45 if (renderingContext.isRenderingPrepared()) { | 41 if (renderingContext.isRenderingPrepared()) { |
46 if (m_renderSVGImage.style()->svgStyle().bufferedRendering() != BR_STATI
C) { | 42 if (m_renderSVGImage.style()->svgStyle().bufferedRendering() != BR_STATI
C) { |
47 paintForeground(childPaintInfo); | 43 paintForeground(childPaintInfo); |
48 } else { | 44 } else { |
49 RefPtr<const SkPicture>& bufferedForeground = m_renderSVGImage.buffe
redForeground(); | 45 RefPtr<const SkPicture>& bufferedForeground = m_renderSVGImage.buffe
redForeground(); |
50 if (!bufferedForeground) { | 46 if (!bufferedForeground) { |
51 childPaintInfo.context->beginRecording(m_renderSVGImage.objectBo
undingBox()); | 47 childPaintInfo.context->beginRecording(m_renderSVGImage.objectBo
undingBox()); |
52 paintForeground(childPaintInfo); | 48 paintForeground(childPaintInfo); |
53 bufferedForeground = childPaintInfo.context->endRecording(); | 49 bufferedForeground = childPaintInfo.context->endRecording(); |
54 } | 50 } |
55 | 51 |
56 childPaintInfo.context->drawPicture(bufferedForeground.get()); | 52 childPaintInfo.context->drawPicture(bufferedForeground.get()); |
57 } | 53 } |
58 } | 54 } |
59 | 55 |
60 if (m_renderSVGImage.style()->outlineWidth()) | 56 if (m_renderSVGImage.style()->outlineWidth()) |
61 ObjectPainter(m_renderSVGImage).paintOutline(childPaintInfo, IntRect(inv
alBox)); | 57 ObjectPainter(m_renderSVGImage).paintOutline(childPaintInfo, IntRect(m_r
enderSVGImage.paintInvalidationRectInLocalCoordinates())); |
62 } | 58 } |
63 | 59 |
64 void SVGImagePainter::paintForeground(const PaintInfo& paintInfo) | 60 void SVGImagePainter::paintForeground(const PaintInfo& paintInfo) |
65 { | 61 { |
66 RefPtr<Image> image = m_renderSVGImage.imageResource()->image(); | 62 RefPtr<Image> image = m_renderSVGImage.imageResource()->image(); |
67 FloatRect destRect = m_renderSVGImage.objectBoundingBox(); | 63 FloatRect destRect = m_renderSVGImage.objectBoundingBox(); |
68 FloatRect srcRect(0, 0, image->width(), image->height()); | 64 FloatRect srcRect(0, 0, image->width(), image->height()); |
69 | 65 |
70 SVGImageElement* imageElement = toSVGImageElement(m_renderSVGImage.element()
); | 66 SVGImageElement* imageElement = toSVGImageElement(m_renderSVGImage.element()
); |
71 imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect,
srcRect); | 67 imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect,
srcRect); |
72 | 68 |
73 InterpolationQuality interpolationQuality = InterpolationDefault; | 69 InterpolationQuality interpolationQuality = InterpolationDefault; |
74 if (m_renderSVGImage.style()->svgStyle().bufferedRendering() != BR_STATIC) | 70 if (m_renderSVGImage.style()->svgStyle().bufferedRendering() != BR_STATIC) |
75 interpolationQuality = ImageQualityController::imageQualityController()-
>chooseInterpolationQuality(paintInfo.context, &m_renderSVGImage, image.get(), i
mage.get(), LayoutSize(destRect.size())); | 71 interpolationQuality = ImageQualityController::imageQualityController()-
>chooseInterpolationQuality(paintInfo.context, &m_renderSVGImage, image.get(), i
mage.get(), LayoutSize(destRect.size())); |
76 | 72 |
77 InterpolationQuality previousInterpolationQuality = paintInfo.context->image
InterpolationQuality(); | 73 InterpolationQuality previousInterpolationQuality = paintInfo.context->image
InterpolationQuality(); |
78 paintInfo.context->setImageInterpolationQuality(interpolationQuality); | 74 paintInfo.context->setImageInterpolationQuality(interpolationQuality); |
79 paintInfo.context->drawImage(image.get(), destRect, srcRect, CompositeSource
Over); | 75 paintInfo.context->drawImage(image.get(), destRect, srcRect, CompositeSource
Over); |
80 paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality
); | 76 paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality
); |
81 } | 77 } |
82 | 78 |
83 } // namespace blink | 79 } // namespace blink |
OLD | NEW |