2009-02-10 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Feb 2009 01:12:57 +0000 (01:12 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Feb 2009 01:12:57 +0000 (01:12 +0000)
        Reviewed by Dave Hyatt

        Move enclosingCompositingLayer() from RenderObject to RenderLayer, since it
        relates to the RenderLayer z-order/overflow structure, rather than the render tree
        parent chain. Add a convenience method, ancestorCompositingLayer(), which finds
        the enclosing layer excluding self.

        Fix enclosingCompositingLayer() to correctly look at stacking context and overflow
        lists.

        Check for documentBeingDestroyed() in a few places to avoid work on document
        teardown.

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

WebCore/ChangeLog
WebCore/rendering/RenderLayer.cpp
WebCore/rendering/RenderLayer.h
WebCore/rendering/RenderLayerBacking.cpp
WebCore/rendering/RenderLayerCompositor.cpp
WebCore/rendering/RenderLayerCompositor.h
WebCore/rendering/RenderObject.cpp
WebCore/rendering/RenderObject.h

index 3373090..ec04c66 100644 (file)
@@ -1,3 +1,37 @@
+2009-02-10  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Dave Hyatt
+
+        Move enclosingCompositingLayer() from RenderObject to RenderLayer, since it
+        relates to the RenderLayer z-order/overflow structure, rather than the render tree
+        parent chain. Add a convenience method, ancestorCompositingLayer(), which finds
+        the enclosing layer excluding self.
+        
+        Fix enclosingCompositingLayer() to correctly look at stacking context and overflow
+        lists.
+        
+        Check for documentBeingDestroyed() in a few places to avoid work on document
+        teardown.
+        
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::enclosingCompositingLayer):
+        (WebCore::RenderLayer::setParent):
+        (WebCore::RenderLayer::dirtyZOrderLists):
+        (WebCore::RenderLayer::dirtyOverflowList):
+        * rendering/RenderLayer.h:
+        (WebCore::RenderLayer::ancestorCompositingLayer):
+        * rendering/RenderLayerBacking.cpp:
+        (WebCore::RenderLayerBacking::updateGraphicsLayerGeometry):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::updateLayerCompositingState):
+        (WebCore::RenderLayerCompositor::calculateCompositedBounds):
+        (WebCore::RenderLayerCompositor::layerWillBeRemoved):
+        (WebCore::RenderLayerCompositor::clippedByAncestor):
+        * rendering/RenderLayerCompositor.h:
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::containerForRepaint):
+        * rendering/RenderObject.h:
+
 2009-02-10  David Hyatt  <hyatt@apple.com>
 
         Rename xPos() and yPos() on RenderLayer to x() and y() to match RenderBox.  Rename setPos to setLocation.
index 99d46a9..693423c 100644 (file)
@@ -523,6 +523,27 @@ RenderLayer* RenderLayer::enclosingTransformedAncestor() const
     return curr;
 }
 
+#if USE(ACCELERATED_COMPOSITING)
+RenderLayer* RenderLayer::enclosingCompositingLayer(bool includeSelf) const
+{
+    if (includeSelf && isComposited())
+        return const_cast<RenderLayer*>(this);
+
+    // Compositing layers are parented according to stacking order and overflow list,
+    // so we have to check whether the parent is a stacking context, or whether 
+    // the child is overflow-only.
+    bool inOverflowList = isOverflowOnly();
+    for (RenderLayer* curr = parent(); curr; curr = curr->parent()) {
+        if (curr->isComposited() && (inOverflowList || curr->isStackingContext()))
+            return curr;
+        
+        inOverflowList = curr->isOverflowOnly();
+    }
+         
+    return 0;
+}
+#endif
+
 IntPoint RenderLayer::absoluteToContents(const IntPoint& absolutePoint) const
 {
     // We don't use convertToLayerCoords because it doesn't know about transforms
@@ -2438,14 +2459,14 @@ void RenderLayer::setParent(RenderLayer* parent)
         return;
 
 #if USE(ACCELERATED_COMPOSITING)
-    if (m_parent && compositor())
+    if (m_parent && !renderer()->documentBeingDestroyed())
         compositor()->layerWillBeRemoved(m_parent, this);
 #endif
     
     m_parent = parent;
     
 #if USE(ACCELERATED_COMPOSITING)
-    if (m_parent)
+    if (m_parent && !renderer()->documentBeingDestroyed())
         compositor()->layerWasAdded(m_parent, this);
 #endif
 }
