Commit 8e623735 authored by fmalita's avatar fmalita Committed by Commit bot

SVGImageForContainer::imageForCurrentFrame() needs to account for zoom

SVGImageForContainer tracks a container zoom factor independently of
the actual container size.  This zoom factor needs to be accounted for
in imageForCurrentFrame() -- otherwise we end up producing an SkImage
with a different size than reported by SVGImageForContainer::size().

The easiest way to accomplish this is to use size() when calling
SVGImage::imageForCurrentFrameForContainer(), instead of the unzoomed
m_containerSize.

BUG=643623
R=fs@opera.com,davve@opera.com

Review-Url: https://codereview.chromium.org/2323853002
Cr-Commit-Position: refs/heads/master@{#417504}
parent b03f8786
......@@ -150,6 +150,9 @@ crbug.com/563265 editing/spelling/spelling-unified-emulation.html [ Skip ]
crbug.com/538697 [ Win7 Debug ] virtual/threaded/printing/webgl-oversized-printing.html [ Failure Crash ]
crbug.com/538697 [ Win7 Debug ] printing/webgl-oversized-printing.html [ Failure Crash ]
# https://codereview.chromium.org/2323853002/
crbug.com/643623 fast/backgrounds/background-svg-scaling-zoom.html [ NeedsRebaseline ]
crbug.com/617152 imported/wpt/mediacapture-streams/GUM-impossible-constraint.https.html [ Skip ]
crbug.com/644433 virtual/gpu/fast/canvas/OffscreenCanvas-2d-pattern-in-worker.html [ Failure ]
......
layer at (0,0) size 800x600
LayoutView at (0,0) size 800x600
layer at (0,0) size 800x189
LayoutBlockFlow {HTML} at (0,0) size 800x189
LayoutBlockFlow {BODY} at (4,4) size 792x181
LayoutBlockFlow {DIV} at (0,0) size 25x25
LayoutText {#text} at (25,15) size 2x12
text run at (25,15) width 2: " "
LayoutBlockFlow {DIV} at (27,0) size 25x25
LayoutText {#text} at (52,15) size 2x12
text run at (52,15) width 2: " "
LayoutBlockFlow {DIV} at (54,0) size 25x25
LayoutText {#text} at (79,15) size 2x12
text run at (79,15) width 2: " "
LayoutBR {BR} at (0,0) size 0x0
LayoutBlockFlow {DIV} at (0,27) size 50x50
LayoutText {#text} at (50,67) size 2x12
text run at (50,67) width 2: " "
LayoutBlockFlow {DIV} at (52,27) size 50x50
LayoutText {#text} at (102,67) size 2x12
text run at (102,67) width 2: " "
LayoutBlockFlow {DIV} at (104,27) size 50x50
LayoutText {#text} at (154,67) size 2x12
text run at (154,67) width 2: " "
LayoutBR {BR} at (0,0) size 0x0
LayoutBlockFlow {DIV} at (0,79) size 100x100
LayoutText {#text} at (100,169) size 2x12
text run at (100,169) width 2: " "
LayoutBlockFlow {DIV} at (102,79) size 100x100
LayoutText {#text} at (202,169) size 2x12
text run at (202,169) width 2: " "
LayoutBlockFlow {DIV} at (204,79) size 100x100
LayoutText {#text} at (304,169) size 2x12
text run at (304,169) width 2: " "
LayoutBR {BR} at (0,0) size 0x0
<!DOCTYPE html>
<style>
body {
zoom: 0.5;
}
div {
display: inline-block;
border-radius: 1px;
background-image: url('data:image/svg+xml,\
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 10 10" stroke="green" stroke-width="2">\
<line x1="0" y1="0" x2="10" y2="10"/>\
<line x1="10" y1="0" x2="0" y2="10"/>\
</svg>');
}
</style>
<body>
<div style="width: 50px; height: 50px; background-size: 100px;"></div>
<div style="width: 50px; height: 50px; background-size: 50px;"></div>
<div style="width: 50px; height: 50px; background-size: 25px;"></div>
<br>
<div style="width: 100px; height: 100px; background-size: 200px;"></div>
<div style="width: 100px; height: 100px; background-size: 100px;"></div>
<div style="width: 100px; height: 100px; background-size: 50px;"></div>
<br>
<div style="width: 200px; height: 200px; background-size: 400px;"></div>
<div style="width: 200px; height: 200px; background-size: 200px;"></div>
<div style="width: 200px; height: 200px; background-size: 100px;"></div>
<br>
</body>
......@@ -251,7 +251,7 @@ void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl
sk_sp<SkImage> SVGImage::imageForCurrentFrame()
{
return imageForCurrentFrameForContainer(KURL(), FloatSize(size()));
return imageForCurrentFrameForContainer(KURL(), size());
}
void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize containerSize,
......@@ -289,23 +289,19 @@ void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize
context.drawRect(dstRect, paint);
}
sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const FloatSize& containerSize)
sk_sp<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const IntSize& containerSize)
{
if (!m_page)
return nullptr;
const FloatRect containerRect(FloatPoint(), containerSize);
const FloatRect containerRect((FloatPoint()), FloatSize(containerSize));
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(containerRect);
drawForContainer(canvas, SkPaint(), containerSize, 1, containerRect, containerRect, url);
drawForContainer(canvas, SkPaint(), containerRect.size(), 1, containerRect, containerRect, url);
const IntSize imageSize = roundedIntSize(containerSize);
const SkMatrix residualScale = SkMatrix::MakeScale(
static_cast<float>(imageSize.width()) / containerSize.width(),
static_cast<float>(imageSize.height()) / containerSize.height());
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
SkISize::Make(imageSize.width(), imageSize.height()), &residualScale, nullptr);
SkISize::Make(containerSize.width(), containerSize.height()), nullptr, nullptr);
}
static bool drawNeedsLayer(const SkPaint& paint)
......
......@@ -111,7 +111,7 @@ private:
void drawForContainer(SkCanvas*, const SkPaint&, const FloatSize, float, const FloatRect&, const FloatRect&, const KURL&);
void drawPatternForContainer(GraphicsContext&, const FloatSize, float, const FloatRect&, const FloatSize&, const FloatPoint&,
SkXfermode::Mode, const FloatRect&, const FloatSize& repeatSpacing, const KURL&);
sk_sp<SkImage> imageForCurrentFrameForContainer(const KURL&, const FloatSize& containerSize);
sk_sp<SkImage> imageForCurrentFrameForContainer(const KURL&, const IntSize& containerSize);
void drawInternal(SkCanvas*, const SkPaint&, const FloatRect& fromRect, const FloatRect& toRect, RespectImageOrientationEnum,
ImageClampingMode, const KURL&);
......
......@@ -53,7 +53,7 @@ void SVGImageForContainer::drawPattern(GraphicsContext& context, const FloatRect
sk_sp<SkImage> SVGImageForContainer::imageForCurrentFrame()
{
return m_image->imageForCurrentFrameForContainer(m_url, m_containerSize);
return m_image->imageForCurrentFrameForContainer(m_url, size());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment