Title: [165127] trunk
Revision
165127
Author
[email protected]
Date
2014-03-05 13:56:51 -0800 (Wed, 05 Mar 2014)

Log Message

Subpixel rendering: Device pixel round accumulated subpixel value when the RenderLayer with transform paints its content.
https://bugs.webkit.org/show_bug.cgi?id=129079

Reviewed by Simon Fraser.

Snap the content to the device pixel position (as opposed to integral position) before
applying the transform. Recalculate the remaining subpixels that need offsetting at painting time.

Source/WebCore:

Test: compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html

* platform/graphics/LayoutPoint.h:
(WebCore::roundedForPainting):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::paintLayerByApplyingTransform):

LayoutTests:

* compositing/hidpi-absolute-subpixel-positioned-transformed-elements-expected.html: Added.
* compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (165126 => 165127)


--- trunk/LayoutTests/ChangeLog	2014-03-05 21:40:30 UTC (rev 165126)
+++ trunk/LayoutTests/ChangeLog	2014-03-05 21:56:51 UTC (rev 165127)
@@ -1,3 +1,16 @@
+2014-03-05  Zalan Bujtas  <[email protected]>
+
+        Subpixel rendering: Device pixel round accumulated subpixel value when the RenderLayer with transform paints its content.
+        https://bugs.webkit.org/show_bug.cgi?id=129079
+
+        Reviewed by Simon Fraser.
+
+        Snap the content to the device pixel position (as opposed to integral position) before
+        applying the transform. Recalculate the remaining subpixels that need offsetting at painting time.
+
+        * compositing/hidpi-absolute-subpixel-positioned-transformed-elements-expected.html: Added.
+        * compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html: Added.
+
 2014-03-05  Michael Saboff  <[email protected]>
 
         JSDataViewPrototype::getData() and setData() crash on platforms that don't allow unaligned accesses

Added: trunk/LayoutTests/compositing/hidpi-absolute-subpixel-positioned-transformed-elements-expected.html (0 => 165127)


--- trunk/LayoutTests/compositing/hidpi-absolute-subpixel-positioned-transformed-elements-expected.html	                        (rev 0)
+++ trunk/LayoutTests/compositing/hidpi-absolute-subpixel-positioned-transformed-elements-expected.html	2014-03-05 21:56:51 UTC (rev 165127)
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that applying rotation on a subpixel (absolute)positioned box does not change its position/size.</title>
+<head>
+<style>
+  div {
+    background: green;
+    width: 9px;
+    height: 9px;
+    position: absolute;
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var container = document.getElementById("container");
+  adjustment = 0.1;
+  for (i = 0; i < 10; ++i) {
+    adjustment+=0.1;
+    for (j = 0; j < 10; ++j) {
+      var e = document.createElement("div");
+      e.style.top = (11 * i + j * adjustment) + "px";
+      e.style.left = (11 * j + i * adjustment) + "px";
+      container.appendChild(e);
+    }
+  }
+</script>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html (0 => 165127)


--- trunk/LayoutTests/compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html	                        (rev 0)
+++ trunk/LayoutTests/compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html	2014-03-05 21:56:51 UTC (rev 165127)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that applying rotation on a subpixel (absolute)positioned box does not change its position/size.</title>
+<head>
+<style>
+  div {
+    background: green;
+    width: 9px;
+    height: 9px;
+    position: absolute;
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var container = document.getElementById("container");
+  adjustment = 0.1;
+  for (i = 0; i < 10; ++i) {
+    adjustment+=0.1;
+    for (j = 0; j < 10; ++j) {
+      var e = document.createElement("div");
+      e.style.top = (11 * i + j * adjustment) + "px";
+      e.style.left = (11 * j + i * adjustment) + "px";
+      container.appendChild(e);
+    }
+  }
+  
+  function rotate() {
+     divs = document.getElementsByTagName("div");
+     for (i = 0; i < divs.length; ++i)
+       divs[i].style.webkitTransform = "rotate(90deg)";
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+  }
+
+  if (window.testRunner)
+    testRunner.waitUntilDone();
+
+  setTimeout(rotate, 0);
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (165126 => 165127)


--- trunk/Source/WebCore/ChangeLog	2014-03-05 21:40:30 UTC (rev 165126)
+++ trunk/Source/WebCore/ChangeLog	2014-03-05 21:56:51 UTC (rev 165127)
@@ -1,3 +1,20 @@
+2014-03-05  Zalan Bujtas  <[email protected]>
+
+        Subpixel rendering: Device pixel round accumulated subpixel value when the RenderLayer with transform paints its content.
+        https://bugs.webkit.org/show_bug.cgi?id=129079
+
+        Reviewed by Simon Fraser.
+
+        Snap the content to the device pixel position (as opposed to integral position) before
+        applying the transform. Recalculate the remaining subpixels that need offsetting at painting time.
+
+        Test: compositing/hidpi-absolute-subpixel-positioned-transformed-elements.html
+
+        * platform/graphics/LayoutPoint.h:
+        (WebCore::roundedForPainting):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::paintLayerByApplyingTransform):
+
 2014-03-05  Eric Carlson  <[email protected]>
 
         [iOS] Show external device name/type in placeholder

Modified: trunk/Source/WebCore/platform/graphics/LayoutPoint.h (165126 => 165127)


--- trunk/Source/WebCore/platform/graphics/LayoutPoint.h	2014-03-05 21:40:30 UTC (rev 165126)
+++ trunk/Source/WebCore/platform/graphics/LayoutPoint.h	2014-03-05 21:56:51 UTC (rev 165127)
@@ -185,6 +185,16 @@
     return IntSize(snapSizeToPixel(s.width(), p.x()), snapSizeToPixel(s.height(), p.y()));
 }
 