@@ -2547,7 +2568,7 @@ void RenderLayer::dirtyZOrderLists()
     m_zOrderListsDirty = true;
 
 #if USE(ACCELERATED_COMPOSITING)
-    if (compositor())
+    if (!renderer()->documentBeingDestroyed())
         compositor()->setCompositingLayersNeedUpdate();
 #endif
 }
@@ -2566,7 +2587,7 @@ void RenderLayer::dirtyOverflowList()
     m_overflowListDirty = true;
 
 #if USE(ACCELERATED_COMPOSITING)
-    if (compositor())
+    if (!renderer()->documentBeingDestroyed())
         compositor()->setCompositingLayersNeedUpdate();
 #endif
 }
index 2bad08c..e502d44 100644 (file)
@@ -342,6 +342,13 @@ public:
     // the <html> layer and the root layer).
     RenderLayer* enclosingPositionedAncestor() const;
 
+#if USE(ACCELERATED_COMPOSITING)
+    // Enclosing compositing layer; if includeSelf is true, may return this.
+    RenderLayer* enclosingCompositingLayer(bool includeSelf = true) const;
+    // Ancestor compositing layer, excluding this.
+    RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(false); }
+#endif
+
     void convertToLayerCoords(const RenderLayer* ancestorLayer, int& x, int& y) const;
 
     bool hasAutoZIndex() const { return renderer()->style()->hasAutoZIndex(); }
index 203da15..8d8ff38 100644 (file)
@@ -175,7 +175,7 @@ void RenderLayerBacking::updateGraphicsLayerGeometry()
 
     m_compositingContentOffsetDirty = true;
     
-    RenderLayer* compAncestor = compositor()->ancestorCompositingLayer(m_owningLayer);
+    RenderLayer* compAncestor = m_owningLayer->ancestorCompositingLayer();
     
     // We compute everything relative to the enclosing compositing layer.
     IntRect ancestorCompositingBounds;
