Bug 1462961 - Refactor to save a nsDisplayTransform* instead of just the transform matrix. r?jrmuizel draft
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 23 May 2018 16:08:18 -0400
changeset 798966 0cb4adf27c7c4fd7cab62043938dbdff4573a4d3
parent 798965 1f535799fc5c948c5af2824a4a40e08854671799
child 798967 b6cb6ef58608f70b8497e2bf7466130c4c9d033f
push id110903
push userkgupta@mozilla.com
push dateWed, 23 May 2018 20:09:12 +0000
reviewersjrmuizel
bugs1462961
milestone62.0a1
Bug 1462961 - Refactor to save a nsDisplayTransform* instead of just the transform matrix. r?jrmuizel Instead of just storing the gfx::Matrix from the nsDisplayTransform on the stacking context for scrolldata use, we now store a pointer to the entire nsDisplayTransform item. We will need this in the next patch. This patch should not have any functional changes. MozReview-Commit-ID: 7qsZpL3Ka0X
gfx/layers/wr/StackingContextHelper.cpp
gfx/layers/wr/StackingContextHelper.h
gfx/layers/wr/WebRenderCommandBuilder.cpp
layout/painting/nsDisplayList.cpp
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -29,22 +29,22 @@ StackingContextHelper::StackingContextHe
                                              const gfx::Matrix4x4* aBoundTransform,
                                              const wr::WrAnimationProperty* aAnimation,
                                              const float* aOpacityPtr,
                                              const gfx::Matrix4x4* aTransformPtr,
                                              const gfx::Matrix4x4* aPerspectivePtr,
                                              const gfx::CompositionOp& aMixBlendMode,
                                              bool aBackfaceVisible,
                                              bool aIsPreserve3D,
-                                             const Maybe<gfx::Matrix4x4>& aTransformForScrollData,
+                                             const Maybe<nsDisplayTransform*>& aDeferredTransformItem,
                                              const wr::WrClipId* aClipNodeId,
                                              bool aRasterizeLocally)
   : mBuilder(&aBuilder)
   , mScale(1.0f, 1.0f)
