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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
diff --git a/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp b/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
index 1f1be3863911238d9340fbb289e22b3cfab9f0a9..126324c1b5351083e4234d381434091be90e2c89 100644
--- a/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
+++ b/third_party/WebKit/Source/core/paint/SVGImagePainter.cpp
@@ -31,6 +31,10 @@ void SVGImagePainter::paint(const PaintInfo& paintInfo)
if (!paintInfo.cullRect().intersectsCullRect(m_layoutSVGImage.localToParentTransform(), boundingBox))
return;
+ FloatSize imageViewportSize = computeImageViewportSize();
+ if (imageViewportSize.isEmpty())
+ 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
+
PaintInfo paintInfoBeforeFiltering(paintInfo);
// Images cannot have children so do not call updateCullRect.
TransformRecorder transformRecorder(*paintInfoBeforeFiltering.context, m_layoutSVGImage, m_layoutSVGImage.localToParentTransform());
@@ -38,7 +42,7 @@ void SVGImagePainter::paint(const PaintInfo& paintInfo)
SVGPaintContext paintContext(m_layoutSVGImage, paintInfoBeforeFiltering);
if (paintContext.applyClipMaskAndFilterIfNecessary() && !LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*paintContext.paintInfo().context, m_layoutSVGImage, paintContext.paintInfo().phase, LayoutPoint())) {
LayoutObjectDrawingRecorder recorder(*paintContext.paintInfo().context, m_layoutSVGImage, paintContext.paintInfo().phase, boundingBox, LayoutPoint());
- paintForeground(paintContext.paintInfo());
+ paintForeground(paintContext.paintInfo(), imageViewportSize);
}
}
@@ -49,9 +53,11 @@ void SVGImagePainter::paint(const PaintInfo& paintInfo)
}
}
-void SVGImagePainter::paintForeground(const PaintInfo& paintInfo)
+void SVGImagePainter::paintForeground(const PaintInfo& paintInfo, const FloatSize& imageViewportSize)
{
- RefPtr<Image> image = m_layoutSVGImage.imageResource()->image(IntSize());
+ const LayoutImageResource* imageResource = m_layoutSVGImage.imageResource();
+
+ 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.
FloatRect destRect = m_layoutSVGImage.objectBoundingBox();
FloatRect srcRect(0, 0, image->width(), image->height());
@@ -67,4 +73,24 @@ void SVGImagePainter::paintForeground(const PaintInfo& paintInfo)
paintInfo.context->setImageInterpolationQuality(previousInterpolationQuality);
}
+FloatSize SVGImagePainter::computeImageViewportSize() const
+{
+ ASSERT(m_layoutSVGImage.imageResource()->hasImage());
+
+ if (toSVGImageElement(m_layoutSVGImage.element())->preserveAspectRatio()->currentValue()->align() != SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE)
+ return m_layoutSVGImage.objectBoundingBox().size();
+
+ ImageResource* cachedImage = m_layoutSVGImage.imageResource()->cachedImage();
+
+ // Images with preserveAspectRatio=none should force non-uniform
+ // scaling. This can be achieved by setting the image's container size to
+ // its viewport size (i.e. if a viewBox is available - use that - else use intrinsic size.)
+ // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The 'preserveAspectRatio' attribute.
+ Length intrinsicWidth;
+ Length intrinsicHeight;
+ FloatSize intrinsicRatio;
+ cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
+ return intrinsicRatio;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698