Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: third_party/WebKit/Source/core/paint/SVGImagePainter.cpp

Issue 1427943002: Wrap SVGImage for container during paint (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/layout/ImageQualityController.h" 8 #include "core/layout/ImageQualityController.h"
9 #include "core/layout/LayoutImageResource.h" 9 #include "core/layout/LayoutImageResource.h"
10 #include "core/layout/svg/LayoutSVGImage.h" 10 #include "core/layout/svg/LayoutSVGImage.h"
(...skipping 13 matching lines...) Expand all
24 { 24 {
25 if (paintInfo.phase != PaintPhaseForeground 25 if (paintInfo.phase != PaintPhaseForeground
26 || m_layoutSVGImage.style()->visibility() == HIDDEN 26 || m_layoutSVGImage.style()->visibility() == HIDDEN
27 || !m_layoutSVGImage.imageResource()->hasImage()) 27 || !m_layoutSVGImage.imageResource()->hasImage())
28 return; 28 return;
29 29
30 FloatRect boundingBox = m_layoutSVGImage.paintInvalidationRectInLocalCoordin ates(); 30 FloatRect boundingBox = m_layoutSVGImage.paintInvalidationRectInLocalCoordin ates();
31 if (!paintInfo.cullRect().intersectsCullRect(m_layoutSVGImage.localToParentT ransform(), boundingBox)) 31 if (!paintInfo.cullRect().intersectsCullRect(m_layoutSVGImage.localToParentT ransform(), boundingBox))
32 return; 32 return;
33 33
34 FloatSize imageViewportSize = computeImageViewportSize();
35 if (imageViewportSize.isEmpty())
36 return;
fs 2015/11/16 15:08:07 Won't this mean that we could miss out on some of
davve 2015/11/16 16:32:40 Moving the check to SVGImagePainter::paintForegrou
fs 2015/11/16 16:43:21 Yes, computeImageViewport is fishy business (said
37
34 PaintInfo paintInfoBeforeFiltering(paintInfo); 38 PaintInfo paintInfoBeforeFiltering(paintInfo);
35 // Images cannot have children so do not call updateCullRect. 39 // Images cannot have children so do not call updateCullRect.
36 TransformRecorder transformRecorder(*paintInfoBeforeFiltering.context, m_lay outSVGImage, m_layoutSVGImage.localToParentTransform()); 40 TransformRecorder transformRecorder(*paintInfoBeforeFiltering.context, m_lay outSVGImage, m_layoutSVGImage.localToParentTransform());
37 { 41 {
38 SVGPaintContext paintContext(m_layoutSVGImage, paintInfoBeforeFiltering) ; 42 SVGPaintContext paintContext(m_layoutSVGImage, paintInfoBeforeFiltering) ;
39 if (paintContext.applyClipMaskAndFilterIfNecessary() && !LayoutObjectDra wingRecorder::useCachedDrawingIfPossible(*paintContext.paintInfo().context, m_la youtSVGImage, paintContext.paintInfo().phase, LayoutPoint())) { 43 if (paintContext.applyClipMaskAndFilterIfNecessary() && !LayoutObjectDra wingRecorder::useCachedDrawingIfPossible(*paintContext.paintInfo().context, m_la youtSVGImage, paintContext.paintInfo().phase, LayoutPoint())) {
40 LayoutObjectDrawingRecorder recorder(*paintContext.paintInfo().conte xt, m_layoutSVGImage, paintContext.paintInfo().phase, boundingBox, LayoutPoint() ); 44 LayoutObjectDrawingRecorder recorder(*paintContext.paintInfo().conte xt, m_layoutSVGImage, paintContext.paintInfo().phase, boundingBox, LayoutPoint() );
41 paintForeground(paintContext.paintInfo()); 45 paintForeground(paintContext.paintInfo(), imageViewportSize);
42 } 46 }
43 } 47 }
44 48
45 if (m_layoutSVGImage.style()->outlineWidth()) { 49 if (m_layoutSVGImage.style()->outlineWidth()) {
46 PaintInfo outlinePaintInfo(paintInfoBeforeFiltering); 50 PaintInfo outlinePaintInfo(paintInfoBeforeFiltering);
47 outlinePaintInfo.phase = PaintPhaseSelfOutline; 51 outlinePaintInfo.phase = PaintPhaseSelfOutline;
48 ObjectPainter(m_layoutSVGImage).paintOutline(outlinePaintInfo, LayoutPoi nt(boundingBox.location())); 52 ObjectPainter(m_layoutSVGImage).paintOutline(outlinePaintInfo, LayoutPoi nt(boundingBox.location()));
49 } 53 }
50 } 54 }
51 55
52 void SVGImagePainter::paintForeground(const PaintInfo& paintInfo) 56 void SVGImagePainter::paintForeground(const PaintInfo& paintInfo, const FloatSiz e& imageViewportSize)
53 { 57 {
54 RefPtr<Image> image = m_layoutSVGImage.imageResource()->image(IntSize()); 58 const LayoutImageResource* imageResource = m_layoutSVGImage.imageResource();
59
60 RefPtr<Image> image = imageResource->image(expandedIntSize(imageViewportSize ), m_layoutSVGImage.style()->effectiveZoom());
fs 2015/11/16 15:08:07 expandedIntSize used to be roundedIntSize I think,
davve 2015/11/16 16:32:40 Yes, I couldn't really make sense of that.
55 FloatRect destRect = m_layoutSVGImage.objectBoundingBox(); 61 FloatRect destRect = m_layoutSVGImage.objectBoundingBox();
56 FloatRect srcRect(0, 0, image->width(), image->height()); 62 FloatRect srcRect(0, 0, image->width(), image->height());
57 63
58 SVGImageElement* imageElement = toSVGImageElement(m_layoutSVGImage.element() ); 64 SVGImageElement* imageElement = toSVGImageElement(m_layoutSVGImage.element() );
59 imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect, srcRect); 65 imageElement->preserveAspectRatio()->currentValue()->transformRect(destRect, srcRect);
60 66
61 InterpolationQuality interpolationQuality = InterpolationDefault; 67 InterpolationQuality interpolationQuality = InterpolationDefault;
62 interpolationQuality = ImageQualityController::imageQualityController()->cho oseInterpolationQuality(paintInfo.context, &m_layoutSVGImage, image.get(), image .get(), LayoutSize(destRect.size())); 68 interpolationQuality = ImageQualityController::imageQualityController()->cho oseInterpolationQuality(paintInfo.context, &m_layoutSVGImage, image.get(), image .get(), LayoutSize(destRect.size()));
63 69
64 InterpolationQuality previousInterpolationQuality = paintInfo.context->image InterpolationQuality(); 70 InterpolationQuality previousInterpolationQuality = paintInfo.context->image InterpolationQuality();
65 paintInfo.context->setImageInterpolationQuality(interpolationQuality); 71 paintInfo.context->setImageInterpolationQuality(interpolationQuality);
66 paintInfo.context->drawImage(image.get(), destRect, srcRect, SkXfermode::kSr cOver_Mode); 72 paintInfo.context->drawImage(image.get(), destRect, srcRect, SkXfermode::kSr cOver_Mode);
67 paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality ); 73 paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality );
68 } 74 }
69 75
76 FloatSize SVGImagePainter::computeImageViewportSize() const
77 {
78 ASSERT(m_layoutSVGImage.imageResource()->hasImage());
79
80 if (toSVGImageElement(m_layoutSVGImage.element())->preserveAspectRatio()->cu rrentValue()->align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE)
81 return m_layoutSVGImage.objectBoundingBox().size();
82
83 ImageResource* cachedImage = m_layoutSVGImage.imageResource()->cachedImage() ;
84
85 // Images with preserveAspectRatio=none should force non-uniform
86 // scaling. This can be achieved by setting the image's container size to
87 // its viewport size (i.e. if a viewBox is available - use that - else use i ntrinsic size.)
88 // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The 'preserveAspectRa tio' attribute.
89 Length intrinsicWidth;
90 Length intrinsicHeight;
91 FloatSize intrinsicRatio;
92 cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, int rinsicRatio);
93 return intrinsicRatio;
94 }
95
70 } // namespace blink 96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698