Bug 579276. Part 4: Move nsDisplayItem parameter down to ThebesLayerData::Accumulate. r=tnikkel
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 02 Sep 2010 21:18:39 +1200
changeset 51877 1c7bd1f8c86dabfa082a9ea23cdd1bc8cf876608
parent 51876 f2a5d669a7f97f3af53a0295c8448d1d59c828e8
child 51878 022723860a7f2db3807667eee2f273ddd174d99f
push idunknown
push userunknown
push dateunknown
reviewerstnikkel
bugs579276
milestone2.0b6pre
Bug 579276. Part 4: Move nsDisplayItem parameter down to ThebesLayerData::Accumulate. r=tnikkel
layout/base/FrameLayerBuilder.cpp
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -168,20 +168,20 @@ protected:
      * was completely visible
      * @param aOpaqueRect if non-null, the area of the item that's opaque.
      * We pass in a separate opaque rect because the opaque rect can be
      * bigger than the visible rect, and we want to have the biggest
      * opaque rect that we can.
      * @param aSolidColor if non-null, the visible area of the item is
      * a constant color given by *aSolidColor
      */
-    void Accumulate(const nsIntRect& aVisibleRect,
-                    const nsIntRect& aDrawRect,
-                    const nsIntRect* aOpaqueRect,
-                    nscolor* aSolidColor);
+    void Accumulate(nsDisplayListBuilder* aBuilder,
+                    nsDisplayItem* aItem,
+                    const nsIntRect& aVisibleRect,
+                    const nsIntRect& aDrawRect);
     nsIFrame* GetActiveScrolledRoot() { return mActiveScrolledRoot; }
 
     /**
      * The region of visible content in the layer, relative to the
      * container layer (which is at the snapped top-left of the display
      * list reference frame).
      */
     nsIntRegion  mVisibleRegion;
@@ -277,21 +277,20 @@ protected:
    * ThebesLayerData stack, later elements on the stack will be popped off.
    * @param aVisibleRect the area of the next display item that's visible
    * @param aActiveScrolledRoot the active scrolled root for the next
    * display item
    * @param aOpaqueRect if non-null, a region of the display item that is opaque
    * @param aSolidColor if non-null, indicates that every pixel in aVisibleRect
    * will be painted with aSolidColor by the item
    */
-  already_AddRefed<ThebesLayer> FindThebesLayerFor(const nsIntRect& aVisibleRect,
+  already_AddRefed<ThebesLayer> FindThebesLayerFor(nsDisplayItem* aItem,
+                                                   const nsIntRect& aVisibleRect,
                                                    const nsIntRect& aDrawRect,
-                                                   nsIFrame* aActiveScrolledRoot,
-                                                   const nsIntRect* aOpaqueRect,
-                                                   nscolor* aSolidColor);
+                                                   nsIFrame* aActiveScrolledRoot);
   ThebesLayerData* GetTopThebesLayerData()
   {
     return mThebesLayerDataStack.IsEmpty() ? nsnull
         : mThebesLayerDataStack[mThebesLayerDataStack.Length() - 1].get();
   }
 
   nsDisplayListBuilder*            mBuilder;
   LayerManager*                    mManager;
@@ -856,61 +855,62 @@ ContainerState::PopThebesLayerData()
     nextData->mDrawAboveRegion.Or(nextData->mDrawAboveRegion,
                                      data->mDrawRegion);
   }
 
   mThebesLayerDataStack.RemoveElementAt(lastIndex);
 }
 
 void