-  , mTransformForScrollData(aTransformForScrollData)
+  , mDeferredTransformItem(aDeferredTransformItem)
   , mIsPreserve3D(aIsPreserve3D)
   , mRasterizeLocally(aRasterizeLocally || aParentSC.mRasterizeLocally)
 {
   // Compute scale for fallback rendering. We don't try to guess a scale for 3d
   // transformed items
   gfx::Matrix transform2d;
   if (aBoundTransform && aBoundTransform->CanDraw2D(&transform2d)
       && !aPerspectivePtr
@@ -84,16 +84,16 @@ StackingContextHelper::StackingContextHe
 
 StackingContextHelper::~StackingContextHelper()
 {
   if (mBuilder) {
     mBuilder->PopStackingContext();
   }
 }
 
-const Maybe<gfx::Matrix4x4>&
-StackingContextHelper::GetTransformForScrollData() const
+const Maybe<nsDisplayTransform*>&
+StackingContextHelper::GetDeferredTransformItem() const
 {
-  return mTransformForScrollData;
+  return mDeferredTransformItem;
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -8,19 +8,17 @@
 #define GFX_STACKINGCONTEXTHELPER_H
 
 #include "mozilla/Attributes.h"
 #include "mozilla/gfx/MatrixFwd.h"
 #include "mozilla/webrender/WebRenderAPI.h"
 #include "mozilla/webrender/WebRenderTypes.h"
 #include "Units.h"
 
-class nsDisplayListBuilder;
-class nsDisplayItem;
-class nsDisplayList;
+class nsDisplayTransform;
 
 namespace mozilla {
 namespace layers {
 
 /**
  * This is a helper class that pushes/pops a stacking context, and manages
  * some of the coordinate space transformations needed.
  */
@@ -34,17 +32,17 @@ public:
                         const gfx::Matrix4x4* aBoundTransform = nullptr,
                         const wr::WrAnimationProperty* aAnimation = nullptr,
                         const float* aOpacityPtr = nullptr,
                         const gfx::Matrix4x4* aTransformPtr = nullptr,
                         const gfx::Matrix4x4* aPerspectivePtr = nullptr,
                         const gfx::CompositionOp& aMixBlendMode = gfx::CompositionOp::OP_OVER,
                         bool aBackfaceVisible = true,
                         bool aIsPreserve3D = false,
-                        const Maybe<gfx::Matrix4x4>& aTransformForScrollData = Nothing(),
+                        const Maybe<nsDisplayTransform*>& aDeferredTransformItem = Nothing(),
                         const wr::WrClipId* aClipNodeId = nullptr,
                         bool aRasterizeLocally = false);
   // This version of the constructor should only be used at the root level
   // of the tree, so that we have a StackingContextHelper to pass down into
   // the RenderLayer traversal, but don't actually want it to push a stacking
   // context on the display list builder.
   StackingContextHelper();
 
@@ -59,17 +57,17 @@ public:
     return mInheritedTransform;
   }
 
   const gfx::Matrix& GetSnappingSurfaceTransform() const
   {
     return mSnappingSurfaceTransform;
   }
 
-  const Maybe<gfx::Matrix4x4>& GetTransformForScrollData() const;
+  const Maybe<nsDisplayTransform*>& GetDeferredTransformItem() const;
 
   bool AffectsClipPositioning() const { return mAffectsClipPositioning; }
   Maybe<wr::WrClipId> ReferenceFrameId() const { return mReferenceFrameId; }
 
 private:
   wr::DisplayListBuilder* mBuilder;
   gfx::Size mScale;
   gfx::Matrix mInheritedTransform;
@@ -77,17 +75,17 @@ private:
   // The "snapping surface" defines the space that we want to snap in.
   // You can think of it as the nearest physical surface.
   // Animated transforms create a new snapping surface, so that changes to their transform don't affect the snapping of their contents.
   // Non-animated transforms do *not* create a new snapping surface,
   // so that for example the existence of a non-animated identity transform does not affect snapping.
   gfx::Matrix mSnappingSurfaceTransform;
   bool mAffectsClipPositioning;
   Maybe<wr::WrClipId> mReferenceFrameId;
-  Maybe<gfx::Matrix4x4> mTransformForScrollData;
+  Maybe<nsDisplayTransform*> mDeferredTransformItem;
   bool mIsPreserve3D;
   bool mRasterizeLocally;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif /* GFX_STACKINGCONTEXTHELPER_H */
--- a/gfx/layers/wr/WebRenderCommandBuilder.cpp
+++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp
@@ -1366,19 +1366,21 @@ WebRenderCommandBuilder::CreateWebRender
         // Pop the thing we pushed before the recursion, so the topmost item on
         // the stack is enclosing display item's ASR (or the stack is empty)
         mAsrStack.pop_back();
         const ActiveScrolledRoot* stopAtAsr =
             mAsrStack.empty() ? nullptr : mAsrStack.back();
 
         int32_t descendants = mLayerScrollData.size() - layerCountBeforeRecursing;
 
+        Maybe<nsDisplayTransform*> deferred = aSc.GetDeferredTransformItem();
         mLayerScrollData.emplace_back();
         mLayerScrollData.back().Initialize(mManager->GetScrollData(), item,
-            descendants, stopAtAsr, aSc.GetTransformForScrollData());
+            descendants, stopAtAsr,
+            deferred ? Some((*deferred)->GetTransform().GetMatrix()) : Nothing());
       } else if (mLayerScrollData.size() != layerCountBeforeRecursing &&
                  !eventRegions.IsEmpty()) {
         // We are not forcing a new layer for |item|, but we did create some
         // layers while recursing. In this case, we need to make sure any
         // event regions that we were carrying end up on the right layer. So we
         // do an event region "flush" but retroactively; i.e. the event regions
         // end up on the layer that was mLayerScrollData.back() prior to the
         // recursion.
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -8629,24 +8629,24 @@ nsDisplayTransform::CreateWebRenderComma
     aManager->WrBridge()->AddWebRenderParentCommand(anim);
     aManager->AddActiveCompositorAnimationId(animationsId);
   } else if (animationsId) {
     aManager->AddCompositorAnimationsIdForDiscard(animationsId);
     animationsId = 0;
   }
 
   nsTArray<mozilla::wr::WrFilterOp> filters;
-  Maybe<Matrix4x4> transformForScrollData;
+  Maybe<nsDisplayTransform*> deferredTransformItem;
   if (!mFrame->HasPerspective()) {
     // If it has perspective, we create a new scroll data via the
     // UpdateScrollData call because that scenario is more complex. Otherwise
     // we can just stash the transform on the StackingContextHelper and
     // apply it to any scroll data that are created inside this
     // nsDisplayTransform.
-    transformForScrollData = Some(GetTransform().GetMatrix());
+    deferredTransformItem = Some(this);
   }
 
   // If it looks like we're animated, we should rasterize in local space
   // (disabling subpixel-aa and global pixel snapping)
   bool rasterizeLocally = ActiveLayerTracker::IsStyleMaybeAnimated(
     Frame(), eCSSProperty_transform);
 
   StackingContextHelper sc(aSc,
@@ -8656,17 +8656,17 @@ nsDisplayTransform::CreateWebRenderComma
                            &newTransformMatrix,
                            animationsId ? &prop : nullptr,
                            nullptr,
                            transformForSC,
                            nullptr,
                            gfx::CompositionOp::OP_OVER,
                            !BackfaceIsHidden(),
                            mFrame->Extend3DContext() && !mNoExtendContext,
-                           transformForScrollData,
+                           deferredTransformItem,
                            nullptr,
                            rasterizeLocally);
 
   return mStoredList.CreateWebRenderCommands(aBuilder, aResources, sc,
                                              aManager, aDisplayListBuilder);
 }
 
 bool