Subpixel rendering: Enable compositing RenderLayer painting on device pixel position.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Feb 2014 23:04:20 +0000 (23:04 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Feb 2014 23:04:20 +0000 (23:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128509

Reviewed by Simon Fraser.

GraphicsLayer is now positioned on device pixel boundary. This enables us to put
compositing layers on a subpixel position and animate them with device pixel
precision.

Source/WebCore:

Tests: fast/sub-pixel/compositing-layers-on-subpixel-position.html
       fast/sub-pixel/simple-clipping.html

* platform/LayoutUnit.h:
(WebCore::ceilToDevicePixel):
* platform/graphics/LayoutPoint.h:
(WebCore::flooredForPainting):
(WebCore::ceiledForPainting):
* platform/graphics/LayoutRect.cpp:
(WebCore::enclosingRectForPainting):
* platform/graphics/LayoutRect.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::clipToRect):
* rendering/RenderLayerBacking.cpp:
(WebCore::clipBox):
(WebCore::pixelFractionForLayerPainting):
(WebCore::calculateDevicePixelOffsetFromRenderer):
(WebCore::RenderLayerBacking::updateGraphicsLayerGeometry):
(WebCore::RenderLayerBacking::paintIntoLayer):
* rendering/RenderLayerBacking.h:

LayoutTests:

* TestExpectations:
* fast/sub-pixel/compositing-layers-on-subpixel-position-expected.html: Added.
* fast/sub-pixel/compositing-layers-on-subpixel-position.html: Added.
* fast/sub-pixel/simple-clipping-expected.html: Added.
* fast/sub-pixel/simple-clipping.html: Added.
* platform/mac/compositing/layer-creation/overlap-animation-container-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164449 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/sub-pixel/compositing-layers-on-subpixel-position-expected.html [new file with mode: 0644]
LayoutTests/fast/sub-pixel/compositing-layers-on-subpixel-position.html [new file with mode: 0644]
LayoutTests/fast/sub-pixel/simple-clipping-expected.html [new file with mode: 0644]
LayoutTests/fast/sub-pixel/simple-clipping.html [new file with mode: 0644]
LayoutTests/platform/mac/compositing/layer-creation/overlap-animation-container-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/platform/LayoutUnit.h
Source/WebCore/platform/graphics/LayoutPoint.h
Source/WebCore/platform/graphics/LayoutRect.cpp
Source/WebCore/platform/graphics/LayoutRect.h
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderLayerBacking.cpp
Source/WebCore/rendering/RenderLayerBacking.h

index 02f937a..78d1e85 100644 (file)
@@ -1,3 +1,21 @@
+2014-02-20  Zalan Bujtas  <zalan@apple.com>
+
+        Subpixel rendering: Enable compositing RenderLayer painting on device pixel position.
+        https://bugs.webkit.org/show_bug.cgi?id=128509
+
+        Reviewed by Simon Fraser.
+
+        GraphicsLayer is now positioned on device pixel boundary. This enables us to put
+        compositing layers on a subpixel position and animate them with device pixel
+        precision.
+
+        * TestExpectations:
+        * fast/sub-pixel/compositing-layers-on-subpixel-position-expected.html: Added.
+        * fast/sub-pixel/compositing-layers-on-subpixel-position.html: Added.
+        * fast/sub-pixel/simple-clipping-expected.html: Added.
+        * fast/sub-pixel/simple-clipping.html: Added.
+        * platform/mac/compositing/layer-creation/overlap-animation-container-expected.txt:
+
 2014-02-20  Mark Hahnenberg  <mhahnenberg@apple.com>
 
         Unskip fast/workers/use-machine-stack.html
index e3b6e2b..4238e60 100644 (file)
@@ -102,3 +102,7 @@ webkit.org/b/127697 fast/writing-mode/ruby-text-logical-left.html [ Skip ]
 webkit.org/b/83618 fast/dom/inline-event-attributes-release.html [ Failure ]
 
 webkit.org/b/129057 media/controls-styling-strict.html [ Pass Failure ]
+
+#subpixel failure on non-retina displays.
+webkit.org/b/129050 fast/sub-pixel/compositing-layers-on-subpixel-position.html [ Failure ]
+webkit.org/b/129113 fast/multicol/newmulticol/clipping.html [ Failure ]
diff --git a/LayoutTests/fast/sub-pixel/compositing-layers-on-subpixel-position-expected.html b/LayoutTests/fast/sub-pixel/compositing-layers-on-subpixel-position-expected.html
new file mode 100644 (file)
index 0000000..729bc48
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we properly position render layers when composition is introduced.</title>
+<style>
+  div {
+    background-color: black;
+    position: absolute;
+  }
+  .parent {
+    background-color: red;
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var childPos = -2;
+  function createGrid(topPos, leftPos) {
+    var container = document.getElementById("container");
+    localTopPos = topPos;
+    localLeftPos = leftPos;
+    for (var i = 0; i < 10; ++i, localTopPos = localTopPos + 7) {
+      localLeftPos = leftPos;
+      for (var j = 0; j < 10; ++j, localLeftPos = localLeftPos + 7, childPos = childPos < 2 ? childPos + 0.1 : -2) {
+        var outer = document.createElement("div");
+        outer.className = "parent";
+        outer.style.top = localTopPos + "px";
+        outer.style.left = localLeftPos + "px";
+        outer.style.width = "4px";
+        outer.style.height = "4px";
+
+        var inner = document.createElement("div");
+        inner.style.top = childPos + "px";
+        inner.style.left = childPos + "px";
+        inner.style.width = "2px";
+        inner.style.height = "2px";
+
+        outer.appendChild(inner);
+        container.appendChild(outer);
+      }
+    }
+  }
+
+  for (var i = 0; i < 10; ++i)
+    createGrid(i * 0.1, i * 70.1);
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/sub-pixel/compositing-layers-on-subpixel-position.html b/LayoutTests/fast/sub-pixel/compositing-layers-on-subpixel-position.html
new file mode 100644 (file)
index 0000000..10ea3ee
--- /dev/null
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests that we properly position render layers when composition is introduced.</title>
+<style>
+  div {
+    background-color: black;
+    position: absolute;
+  }
+  .parent {
+    background-color: red;
+    -webkit-transform: translateZ(0);
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+<script>
+  var childPos = -2;
+  function createGrid(topPos, leftPos) {
+    var container = document.getElementById("container");
+    localTopPos = topPos;
+    localLeftPos = leftPos;
+    for (var i = 0; i < 10; ++i, localTopPos = localTopPos + 7) {
+      localLeftPos = leftPos;
+      for (var j = 0; j < 10; ++j, localLeftPos = localLeftPos + 7, childPos = childPos < 2 ? childPos + 0.1 : -2) {
+        var outer = document.createElement("div");
+        outer.className = "parent";
+        outer.style.top = localTopPos + "px";
+        outer.style.left = localLeftPos + "px";
+        outer.style.width = "4px";
+        outer.style.height = "4px";
+
+        var inner = document.createElement("div");
+        inner.style.top = childPos + "px";
+        inner.style.left = childPos + "px";
+        inner.style.width = "2px";
+        inner.style.height = "2px";
+
+        outer.appendChild(inner);
+        container.appendChild(outer);
+      }
+    }
+  }
+
+  for (var i = 0; i < 10; ++i)
+    createGrid(i * 0.1, i * 70.1);
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/fast/sub-pixel/simple-clipping-expected.html b/LayoutTests/fast/sub-pixel/simple-clipping-expected.html
new file mode 100644 (file)
index 0000000..187fae1
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Simple clipping. This tests that we properly clip device pixel positioned elements.</title>
+<style>
+  div {
+    width: 20px;
+    height: 20px;
+    border: solid 1px red;
+    position: absolute;
+    top: 0px;
+  }
+</style>
+</head>
+<body>
+<p id="container"></p>
+
+<script>
+  var container = document.getElementById("container");
+  for (i = 0; i < 100; i = i + 21) {
+    var e1 = document.createElement("div");
+    var e2 = document.createElement("div");
+    var e3 = document.createElement("div");
+
+    e1.style.left = i + 101 + "px";
+
+    e2.style.top = "22px";
+    e2.style.left = i + 101.5 +"px";
+
+    e3.style.top = "44px";
+    e3.style.left = i + 102 + "px";
+
+    container.appendChild(e1);
+    container.appendChild(e2);
+    container.appendChild(e3);
+  }
+</script>
+
+</body>
+</html>
+
diff --git a/LayoutTests/fast/sub-pixel/simple-clipping.html b/LayoutTests/fast/sub-pixel/simple-clipping.html
new file mode 100644 (file)
index 0000000..8f2d0f3
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Simple clipping. This tests that we properly clip device pixel positioned elements.</title>
+<style>
+  div {
+    width: 20px;
+    height: 20px;
+    border: solid 1px red;
+    position: absolute;
+    top: 0px;
+    -webkit-transform: translateZ(0);
+  }
+</style>
+<script>
+  if (window.testRunner)
+    window.testRunner.waitUntilDone();
+
+  function moveBoxes() {
+    var boxes = document.getElementsByTagName("div");
+
+    for (var i = 0; i < boxes.length; i++)
+      boxes[i].style.left = parseFloat(boxes[i].style.left) + 100.5 + 'px';
+
+    if (window.testRunner)
+      window.testRunner.notifyDone();
+  }
+</script>
+</head>
+<body onload="setTimeout(moveBoxes, 0);">
+<p id="container"></p>
+<script>
+  var container = document.getElementById("container");
+  for (i = 0; i < 100; i = i + 21) {
+    var e1 = document.createElement("div");
+    var e2 = document.createElement("div");
+    var e3 = document.createElement("div");
+
+    e1.style.left = i + 0.5 + "px";
+
+    e2.style.top = "22px";
+    e2.style.left = i + 1 +"px";
+
+    e3.style.top = "44px";
+    e3.style.left = i + 1.5 + "px";
+
+    container.appendChild(e1);
+    container.appendChild(e2);
+    container.appendChild(e3);
+  }
+</script>
+
+</body>
+</html>
index c6806e4..93baac9 100644 (file)
@@ -12,12 +12,12 @@ Before:
           (transform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [0.00 0.00 1.00 0.00] [0.00 -110.00 0.00 1.00])
         )
         (GraphicsLayer
-          (position 47.00 229.00)
-          (bounds 144.00 454.00)
+          (position 46.00 229.00)
+          (bounds 146.00 454.00)
           (drawsContent 1)
           (children 1
             (GraphicsLayer
-              (position 21.00 11.00)
+              (position 21.13 11.00)
               (bounds 102.00 102.00)
               (transform [1.00 0.00 0.00 0.00] [0.00 1.00 0.00 0.00] [0.00 0.00 1.00 0.00] [0.00 0.00 -1.00 1.00])
             )
index 5a80259..46afaf6 100644 (file)
@@ -1,3 +1,35 @@
+2014-02-20  Zalan Bujtas  <zalan@apple.com>
+
+        Subpixel rendering: Enable compositing RenderLayer painting on device pixel position.
+        https://bugs.webkit.org/show_bug.cgi?id=128509
+
+        Reviewed by Simon Fraser.
+
+        GraphicsLayer is now positioned on device pixel boundary. This enables us to put
+        compositing layers on a subpixel position and animate them with device pixel
+        precision.
+
+        Tests: fast/sub-pixel/compositing-layers-on-subpixel-position.html
+               fast/sub-pixel/simple-clipping.html
+
+        * platform/LayoutUnit.h:
+        (WebCore::ceilToDevicePixel):
+        * platform/graphics/LayoutPoint.h:
+        (WebCore::flooredForPainting):
+        (WebCore::ceiledForPainting):
+        * platform/graphics/LayoutRect.cpp:
+        (WebCore::enclosingRectForPainting):
+        * platform/graphics/LayoutRect.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::clipToRect):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::clipBox):
+        (WebCore::pixelFractionForLayerPainting):
+        (WebCore::calculateDevicePixelOffsetFromRenderer):
+        (WebCore::RenderLayerBacking::updateGraphicsLayerGeometry):
+        (WebCore::RenderLayerBacking::paintIntoLayer):
+        * rendering/RenderLayerBacking.h:
+
 2014-02-20  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         Rename border/padding/margin width/height to horizontal/vertical extent on RenderBoxModelObject
index 80a223a..5364fc9 100644 (file)
@@ -945,6 +945,11 @@ inline float floorToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
     return floorf((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
 }
 
+inline float ceilToDevicePixel(LayoutUnit value, float pixelSnappingFactor)
+{
+    return ceilf((value.rawValue() * pixelSnappingFactor) / kEffectiveFixedPointDenominator) / pixelSnappingFactor;
+}
+
 inline float snapSizeToDevicePixel(LayoutUnit size, LayoutUnit location, float pixelSnappingFactor)
 {
     LayoutUnit fraction = location.fraction();
index 28a2dba..5166699 100644 (file)
@@ -185,6 +185,26 @@ inline IntSize pixelSnappedIntSize(const LayoutSize& s, const LayoutPoint& p)
     return IntSize(snapSizeToPixel(s.width(), p.x()), snapSizeToPixel(s.height(), p.y()));
 }
 
+inline FloatPoint flooredForPainting(const LayoutPoint& point, float pixelSnappingFactor)
+{
+#if ENABLE(SUBPIXEL_LAYOUT)
+    return FloatPoint(floorToDevicePixel(point.x(), pixelSnappingFactor), floorToDevicePixel(point.y(), pixelSnappingFactor));
+#else
+    UNUSED_PARAM(pixelSnappingFactor);
+    return FloatPoint(point);
+#endif
+}
+
+inline FloatPoint ceiledForPainting(const LayoutPoint& point, float pixelSnappingFactor)
+{
+#if ENABLE(SUBPIXEL_LAYOUT)
+    return FloatPoint(ceilToDevicePixel(point.x(), pixelSnappingFactor), ceilToDevicePixel(point.y(), pixelSnappingFactor));
+#else
+    UNUSED_PARAM(pixelSnappingFactor);
+    return FloatPoint(point);
+#endif
+}
+
 inline LayoutPoint roundedLayoutPoint(const FloatPoint& p)
 {
 #if ENABLE(SUBPIXEL_LAYOUT)
index dce0e12..14ab921 100644 (file)
@@ -147,4 +147,12 @@ LayoutRect enclosingLayoutRect(const FloatRect& rect)
 #endif
 }
 
+FloatRect enclosingRectForPainting(const LayoutRect& rect, float pixelSnappingFactor)
+{
+    FloatPoint location = flooredForPainting(rect.minXMinYCorner(), pixelSnappingFactor);
+    FloatPoint maxPoint = ceiledForPainting(rect.maxXMaxYCorner(), pixelSnappingFactor);
+
+    return FloatRect(location, maxPoint - location);
+}
+
 } // namespace WebCore
index fd4e414..1acabaa 100644 (file)
@@ -214,7 +214,7 @@ inline IntRect pixelSnappedIntRect(const LayoutRect& rect)
 
 IntRect enclosingIntRect(const LayoutRect&);
 LayoutRect enclosingLayoutRect(const FloatRect&);
-
+FloatRect enclosingRectForPainting(const LayoutRect&, float pixelSnappingFactor);
 
 inline IntRect pixelSnappedIntRect(LayoutUnit left, LayoutUnit top, LayoutUnit width, LayoutUnit height)
 {
index b90155b..2a867e2 100644 (file)
@@ -3572,7 +3572,7 @@ void RenderLayer::clipToRect(RenderLayer* rootLayer, GraphicsContext* context, c
 {
     if (clipRect.rect() != paintDirtyRect || clipRect.hasRadius()) {
         context->save();
-        context->clip(pixelSnappedIntRect(clipRect.rect()));
+        context->clip(clipRect.rect());
     }
 
     if (!clipRect.hasRadius())
index 079a4fd..0f4b2ba 100644 (file)
@@ -642,7 +642,23 @@ static LayoutRect clipBox(RenderBox& renderer)
     if (renderer.hasClip())
         result.intersect(renderer.clipRect(LayoutPoint(), 0)); // FIXME: Incorrect for CSS regions.
 
-    return pixelSnappedIntRect(result);
+    return result;
+}
+
+static FloatSize pixelFractionForLayerPainting(const LayoutPoint& point, float pixelSnappingFactor)
+{
+    LayoutUnit x = point.x();
+    LayoutUnit y = point.y();
+    x = x >= 0 ? floorToDevicePixel(x, pixelSnappingFactor) : ceilToDevicePixel(x, pixelSnappingFactor);
+    y = y >= 0 ? floorToDevicePixel(y, pixelSnappingFactor) : ceilToDevicePixel(y, pixelSnappingFactor);
+    return point - LayoutPoint(x, y);
+}
+
+static void calculateDevicePixelOffsetFromRenderer(const LayoutSize& rendererOffsetFromGraphicsLayer, FloatSize& devicePixelOffsetFromRenderer,
+    LayoutSize& devicePixelFractionFromRenderer, float deviceScaleFactor)
+{
+    devicePixelFractionFromRenderer = LayoutSize(pixelFractionForLayerPainting(toLayoutPoint(rendererOffsetFromGraphicsLayer), deviceScaleFactor));
+    devicePixelOffsetFromRenderer = rendererOffsetFromGraphicsLayer - devicePixelFractionFromRenderer;
 }
 
 void RenderLayerBacking::updateGraphicsLayerGeometry()
@@ -689,20 +705,49 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
     LayoutRect ancestorCompositingBounds;
     if (compAncestor) {
         ASSERT(compAncestor->backing());
-        ancestorCompositingBounds = pixelSnappedIntRect(compAncestor->backing()->compositedBounds());
-    }
+        ancestorCompositingBounds = compAncestor->backing()->compositedBounds();
+    }
+
+    /*
+    * GraphicsLayer: device pixel positioned. Floored, enclosing rect.
+    * RenderLayer: subpixel positioned.
+    * Offset from renderer (GraphicsLayer <-> RenderLayer::renderer()): subpixel based offset.
+    *
+    *     relativeCompositingBounds
+    *      _______________________________________
+    *     |\          GraphicsLayer               |
+    *     | \                                     |
+    *     |  \ offset from renderer: (device pixel + subpixel)
+    *     |   \                                   |
+    *     |    \______________________________    |
+    *     |    | localCompositingBounds       |   |
+    *     |    |                              |   |
+    *     |    |   RenderLayer::renderer()    |   |
+    *     |    |                              |   |
+    *
+    * localCompositingBounds: this RenderLayer relative to its renderer().
+    * relativeCompositingBounds: this RenderLayer relative to its parent compositing layer.
+    * enclosingRelativeCompositingBounds: this RenderLayer relative to its parent but floored to device pixel position.
+    * rendererOffsetFromGraphicsLayer: RenderLayer::renderer()'s offset from its enclosing GraphicsLayer.
+    * devicePixelOffsetFromRenderer: rendererOffsetFromGraphicsLayer's device pixel part. (6.9px -> 6.5px in case of 2x display)
+    * devicePixelFractionFromRenderer: rendererOffsetFromGraphicsLayer's fractional part (6.9px -> 0.4px in case of 2x display)
+    */
+    float deviceScaleFactor = this->deviceScaleFactor();
+    LayoutRect localCompositingBounds = compositedBounds();
+    LayoutRect relativeCompositingBounds(localCompositingBounds);
 
-    LayoutRect localRawCompositingBounds = compositedBounds();
-    LayoutPoint rawDelta;
-    m_owningLayer.convertToLayerCoords(compAncestor, rawDelta, RenderLayer::AdjustForColumns);
-    IntPoint delta = flooredIntPoint(rawDelta);
-    m_subpixelAccumulation = toLayoutSize(rawDelta.fraction());
-    // Move the bounds by the subpixel accumulation so that it pixel-snaps relative to absolute pixels instead of local coordinates.
-    localRawCompositingBounds.move(m_subpixelAccumulation);
+    LayoutPoint offsetFromParent;
+    m_owningLayer.convertToLayerCoords(compAncestor, offsetFromParent, RenderLayer::AdjustForColumns);
+    relativeCompositingBounds.moveBy(offsetFromParent);
 
-    LayoutRect localCompositingBounds = pixelSnappedIntRect(localRawCompositingBounds);
-    LayoutRect relativeCompositingBounds(localCompositingBounds);
-    relativeCompositingBounds.moveBy(delta);
+    LayoutRect enclosingRelativeCompositingBounds = LayoutRect(enclosingRectForPainting(relativeCompositingBounds, deviceScaleFactor));
+    LayoutSize subpixelOffsetAdjustment = enclosingRelativeCompositingBounds.location() - relativeCompositingBounds.location();
+    LayoutSize rendererOffsetFromGraphicsLayer =  toLayoutSize(localCompositingBounds.location()) + subpixelOffsetAdjustment;
+
+    FloatSize devicePixelOffsetFromRenderer;
+    LayoutSize devicePixelFractionFromRenderer;
+    calculateDevicePixelOffsetFromRenderer(rendererOffsetFromGraphicsLayer, devicePixelOffsetFromRenderer, devicePixelFractionFromRenderer, deviceScaleFactor);
+    m_devicePixelFractionFromRenderer = LayoutSize(fabs(devicePixelFractionFromRenderer.width().toFloat()), fabs(devicePixelFractionFromRenderer.height().toFloat()));
 
     adjustAncestorCompositingBoundsForFlowThread(ancestorCompositingBounds, compAncestor);
 
@@ -741,40 +786,39 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
         // layer. Note that we call it with temporaryClipRects = true because normally when computing clip rects
         // for a compositing layer, rootLayer is the layer itself.
         RenderLayer::ClipRectsContext clipRectsContext(compAncestor, 0, TemporaryClipRects, IgnoreOverlayScrollbarSize, IgnoreOverflowClip);
-        LayoutRect parentClipRect = pixelSnappedIntRect(m_owningLayer.backgroundClipRect(clipRectsContext).rect()); // FIXME: Incorrect for CSS regions.
+        LayoutRect parentClipRect = m_owningLayer.backgroundClipRect(clipRectsContext).rect(); // FIXME: Incorrect for CSS regions.
         ASSERT(parentClipRect != LayoutRect::infiniteRect());
         m_ancestorClippingLayer->setPosition(FloatPoint(parentClipRect.location() - graphicsLayerParentLocation));
         m_ancestorClippingLayer->setSize(parentClipRect.size());
 
         // backgroundRect is relative to compAncestor, so subtract deltaX/deltaY to get back to local coords.
-        m_ancestorClippingLayer->setOffsetFromRenderer(parentClipRect.location() - delta);
+        m_ancestorClippingLayer->setOffsetFromRenderer(parentClipRect.location() - offsetFromParent);
 
         // The primary layer is then parented in, and positioned relative to this clipping layer.
         graphicsLayerParentLocation = parentClipRect.location();
     }
 
-    LayoutSize contentsSize = relativeCompositingBounds.size();
+    LayoutSize contentsSize = enclosingRelativeCompositingBounds.size();
     
     if (m_contentsContainmentLayer) {
         m_contentsContainmentLayer->setPreserves3D(preserves3D);
-        m_contentsContainmentLayer->setPosition(FloatPoint(relativeCompositingBounds.location() - graphicsLayerParentLocation));
+        m_contentsContainmentLayer->setPosition(FloatPoint(enclosingRelativeCompositingBounds.location() - graphicsLayerParentLocation));
         // Use the same size as m_graphicsLayer so transforms behave correctly.
         m_contentsContainmentLayer->setSize(contentsSize);
-        graphicsLayerParentLocation = relativeCompositingBounds.location();
+        graphicsLayerParentLocation = enclosingRelativeCompositingBounds.location();
     }
 
-    m_graphicsLayer->setPosition(FloatPoint(relativeCompositingBounds.location() - graphicsLayerParentLocation));
+    m_graphicsLayer->setPosition(FloatPoint(enclosingRelativeCompositingBounds.location() - graphicsLayerParentLocation));
     m_graphicsLayer->setSize(contentsSize);
-    FloatSize offsetFromRenderer = toLayoutSize(localCompositingBounds.location());
-    if (offsetFromRenderer != m_graphicsLayer->offsetFromRenderer()) {
-        m_graphicsLayer->setOffsetFromRenderer(offsetFromRenderer);
+    if (devicePixelOffsetFromRenderer != m_graphicsLayer->offsetFromRenderer()) {
+        m_graphicsLayer->setOffsetFromRenderer(devicePixelOffsetFromRenderer);
         positionOverflowControlsLayers();
     }
 
     if (!m_isMainFrameRenderViewLayer) {
         // For non-root layers, background is always painted by the primary graphics layer.
         ASSERT(!m_backgroundLayer);
-        bool hadSubpixelRounding = relativeCompositingBounds.size() != localRawCompositingBounds.size();
+        bool hadSubpixelRounding = !m_devicePixelFractionFromRenderer.isEmpty();
         m_graphicsLayer->setContentsOpaque(!hadSubpixelRounding && m_owningLayer.backgroundIsKnownToBeOpaqueInRect(localCompositingBounds));
     }
 
@@ -797,14 +841,14 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
         const LayoutRect borderBox = toRenderBox(renderer()).pixelSnappedBorderBoxRect();
 
         // Get layout bounds in the coords of compAncestor to match relativeCompositingBounds.
-        LayoutRect layerBounds(delta, borderBox.size());
+        LayoutRect layerBounds(offsetFromParent, borderBox.size());
 
         // Update properties that depend on layer dimensions
         FloatPoint3D transformOrigin = computeTransformOrigin(borderBox);
         // Compute the anchor point, which is in the center of the renderer box unless transform-origin is set.
-        FloatPoint3D anchor(relativeCompositingBounds.width()  != 0.0f ? ((layerBounds.x() - relativeCompositingBounds.x()) + transformOrigin.x()) / relativeCompositingBounds.width()  : 0.5f,
-                            relativeCompositingBounds.height() != 0.0f ? ((layerBounds.y() - relativeCompositingBounds.y()) + transformOrigin.y()) / relativeCompositingBounds.height() : 0.5f,
-                            transformOrigin.z());
+        FloatPoint3D anchor(enclosingRelativeCompositingBounds.width() != 0.0f ? ((layerBounds.x() - enclosingRelativeCompositingBounds.x()) + transformOrigin.x())
+            / enclosingRelativeCompositingBounds.width() : 0.5f, enclosingRelativeCompositingBounds.height() != 0.0f ? ((layerBounds.y() - enclosingRelativeCompositingBounds.y())
+            + transformOrigin.y()) / enclosingRelativeCompositingBounds.height() : 0.5f, transformOrigin.z());
         if (m_contentsContainmentLayer)
             m_contentsContainmentLayer->setAnchorPoint(anchor);
         else
@@ -876,15 +920,15 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
     if (m_scrollingLayer) {
         ASSERT(m_scrollingContentsLayer);
         RenderBox& renderBox = toRenderBox(renderer());
-        IntRect paddingBox(renderBox.borderLeft(), renderBox.borderTop(), renderBox.width() - renderBox.borderLeft() - renderBox.borderRight(), renderBox.height() - renderBox.borderTop() - renderBox.borderBottom());
-        IntSize scrollOffset = m_owningLayer.scrollOffset();
+        LayoutRect paddingBox(renderBox.borderLeft(), renderBox.borderTop(), renderBox.width() - renderBox.borderLeft() - renderBox.borderRight(), renderBox.height() - renderBox.borderTop() - renderBox.borderBottom());
+        LayoutSize scrollOffset = m_owningLayer.scrollOffset();
 
         m_scrollingLayer->setPosition(FloatPoint(paddingBox.location() - localCompositingBounds.location()));
 
         m_scrollingLayer->setSize(paddingBox.size());
 #if PLATFORM(IOS)
         FloatSize oldScrollingLayerOffset = m_scrollingLayer->offsetFromRenderer();
-        m_scrollingLayer->setOffsetFromRenderer(IntPoint() - paddingBox.location());
+        m_scrollingLayer->setOffsetFromRenderer(FloatPoint() - paddingBox.location());
         bool paddingBoxOffsetChanged = oldScrollingLayerOffset != m_scrollingLayer->offsetFromRenderer();
 
         if (m_owningLayer.isInUserScroll()) {
@@ -914,7 +958,7 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
         m_scrollingContentsLayer->setPosition(FloatPoint(-scrollOffset.width(), -scrollOffset.height()));
 
         FloatSize oldScrollingLayerOffset = m_scrollingLayer->offsetFromRenderer();
-        m_scrollingLayer->setOffsetFromRenderer(-toIntSize(paddingBox.location()));
+        m_scrollingLayer->setOffsetFromRenderer(-toFloatSize(paddingBox.location()));
 
         bool paddingBoxOffsetChanged = oldScrollingLayerOffset != m_scrollingLayer->offsetFromRenderer();
 
@@ -922,7 +966,7 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
         if (scrollSize != m_scrollingContentsLayer->size() || paddingBoxOffsetChanged)
             m_scrollingContentsLayer->setNeedsDisplay();
 
-        IntSize scrollingContentsOffset = toIntSize(paddingBox.location() - scrollOffset);
+        LayoutSize scrollingContentsOffset = toLayoutSize(paddingBox.location() - scrollOffset);
         if (scrollingContentsOffset != m_scrollingContentsLayer->offsetFromRenderer() || scrollSize != m_scrollingContentsLayer->size())
             compositor().scrollingLayerDidChange(m_owningLayer);
 
@@ -938,7 +982,7 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
     }
 
     // If this layer was created just for clipping or to apply perspective, it doesn't need its own backing store.
-    setRequiresOwnBackingStore(compositor().requiresOwnBackingStore(m_owningLayer, compAncestor, relativeCompositingBounds, ancestorCompositingBounds));
+    setRequiresOwnBackingStore(compositor().requiresOwnBackingStore(m_owningLayer, compAncestor, enclosingRelativeCompositingBounds, ancestorCompositingBounds));
 
     bool didUpdateContentsRect = false;
     updateDirectlyCompositedContents(isSimpleContainer, didUpdateContentsRect);
@@ -2161,7 +2205,7 @@ void RenderLayerBacking::paintIntoLayer(const GraphicsLayer* graphicsLayer, Grap
         paintFlags |= RenderLayer::PaintLayerPaintingSkipRootBackground;
     
     // FIXME: GraphicsLayers need a way to split for RenderRegions.
-    RenderLayer::LayerPaintingInfo paintingInfo(&m_owningLayer, paintDirtyRect, paintBehavior, m_subpixelAccumulation);
+    RenderLayer::LayerPaintingInfo paintingInfo(&m_owningLayer, paintDirtyRect, paintBehavior, m_devicePixelFractionFromRenderer);
     m_owningLayer.paintLayerContents(context, paintingInfo, paintFlags);
 
     if (m_owningLayer.containsDirtyOverlayScrollbars())
index 41d33c1..aa035d7 100644 (file)
@@ -311,7 +311,7 @@ private:
     uint64_t m_scrollLayerID;
 
     LayoutRect m_compositedBounds;
-    LayoutSize m_subpixelAccumulation; // The accumulated subpixel offset of the compositedBounds compared to absolute coordinates.
+    LayoutSize m_devicePixelFractionFromRenderer;
 
     bool m_artificiallyInflatedBounds; // bounds had to be made non-zero to make transform-origin work
     bool m_isMainFrameRenderViewLayer;