-ContainerState::ThebesLayerData::Accumulate(const nsIntRect& aVisibleRect,
-                                            const nsIntRect& aDrawRect,
-                                            const nsIntRect* aOpaqueRect,
-                                            nscolor* aSolidColor)
+ContainerState::ThebesLayerData::Accumulate(nsDisplayListBuilder* aBuilder,
+                                            nsDisplayItem* aItem,
+                                            const nsIntRect& aVisibleRect,
+                                            const nsIntRect& aDrawRect)
 {
-  if (aSolidColor) {
+  nscolor uniformColor;
+  if (aItem->IsUniform(aBuilder, &uniformColor)) {
     if (mVisibleRegion.IsEmpty()) {
       // This color is all we have
-      mSolidColor = *aSolidColor;
+      mSolidColor = uniformColor;
       mIsSolidColorInVisibleRegion = PR_TRUE;
     } else if (mIsSolidColorInVisibleRegion &&
                mVisibleRegion.IsEqual(nsIntRegion(aVisibleRect))) {
       // we can just blend the colors together
-      mSolidColor = NS_ComposeColors(mSolidColor, *aSolidColor);
+      mSolidColor = NS_ComposeColors(mSolidColor, uniformColor);
     } else {
       mIsSolidColorInVisibleRegion = PR_FALSE;
     }
   } else {
     mIsSolidColorInVisibleRegion = PR_FALSE;
   }
 
   mVisibleRegion.Or(mVisibleRegion, aVisibleRect);
   mVisibleRegion.SimplifyOutward(4);
   mDrawRegion.Or(mDrawRegion, aDrawRect);
   mDrawRegion.SimplifyOutward(4);
-  if (aOpaqueRect) {
+
+  if (aItem->IsOpaque(aBuilder)) {
     // We don't use SimplifyInward here since it's not defined exactly
     // what it will discard. For our purposes the most important case
     // is a large opaque background at the bottom of z-order (e.g.,
     // a canvas background), so we need to make sure that the first rect
     // we see doesn't get discarded.
     nsIntRegion tmp;
-    tmp.Or(mOpaqueRegion, *aOpaqueRect);
+    tmp.Or(mOpaqueRegion, aDrawRect);
     if (tmp.GetNumRects() <= 4) {
       mOpaqueRegion = tmp;
     }
   }
 }
 
 already_AddRefed<ThebesLayer>
-ContainerState::FindThebesLayerFor(const nsIntRect& aVisibleRect,
+ContainerState::FindThebesLayerFor(nsDisplayItem* aItem,
+                                   const nsIntRect& aVisibleRect,
                                    const nsIntRect& aDrawRect,
-                                   nsIFrame* aActiveScrolledRoot,
-                                   const nsIntRect* aOpaqueRect,
-                                   nscolor* aSolidColor)
+                                   nsIFrame* aActiveScrolledRoot)
 {
   PRInt32 i;
   PRInt32 lowestUsableLayerWithScrolledRoot = -1;
   PRInt32 topmostLayerWithScrolledRoot = -1;
   for (i = mThebesLayerDataStack.Length() - 1; i >= 0; --i) {
     ThebesLayerData* data = mThebesLayerDataStack[i];
     if (data->mDrawAboveRegion.Intersects(aVisibleRect)) {
       ++i;
@@ -954,17 +954,17 @@ ContainerState::FindThebesLayerFor(const
     mThebesLayerDataStack.AppendElement(thebesLayerData);
     thebesLayerData->mLayer = layer;
     thebesLayerData->mActiveScrolledRoot = aActiveScrolledRoot;
   } else {
     thebesLayerData = mThebesLayerDataStack[lowestUsableLayerWithScrolledRoot];
     layer = thebesLayerData->mLayer;
   }
 
-  thebesLayerData->Accumulate(aVisibleRect, aDrawRect, aOpaqueRect, aSolidColor);
+  thebesLayerData->Accumulate(mBuilder, aItem, aVisibleRect, aDrawRect);
   return layer.forget();
 }
 
 static already_AddRefed<BasicLayerManager>
 BuildTempManagerForInactiveLayer(nsDisplayListBuilder* aBuilder,
                                  nsDisplayItem* aItem)
 {
   // This item has an inactive layer. We will render it to a ThebesLayer
@@ -1100,27 +1100,19 @@ ContainerState::ProcessDisplayItems(cons
         // nsGfxScrollFrame will not repaint this item when scrolling occurs.
         nsIFrame* viewportFrame =
           nsLayoutUtils::GetClosestFrameOfType(f, nsGkAtoms::viewportFrame);
         NS_ASSERTION(viewportFrame, "no viewport???");
         activeScrolledRoot =
           nsLayoutUtils::GetActiveScrolledRootFor(viewportFrame, mBuilder->ReferenceFrame());
       }
 
-      nscolor uniformColor;
-      PRBool isUniform = item->IsUniform(mBuilder, &uniformColor);
-      PRBool isOpaque = item->IsOpaque(mBuilder);
-      nsIntRect opaqueRect;
-      if (isOpaque) {
-        opaqueRect = item->GetBounds(mBuilder).ToNearestPixels(appUnitsPerDevPixel);
-      }
       nsRefPtr<ThebesLayer> thebesLayer =
-        FindThebesLayerFor(itemVisibleRect, itemDrawRect, activeScrolledRoot,
-                           isOpaque ? &opaqueRect : nsnull,
-                           isUniform ? &uniformColor : nsnull);
+        FindThebesLayerFor(item, itemVisibleRect, itemDrawRect,
+                           activeScrolledRoot);
 
       InvalidateForLayerChange(item, thebesLayer);
 
       mBuilder->LayerBuilder()->
         AddThebesDisplayItem(thebesLayer, item, aClipRect, mContainerFrame,
                              layerState, tempLayerManager);
     }
   }