Title: [144238] branches/chromium/1410
Revision
144238
Author
p...@google.com
Date
2013-02-27 14:22:08 -0800 (Wed, 27 Feb 2013)

Log Message

Merge 143257
> Fix scaling of tiled SVG backgrounds on high-dpi displays
> https://bugs.webkit.org/show_bug.cgi?id=110047
> 
> Reviewed by Dirk Schulze.
> 
> Source/WebCore:
> 
> This patch fixes the scaling of SVG when used for drawing patterns. Tiled/patterend SVG
> images are first drawn into an image buffer and then the image buffer is used to stamp
> out tiles. Because it is a raster source, the size of the image buffer needs to
> be scaled to the final resolution of the device. After scaling the image buffer, the
> source rect and pattern transforms need to be adjusted so they align in device pixel
> coordinates. This adjustment was not done before this patch, causing pixelated rendering.
> 
> Additionally, a FIXME has been added due to webkit.org/b/110065 and the image buffer
> has been manually scaled (using "zoomedAndScaledContainerRect") instead of relying
> on the ImageBuffer's resolutionScale parameter.
> 
> Test: svg/as-background-image/tiled-background-image.html
> 
> * svg/graphics/SVGImage.cpp:
> (WebCore::SVGImage::drawPatternForContainer):
> 
>     Note that fixing the FIXME does not change that the source rect and transform need
>     to be adjusted for page scale.
> 
> LayoutTests:
> 
> * svg/as-background-image/tiled-background-image-expected.html: Added.
> * svg/as-background-image/tiled-background-image.html: Added.
> 

TBR=p...@google.com
Review URL: https://codereview.chromium.org/12326167

Modified Paths

Added Paths

Diff

Copied: branches/chromium/1410/LayoutTests/svg/as-background-image/tiled-background-image-expected.html (from rev 143257, trunk/LayoutTests/svg/as-background-image/tiled-background-image-expected.html) (0 => 144238)


--- branches/chromium/1410/LayoutTests/svg/as-background-image/tiled-background-image-expected.html	                        (rev 0)
+++ branches/chromium/1410/LayoutTests/svg/as-background-image/tiled-background-image-expected.html	2013-02-27 22:22:08 UTC (rev 144238)
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+  #div {
+    width: 64px;
+    height: 128px;
+    background-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="128"><circle fill="#3364c2" cx="16" cy="16" r="16" /><circle fill="#f31900" cx="16" cy="48" r="16" /><circle fill="#f7d72b" cx="16" cy="80" r="16" /><circle fill="#44c400" cx="16" cy="112" r="16" /></svg>');
+    background-size: 32px 128px;
+    background-repeat: repeat;
+  }
+  p {
+    font-size: x-small;
+  }
+</style>
+<script>
+  function setScale() {
+    if (window.internals)
+      window.internals.setPageScaleFactor(2, 0, 0);
+  }
+</script>
+</head>
+<body _onload_="setScale()">
+<div id="div"></div>
+<p>Test for WK110047: This test passes if there are 4 rows of 2 circles and they all have sharp edges.</p>
+</body>
+</html>

Copied: branches/chromium/1410/LayoutTests/svg/as-background-image/tiled-background-image.html (from rev 143257, trunk/LayoutTests/svg/as-background-image/tiled-background-image.html) (0 => 144238)


--- branches/chromium/1410/LayoutTests/svg/as-background-image/tiled-background-image.html	                        (rev 0)
+++ branches/chromium/1410/LayoutTests/svg/as-background-image/tiled-background-image.html	2013-02-27 22:22:08 UTC (rev 144238)
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+  #div1 {
+    width: 64px;
+    height: 32px;
+    background-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><circle fill="#3364c2" cx="64" cy="64" r="64" /></svg>');
+    background-size: 32px 32px;
+    background-repeat: repeat;
+  }
+  #div2 {
+    width: 64px;
+    height: 32px;
+    background-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><circle fill="#f31900" cx="64" cy="64" r="64" /></svg>');
+    background-size: 50% 100%;
+    background-repeat: repeat;
+  }
+  #div3 {
+    width: 64px;
+    height: 32px;
+    background-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><circle fill="#f7d72b" cx="16" cy="16" r="16" /></svg>');
+    background-size: 32px 32px;
+    background-repeat: repeat;
+  }
+  #div4 {
+    width: 64px;
+    height: 32px;
+    background-image:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><circle fill="#44c400" cx="16" cy="16" r="16" /></svg>');
+    background-size: 50% 100%;
+    background-repeat: repeat;
+  }
+  p {
+    font-size: x-small;
+  }
+</style>
+<script>
+  function setScale() {
+    if (window.internals)
+      window.internals.setPageScaleFactor(2, 0, 0);
+  }
+</script>
+</head>
+<body _onload_="setScale()">
+<div id="div1"></div>
+<div id="div2"></div>
+<div id="div3"></div>
+<div id="div4"></div>
+<p>Test for WK110047: This test passes if there are 4 rows of 2 circles and they all have sharp edges.</p>
+</body>
+</html>

Modified: branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.cpp (144237 => 144238)


--- branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.cpp	2013-02-27 22:10:11 UTC (rev 144237)
+++ branches/chromium/1410/Source/WebCore/svg/graphics/SVGImage.cpp	2013-02-27 22:22:08 UTC (rev 144238)
@@ -144,15 +144,25 @@
 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, float pageScale, float zoom, const FloatRect& srcRect,
     const AffineTransform& patternTransform, const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator compositeOp, const FloatRect& dstRect)
 {
-    FloatSize zoomedContainerSize(containerSize);
-    zoomedContainerSize.scale(zoom);
-    FloatRect zoomedContainerRect = FloatRect(FloatPoint(), zoomedContainerSize);
+    ASSERT(pageScale);
 
-    OwnPtr<ImageBuffer> buffer = ImageBuffer::create(expandedIntSize(zoomedContainerSize), pageScale);
-    drawForContainer(buffer->context(), containerSize, zoom, zoomedContainerRect, zoomedContainerRect, ColorSpaceDeviceRGB, CompositeSourceOver, BlendModeNormal);
+    FloatRect zoomedContainerRect = FloatRect(FloatPoint(), containerSize);
+    zoomedContainerRect.scale(zoom);
+    FloatRect zoomedAndScaledContainerRect = zoomedContainerRect;
+    zoomedAndScaledContainerRect.scale(pageScale);
 
-    RefPtr<Image> image = buffer->copyImage(CopyBackingStore);
-    image->drawPattern(context, srcRect, patternTransform, phase, colorSpace, compositeOp, dstRect);
+    // FIXME(WK110065): This should take advantage of the ImageBuffer resolution instead of scaling the buffer manually.
+    OwnPtr<ImageBuffer> buffer = ImageBuffer::create(expandedIntSize(zoomedAndScaledContainerRect.size()), 1);
+    drawForContainer(buffer->context(), containerSize, zoom, zoomedAndScaledContainerRect, zoomedContainerRect, ColorSpaceDeviceRGB, CompositeSourceOver, BlendModeNormal);
+    RefPtr<Image> image = buffer->copyImage(CopyBackingStore, Unscaled);
+
+    // Adjust the source rect and transform for image buffer scale due to pageScale.
+    FloatRect scaledSrcRect = srcRect;
+    scaledSrcRect.scale(pageScale);
+    AffineTransform unscaledPatternTransform(patternTransform);
+    unscaledPatternTransform.scale(1 / pageScale);
+
+    image->drawPattern(context, scaledSrcRect, unscaledPatternTransform, phase, colorSpace, compositeOp, dstRect);
 }
 
 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp, BlendMode)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to