index 31cf719..ec10f06 100644 (file)
@@ -173,7 +173,7 @@ bool RenderLayerCompositor::updateLayerCompositingState(RenderLayer* layer, Styl
     
     if (layerChanged) {
         // Invalidate the parent in this region.
-        RenderLayer* compLayer = ancestorCompositingLayer(layer);
+        RenderLayer* compLayer = layer->ancestorCompositingLayer();
         if (compLayer) {
             // We can't reliably compute a dirty rect, because style may have changed already, 
             // so just dirty the whole parent layer
@@ -204,7 +204,7 @@ bool RenderLayerCompositor::updateLayerCompositingState(RenderLayer* layer, Styl
 IntRect RenderLayerCompositor::calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer, IntRect* layerBoundingBox)
 {
     IntRect boundingBoxRect, unionBounds;
-    boundingBoxRect = unionBounds = layer->boundingBox(layer);
+    boundingBoxRect = unionBounds = layer->localBoundingBox();
     
     ASSERT(layer->isStackingContext() || (!layer->m_posZOrderList || layer->m_posZOrderList->size() == 0));
 
@@ -274,7 +274,7 @@ void RenderLayerCompositor::layerWillBeRemoved(RenderLayer* parent, RenderLayer*
     if (parent->renderer()->documentBeingDestroyed())
         return;
 
-    RenderLayer* compLayer = parent->renderer()->enclosingCompositingLayer();
+    RenderLayer* compLayer = parent->enclosingCompositingLayer();
     if (compLayer) {
         IntRect ancestorRect = calculateCompositedBounds(child, compLayer);
         compLayer->setBackingNeedsRepaintInRect(ancestorRect);
@@ -399,14 +399,6 @@ void RenderLayerCompositor::setForcedCompositingLayer(RenderLayer* layer, bool f
     }
 }
 
-RenderLayer* RenderLayerCompositor::ancestorCompositingLayer(const RenderLayer* layer) const
-{
-    if (!layer->parent())
-        return 0;
-
-    return layer->parent()->renderer()->enclosingCompositingLayer();
-}
-
 void RenderLayerCompositor::setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer)
 {
     ASSERT(childLayer->isComposited());
@@ -678,7 +670,7 @@ bool RenderLayerCompositor::clippedByAncestor(RenderLayer* layer) const
     if (!layer->isComposited() || !layer->parent())
         return false;
 
-    RenderLayer* compositingAncestor = ancestorCompositingLayer(layer);
+    RenderLayer* compositingAncestor = layer->ancestorCompositingLayer();
 
     // We need ancestor clipping if something clips between this layer and its compositing, stacking context ancestor
     for (RenderLayer* curLayer = layer->parent(); curLayer && curLayer != compositingAncestor; curLayer = curLayer->parent()) {
index ce47f78..0574269 100644 (file)
@@ -71,9 +71,6 @@ public:
     void layerWasAdded(RenderLayer* parent, RenderLayer* child);
     void layerWillBeRemoved(RenderLayer* parent, RenderLayer* child);
 
-    // Ancestor layer of the given layer that is composited, excluding the layer itself.
-    RenderLayer* ancestorCompositingLayer(const RenderLayer*) const;
-
     // Get the nearest ancestor layer that has overflow or clip, but is not a stacking context
     RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer* layer) const;
 
index fb852e4..46eb5cf 100644 (file)
@@ -526,20 +526,6 @@ RenderLayer* RenderObject::enclosingLayer() const
     return 0;
 }
 
-#if USE(ACCELERATED_COMPOSITING)
-RenderLayer* RenderObject::enclosingCompositingLayer() const
-{
-    const RenderObject* curr = this;
-    while (curr) {
-        RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
-        if (layer && layer->isComposited())
-            return layer;
-        curr = curr->parent();
-    }
-    return 0;
-}
-#endif
-
 RenderBox* RenderObject::enclosingBox() const
 {
     RenderObject* curr = const_cast<RenderObject*>(this);
@@ -1638,7 +1624,7 @@ RenderBoxModelObject* RenderObject::containerForRepaint() const
 #if USE(ACCELERATED_COMPOSITING)
     if (RenderView* v = view()) {
         if (v->usesCompositing()) {
-            RenderLayer* compLayer = enclosingCompositingLayer();
+            RenderLayer* compLayer = enclosingLayer()->enclosingCompositingLayer();
             return compLayer ? compLayer->renderer() : 0;
         }
     }
index 92eafcc..b916880 100644 (file)
@@ -152,7 +152,7 @@ public:
     RenderObject* firstLeafChild() const;
     RenderObject* lastLeafChild() const;
 
-    // The following six functions are used when the render tree hierarchy changes to make sure layers get
+    // The following five functions are used when the render tree hierarchy changes to make sure layers get
     // properly added and removed.  Since containership can be implemented by any subclass, and since a hierarchy
     // can contain a mixture of boxes and other object types, these functions need to be in the base class.
     RenderLayer* enclosingLayer() const;
@@ -162,10 +162,6 @@ public:
     void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
     RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
 
-#if USE(ACCELERATED_COMPOSITING)
-    RenderLayer* enclosingCompositingLayer() const;
-#endif
-
     // Convenience function for getting to the nearest enclosing box of a RenderObject.
     RenderBox* enclosingBox() const;