Bug 1169502 - Pass the offset between the PaintedLayer's AGR and the container reference frame into PaintedLayerData. r=roc draft
authorMarkus Stange <mstange@themasta.com>
Mon, 04 Apr 2016 22:51:41 -0400
changeset 352146 c70f2fa34b3ef0223bf33b5c9a2265c748e66568
parent 352145 d2f95cfa0da2d0675575b2a61b90baf739e71f2e
child 352147 0dbce521693ec11c94c6d3de77d1219ae311fa28
push id15624
push usermstange@themasta.com
push dateFri, 15 Apr 2016 19:43:58 +0000
reviewersroc
bugs1169502
milestone48.0a1
Bug 1169502 - Pass the offset between the PaintedLayer's AGR and the container reference frame into PaintedLayerData. r=roc MozReview-Commit-ID: K0g0eG55g28
layout/base/FrameLayerBuilder.cpp
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -404,18 +404,21 @@ struct AssignedDisplayItem
  * We use a stack here because as much as possible we want to
  * assign display items to existing PaintedLayers, and to the lowest
  * PaintedLayer in z-order. This reduces the number of layers and
  * makes it more likely a display item will be rendered to an opaque
  * layer, giving us the best chance of getting subpixel AA.
  */
 class PaintedLayerData {
 public:
-  PaintedLayerData() :
-    mAnimatedGeometryRoot(nullptr),
+  PaintedLayerData(AnimatedGeometryRoot* aAnimatedGeometryRoot,
+                   const nsPoint& aTopLeft,
+                   const nsIntPoint& aSnappedOffset) :
+    mAnimatedGeometryRoot(aAnimatedGeometryRoot),
+    mAnimatedGeometryRootOffset(aTopLeft),
     mScrollClip(nullptr),
     mReferenceFrame(nullptr),
     mLayer(nullptr),
     mSolidColor(NS_RGBA(0, 0, 0, 0)),
     mIsSolidColorInVisibleRegion(false),
     mFontSmoothingBackgroundColor(NS_RGBA(0,0,0,0)),
     mExclusiveToOneItem(false),
     mSingleItemFixedToViewport(false),
@@ -423,17 +426,17 @@ public:
     mNeedComponentAlpha(false),
     mForceTransparentSurface(false),
     mHideAllLayersBelow(false),
     mOpaqueForAnimatedGeometryRootParent(false),
     mDisableFlattening(false),
     mBackfaceHidden(false),
     mImage(nullptr),
     mCommonClipCount(-1),
-    mNewChildLayersIndex(-1)
+    mNewChildLayersIndex(-1),
   {}
 
 #ifdef MOZ_DUMP_PAINTING
   /**
    * Keep track of important decisions for debugging.
    */
   nsCString mLog;
 
@@ -741,17 +744,18 @@ class PaintedLayerDataTree;
  * stack, in z-order, and the clip rects of the child nodes are allowed to
  * intersect with the visible region or visible above region of their parent
  * node's PaintedLayerDatas.
  */
 class PaintedLayerDataNode {
 public:
   PaintedLayerDataNode(PaintedLayerDataTree& aTree,
                        PaintedLayerDataNode* aParent,
-                       AnimatedGeometryRoot* aAnimatedGeometryRoot);
+                       AnimatedGeometryRoot* aAnimatedGeometryRoot,
+                       const nsIntPoint& aSnappedOffset);
   ~PaintedLayerDataNode();
 
   AnimatedGeometryRoot* GetAnimatedGeometryRoot() const { return mAnimatedGeometryRoot; }
 
   /**
    * Whether this node's contents can potentially intersect aRect.
    * aRect is in our tree's ContainerState's coordinate space.
    */
@@ -841,16 +845,17 @@ protected:
    * Pass off opaque background color searching to our parent node, if we have
    * one.
    */
   nscolor FindOpaqueBackgroundColorInParentNode() const;
 
   PaintedLayerDataTree& mTree;
   PaintedLayerDataNode* mParent;
   AnimatedGeometryRoot* mAnimatedGeometryRoot;
+  const nsIntPoint mSnappedAnimatedGeometryRootOffset;
 
   /**
    * Our contents: a PaintedLayerData stack and our child nodes.
    */
   nsTArray<PaintedLayerData> mPaintedLayerDataStack;
 
   /**
    * UniquePtr is used here in the sense of "unique ownership", i.e. there is
@@ -1145,19 +1150,30 @@ public:
   {
     if (aSnap && mSnappingEnabled) {
       return ScaleRegionToNearestPixels(aRegion);
     }
     return aRegion.ScaleToOutsidePixels(mParameters.mXScale, mParameters.mYScale,
                                         mAppUnitsPerDevPixel);
   }
 
+  nsIntPoint SnapPointToPixels(const nsPoint& aPoint) const
+  {
+    return aPoint.ScaleToNearestPixels(mParameters.mXScale, mParameters.mYScale,
+                                       mAppUnitsPerDevPixel);
+  }
+
   nsIFrame* GetContainerFrame() const { return mContainerFrame; }
   nsDisplayListBuilder* Builder() const { return mBuilder; }
 
+  nsIntPoint GetSnappedOffsetToContainerReferenceFrame(const nsIFrame* aFrame)
+  {
+    return SnapPointToPixels(aFrame->GetOffsetToCrossDoc(mContainerReferenceFrame));
+  }
+
   /**
    * Check if we are currently inside an inactive layer.
    */
   bool IsInInactiveLayer() const {
     return mLayerBuilder->GetContainingPaintedLayerData();
   }
 
   /**
@@ -2522,17 +2538,18 @@ PaintedLayerData::GetContainerForImageLa
     return nullptr;
   }
 
   return mImage->GetContainer(mLayer->Manager(), aBuilder);
 }
 
 PaintedLayerDataNode::PaintedLayerDataNode(PaintedLayerDataTree& aTree,
                                            PaintedLayerDataNode* aParent,
-                                           AnimatedGeometryRoot* aAnimatedGeometryRoot)
+                                           AnimatedGeometryRoot* aAnimatedGeometryRoot,
+                                           const nsIntPoint& aSnappedOffset)
   : mTree(aTree)
   , mParent(aParent)
   , mAnimatedGeometryRoot(aAnimatedGeometryRoot)
   , mAllDrawingAboveBackground(false)
 {
   MOZ_ASSERT(nsLayoutUtils::IsAncestorFrameCrossDoc(mTree.Builder()->RootReferenceFrame(), *mAnimatedGeometryRoot));
   mHasClip = mTree.IsClippedWithRespectToParentAnimatedGeometryRoot(mAnimatedGeometryRoot, &mClipRect);
 }
@@ -2542,18 +2559,19 @@ PaintedLayerDataNode::~PaintedLayerDataN
   MOZ_ASSERT(mPaintedLayerDataStack.IsEmpty());
   MOZ_ASSERT(mChildren.IsEmpty());
 }
 
 PaintedLayerDataNode*
 PaintedLayerDataNode::AddChildNodeFor(AnimatedGeometryRoot* aAnimatedGeometryRoot)
 {
   MOZ_ASSERT(aAnimatedGeometryRoot->mParentAGR == mAnimatedGeometryRoot);
+  nsIntPoint snappedOffset = mTree.ContState().GetSnappedOffsetToContainerReferenceFrame(*aAnimatedGeometryRoot);
   UniquePtr<PaintedLayerDataNode> child =
-    MakeUnique<PaintedLayerDataNode>(mTree, this, aAnimatedGeometryRoot);
+    MakeUnique<PaintedLayerDataNode>(mTree, this, aAnimatedGeometryRoot, snappedOffset);
   mChildren.AppendElement(Move(child));
   return mChildren.LastElement().get();
 }
 
 template<typename NewPaintedLayerCallbackType>
 PaintedLayerData*
 PaintedLayerDataNode::FindPaintedLayerFor(const nsIntRect& aVisibleRect,
                                           bool aBackfaceHidden,
@@ -2803,17 +2821,18 @@ PaintedLayerDataTree::EnsureNodeFor(Anim
   if (node) {
     return node;
   }
 
   AnimatedGeometryRoot* parentAnimatedGeometryRoot = aAnimatedGeometryRoot->mParentAGR;
   if (!parentAnimatedGeometryRoot) {
     MOZ_ASSERT(!mRoot);
     MOZ_ASSERT(*aAnimatedGeometryRoot == Builder()->RootReferenceFrame());
-    mRoot = MakeUnique<PaintedLayerDataNode>(*this, nullptr, aAnimatedGeometryRoot);
+    nsIntPoint snappedOffset = ContState().GetSnappedOffsetToContainerReferenceFrame(*aAnimatedGeometryRoot);
+    mRoot = MakeUnique<PaintedLayerDataNode>(*this, nullptr, aAnimatedGeometryRoot, snappedOffset);
     node = mRoot.get();
   } else {
     PaintedLayerDataNode* parentNode = EnsureNodeFor(parentAnimatedGeometryRoot);
     MOZ_ASSERT(parentNode);
     node = parentNode->AddChildNodeFor(aAnimatedGeometryRoot);
   }
   MOZ_ASSERT(node);
   mNodes.Put(aAnimatedGeometryRoot, node);
@@ -3417,20 +3436,18 @@ PaintedLayerData::AccumulateEventRegions
 
 PaintedLayerData
 ContainerState::NewPaintedLayerData(nsDisplayItem* aItem,
                                     AnimatedGeometryRoot* aAnimatedGeometryRoot,
                                     const DisplayItemScrollClip* aScrollClip,
                                     const nsPoint& aTopLeft,
                                     bool aShouldFixToViewport)
 {
-  PaintedLayerData data;
-  data.mAnimatedGeometryRoot = aAnimatedGeometryRoot;
+  PaintedLayerData data(aAnimatedGeometryRoot, aTopLeft, SnapPointToPixels(aTopLeft));
   data.mScrollClip = aScrollClip;
-  data.mAnimatedGeometryRootOffset = aTopLeft;
   data.mReferenceFrame = aItem->ReferenceFrame();
   data.mSingleItemFixedToViewport = aShouldFixToViewport;
   data.mBackfaceHidden = aItem->Frame()->In3DContextAndBackfaceIsHidden();
   data.mIsCaret = aItem->GetType() == nsDisplayItem::TYPE_CARET;
 
   data.mNewChildLayersIndex = mNewChildLayers.Length();
   NewLayerEntry* newLayerEntry = mNewChildLayers.AppendElement();
   newLayerEntry->mAnimatedGeometryRoot = aAnimatedGeometryRoot;