Fix GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush() to do predictive visib...
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Apr 2013 00:04:49 +0000 (00:04 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 18 Apr 2013 00:04:49 +0000 (00:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=114775

Reviewed by Tim Horton.

GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush() is intended to answer the question
"if your visible rect is changed to X, would any tiles be created or destroyed?".

However, for compositing layer tiled layers, we do some predictive visible rect expansion based on how
the visible rect is changing when we actually commit visible rect changes. recursiveVisibleRectChangeRequiresFlush()
was not doing that, causing it to give confusing answers, so fix it to do so.

Both now call adjustTiledLayerVisibleRect(), and it's cleaner to make this a static function.

A somewhat unrelated change is to take the layer bounds origin into account
in GraphicsLayerCA::computeVisibleRect(). Desktop WebKit never sets this, but it's used
on other platforms for composited scrolling, so needs to be taken into account
when computing visible rects.

* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush):
(WebCore::GraphicsLayerCA::computeVisibleRect):
(WebCore::GraphicsLayerCA::adjustTiledLayerVisibleRect):
(WebCore::GraphicsLayerCA::updateVisibleRect):
* platform/graphics/ca/GraphicsLayerCA.h:
(GraphicsLayerCA):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h

index 1655d18..8d1bb26 100644 (file)
@@ -1,3 +1,32 @@
+2013-04-17  Simon Fraser  <simon.fraser@apple.com>
+
+        Fix GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush() to do predictive visible rect expansion
+        https://bugs.webkit.org/show_bug.cgi?id=114775
+
+        Reviewed by Tim Horton.
+
+        GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush() is intended to answer the question
+        "if your visible rect is changed to X, would any tiles be created or destroyed?".
+        
+        However, for compositing layer tiled layers, we do some predictive visible rect expansion based on how
+        the visible rect is changing when we actually commit visible rect changes. recursiveVisibleRectChangeRequiresFlush()
+        was not doing that, causing it to give confusing answers, so fix it to do so.
+        
+        Both now call adjustTiledLayerVisibleRect(), and it's cleaner to make this a static function.
+        
+        A somewhat unrelated change is to take the layer bounds origin into account
+        in GraphicsLayerCA::computeVisibleRect(). Desktop WebKit never sets this, but it's used
+        on other platforms for composited scrolling, so needs to be taken into account
+        when computing visible rects.
+
+        * platform/graphics/ca/GraphicsLayerCA.cpp:
+        (WebCore::GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush):
+        (WebCore::GraphicsLayerCA::computeVisibleRect):
+        (WebCore::GraphicsLayerCA::adjustTiledLayerVisibleRect):
+        (WebCore::GraphicsLayerCA::updateVisibleRect):
+        * platform/graphics/ca/GraphicsLayerCA.h:
+        (GraphicsLayerCA):
+
 2013-04-17  Oliver Hunt  <oliver@apple.com>
 
         Automate generation of toJS function for classes that need to report extra memory usage
index b1e8463..0cd757c 100644 (file)
@@ -913,10 +913,13 @@ bool GraphicsLayerCA::recursiveVisibleRectChangeRequiresFlush(const TransformSta
     
     // This may be called at times when layout has not been updated, so we want to avoid calling out to the client
     // for animating transforms.
-    FloatRect visibleRect = computeVisibleRect(localState, 0);
-    if (visibleRect != m_visibleRect) {
+    FloatRect newVisibleRect = computeVisibleRect(localState, 0);
+    if (m_layer->layerType() == PlatformCALayer::LayerTypeTiledBackingLayer)
+        newVisibleRect = adjustTiledLayerVisibleRect(tiledBacking(), m_visibleRect, newVisibleRect, m_sizeAtLastVisibleRectUpdate, m_size);
+
+    if (newVisibleRect != m_visibleRect) {
         if (TiledBacking* tiledBacking = this->tiledBacking()) {
-            if (tiledBacking->tilesWouldChangeForVisibleRect(visibleRect))
+            if (tiledBacking->tilesWouldChangeForVisibleRect(newVisibleRect))
                 return true;
         }
     }
@@ -994,7 +997,10 @@ FloatRect GraphicsLayerCA::computeVisibleRect(TransformState& state, ComputeVisi
     
     bool mapWasClamped;
     FloatRect clipRectForChildren = state.mappedQuad(&mapWasClamped).boundingBox();
-    FloatRect clipRectForSelf(0, 0, m_size.width(), m_size.height());
+    FloatPoint boundsOrigin = m_boundsOrigin;
+    clipRectForChildren.move(boundsOrigin.x(), boundsOrigin.y());
+    
+    FloatRect clipRectForSelf(boundsOrigin, m_size);
     if (!applyWasClamped && !mapWasClamped)
         clipRectForSelf.intersect(clipRectForChildren);
     
@@ -1592,24 +1598,24 @@ void GraphicsLayerCA::updateDebugBorder()
         m_layer->setBorderWidth(0);
 }
 
-FloatRect GraphicsLayerCA::adjustTiledLayerVisibleRect(TiledBacking* tiledBacking, const FloatRect& oldVisibleRect, const FloatSize& oldSize) const
+FloatRect GraphicsLayerCA::adjustTiledLayerVisibleRect(TiledBacking* tiledBacking, const FloatRect& oldVisibleRect, const FloatRect& newVisibleRect, const FloatSize& oldSize, const FloatSize& newSize)
 {
     // If the old visible rect is empty, we have no information about how the visible area is changing
     // (maybe the layer was just created), so don't attempt to expand. Also don't attempt to expand
     // if the size changed.
-    if (oldVisibleRect.isEmpty() || m_size != oldSize)
-        return m_visibleRect;
+    if (oldVisibleRect.isEmpty() || newSize != oldSize)
+        return newVisibleRect;
 
     const float paddingMultiplier = 2;
 
-    float leftEdgeDelta = paddingMultiplier * (m_visibleRect.x() - oldVisibleRect.x());
-    float rightEdgeDelta = paddingMultiplier * (m_visibleRect.maxX() - oldVisibleRect.maxX());
+    float leftEdgeDelta = paddingMultiplier * (newVisibleRect.x() - oldVisibleRect.x());
+    float rightEdgeDelta = paddingMultiplier * (newVisibleRect.maxX() - oldVisibleRect.maxX());
 
-    float topEdgeDelta = paddingMultiplier * (m_visibleRect.y() - oldVisibleRect.y());
-    float bottomEdgeDelta = paddingMultiplier * (m_visibleRect.maxY() - oldVisibleRect.maxY());
+    float topEdgeDelta = paddingMultiplier * (newVisibleRect.y() - oldVisibleRect.y());
+    float bottomEdgeDelta = paddingMultiplier * (newVisibleRect.maxY() - oldVisibleRect.maxY());
     
     FloatRect existingTileBackingRect = tiledBacking->visibleRect();
-    FloatRect expandedRect = m_visibleRect;
+    FloatRect expandedRect = newVisibleRect;
 
     // More exposed on left side.
     if (leftEdgeDelta < 0) {
@@ -1659,7 +1665,7 @@ void GraphicsLayerCA::updateVisibleRect(const FloatRect& oldVisibleRect)
 
     FloatRect tileArea = m_visibleRect;
     if (m_layer->layerType() == PlatformCALayer::LayerTypeTiledBackingLayer)
-        tileArea = adjustTiledLayerVisibleRect(tiledBacking(), oldVisibleRect, m_sizeAtLastVisibleRectUpdate);
+        tileArea = adjustTiledLayerVisibleRect(tiledBacking(), oldVisibleRect, tileArea, m_sizeAtLastVisibleRectUpdate, m_size);
 
     tiledBacking()->setVisibleRect(tileArea);
 
index 7b35cac..08732a7 100644 (file)
@@ -250,7 +250,7 @@ private:
     FloatRect computeVisibleRect(TransformState&, ComputeVisibleRectFlags = RespectAnimatingTransforms) const;
     const FloatRect& visibleRect() const { return m_visibleRect; }
     
-    FloatRect adjustTiledLayerVisibleRect(TiledBacking*, const FloatRect& oldVisibleRect, const FloatSize& oldSize) const;
+    static FloatRect adjustTiledLayerVisibleRect(TiledBacking*, const FloatRect& oldVisibleRect, const FloatRect& newVisibleRect, const FloatSize& oldSize, const FloatSize& newSize);
 
     bool recursiveVisibleRectChangeRequiresFlush(const TransformState&) const;