+inline FloatPoint roundedForPainting(const LayoutPoint& point, float pixelSnappingFactor)
+{
+#if ENABLE(SUBPIXEL_LAYOUT)
+    return FloatPoint(roundToDevicePixel(point.x(), pixelSnappingFactor), roundToDevicePixel(point.y(), pixelSnappingFactor));
+#else
+    UNUSED_PARAM(pixelSnappingFactor);
+    return FloatPoint(point);
+#endif
+}
+
 inline FloatPoint flooredForPainting(const LayoutPoint& point, float pixelSnappingFactor)
 {
 #if ENABLE(SUBPIXEL_LAYOUT)

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (165126 => 165127)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2014-03-05 21:40:30 UTC (rev 165126)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2014-03-05 21:56:51 UTC (rev 165127)
@@ -4167,20 +4167,21 @@
 {
     // This involves subtracting out the position of the layer in our current coordinate space, but preserving
     // the accumulated error for sub-pixel layout.
+    float deviceScaleFactor = renderer().document().deviceScaleFactor();
     LayoutPoint delta;
     convertToLayerCoords(paintingInfo.rootLayer, delta);
     delta.moveBy(translationOffset);
     TransformationMatrix transform(renderableTransform(paintingInfo.paintBehavior));
-    IntPoint roundedDelta = roundedIntPoint(delta);
+    FloatPoint roundedDelta = roundedForPainting(delta, deviceScaleFactor);
     transform.translateRight(roundedDelta.x(), roundedDelta.y());
-    LayoutSize adjustedSubPixelAccumulation = paintingInfo.subPixelAccumulation + (delta - roundedDelta);
+    LayoutSize adjustedSubPixelAccumulation = paintingInfo.subPixelAccumulation + (delta - LayoutPoint(roundedDelta));
 
     // Apply the transform.
     GraphicsContextStateSaver stateSaver(*context);
     context->concatCTM(transform.toAffineTransform());
 
     // Now do a paint with the root layer shifted to be us.
-    LayerPaintingInfo transformedPaintingInfo(this, enclosingIntRect(transform.inverse().mapRect(paintingInfo.paintDirtyRect)), paintingInfo.paintBehavior,
+    LayerPaintingInfo transformedPaintingInfo(this, LayoutRect(enclosingRectForPainting(transform.inverse().mapRect(paintingInfo.paintDirtyRect), deviceScaleFactor)), paintingInfo.paintBehavior,
         adjustedSubPixelAccumulation, paintingInfo.subtreePaintRoot, paintingInfo.renderNamedFlowFragment, paintingInfo.overlapTestRequests);
     paintLayerContentsAndReflection(context, transformedPaintingInfo, paintFlags);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to