Title: [143257] trunk
Revision
143257
Author
p...@google.com
Date
2013-02-18 13:25:32 -0800 (Mon, 18 Feb 2013)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (143256 => 143257)


--- trunk/LayoutTests/ChangeLog	2013-02-18 21:20:27 UTC (rev 143256)
+++ trunk/LayoutTests/ChangeLog	2013-02-18 21:25:32 UTC (rev 143257)
@@ -1,3 +1,13 @@
+2013-02-18  Philip Rogers  <p...@google.com>
+
+        Fix scaling of tiled SVG backgrounds on high-dpi displays
+        https://bugs.webkit.org/show_bug.cgi?id=110047
+
+        Reviewed by Dirk Schulze.
+
+        * svg/as-background-image/tiled-background-image-expected.html: Added.
+        * svg/as-background-image/tiled-background-image.html: Added.
+
 2013-02-18  David Hyatt  <hy...@apple.com>
 
         Make seamless iframes paginate properly in their enclosing document's pagination context.

Added: trunk/LayoutTests/svg/as-background-image/tiled-background-image-expected.html (0 => 143257)


--- trunk/LayoutTests/svg/as-background-image/tiled-background-image-expected.html	                        (rev 0)
+++ trunk/LayoutTests/svg/as-background-image/tiled-background-image-expected.html	2013-02-18 21:25:32 UTC (rev 143257)
@@ -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>

Added: trunk/LayoutTests/svg/as-background-image/tiled-background-image.html (0 => 143257)


--- trunk/LayoutTests/svg/as-background-image/tiled-background-image.html	                        (rev 0)
+++ trunk/LayoutTests/svg/as-background-image/tiled-background-image.html	2013-02-18 21:25:32 UTC (rev 143257)
@@ -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: trunk/Source/WebCore/ChangeLog (143256 => 143257)


--- trunk/Source/WebCore/ChangeLog	2013-02-18 21:20:27 UTC (rev 143256)
+++ trunk/Source/WebCore/ChangeLog	2013-02-18 21:25:32 UTC (rev 143257)
@@ -1,3 +1,29 @@
+2013-02-18  Philip Rogers  <p...@google.com>
+
+        Fix scaling of tiled SVG backgrounds on high-dpi displays
+        https://bugs.webkit.org/show_bug.cgi?id=110047
+
+        Reviewed by Dirk Schulze.
+
+        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.
+
 2013-02-18  David Hyatt  <hy...@apple.com>
 
         Make seamless iframes paginate properly in their enclosing document's pagination context.

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (143256 => 143257)


--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2013-02-18 21:20:27 UTC (rev 143256)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2013-02-18 21:25:32 UTC (rev 143257)
@@ -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