Bug 1288210 - Simplify AlignFixedAndStickyLayers by not considering the ancestor transform. r=kats,mstange draft
authorBotond Ballo <botond@mozilla.com>
Fri, 23 Sep 2016 19:52:15 -0400
changeset 418539 d3a07e2bb0a727de25817d0d9ca18bdf92d6c6bf
parent 418538 9f86bef66ca93e729c6c5a6f0e75d590bce03366
child 418540 88f31ae44e7baeff546624ba0e058d33ba6dc72f
push id30704
push userbballo@mozilla.com
push dateWed, 28 Sep 2016 17:44:27 +0000
reviewerskats, mstange
bugs1288210
milestone52.0a1
Bug 1288210 - Simplify AlignFixedAndStickyLayers by not considering the ancestor transform. r=kats,mstange There shouldn't be an ancestor transform, because transforms create containing blocks for fixed-position descendants. MozReview-Commit-ID: IVp1djLgIV9
gfx/layers/composite/AsyncCompositionManager.cpp
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -292,28 +292,30 @@ TranslateShadowLayer(Layer* aLayer,
     // If a fixed- or sticky-position layer has a mask layer, that mask should
     // move along with the layer, so apply the translation to the mask layer too.
     if (Layer* maskLayer = aLayer->GetMaskLayer()) {
       TranslateShadowLayer(maskLayer, aTranslation, false, aClipPartsCache);
     }
   }
 }
 
+#ifdef DEBUG
 static void
 AccumulateLayerTransforms(Layer* aLayer,
                           Layer* aAncestor,
                           Matrix4x4& aMatrix)
 {
   // Accumulate the transforms between this layer and the subtree root layer.
   for (Layer* l = aLayer; l && l != aAncestor; l = l->GetParent()) {
     Matrix4x4 transform;
     GetBaseTransform(l, &transform);
     aMatrix *= transform;
   }
 }
+#endif
 
 static LayerPoint
 GetLayerFixedMarginsOffset(Layer* aLayer,
                            const ScreenMargin& aFixedLayerMargins)
 {
   // Work out the necessary translation, in root scrollable layer space.
   // Because fixed layer margins are stored relative to the root scrollable
   // layer, we can just take the difference between these values.
@@ -430,16 +432,22 @@ IsFixedOrSticky(Layer* aLayer)
 void
 AsyncCompositionManager::AlignFixedAndStickyLayers(Layer* aTransformedSubtreeRoot,
                                                    FrameMetrics::ViewID aTransformScrollId,
                                                    const LayerToParentLayerMatrix4x4& aPreviousTransformForRoot,
                                                    const LayerToParentLayerMatrix4x4& aCurrentTransformForRoot,
                                                    const ScreenMargin& aFixedLayerMargins,
                                                    ClipPartsCache* aClipPartsCache)
 {
+  // We're going to be inverting |aCurrentTransformForRoot|.
+  // If it's singular, there's nothing we can do.
+  if (aCurrentTransformForRoot.IsSingular()) {
+    return;
+  }
+
   ForEachNode<ForwardIterator>(
       aTransformedSubtreeRoot,
       [&] (Layer* layer)
       {
         bool needsAsyncTransformUnapplied = false;
         if (Maybe<FrameMetrics::ViewID> fixedTo = IsFixedOrSticky(layer)) {
           needsAsyncTransformUnapplied = AsyncTransformShouldBeUnapplied(layer,
               *fixedTo, aTransformedSubtreeRoot, aTransformScrollId);
@@ -448,63 +456,65 @@ AsyncCompositionManager::AlignFixedAndSt
         // We want to process all the fixed and sticky descendants of
         // aTransformedSubtreeRoot. Once we do encounter such a descendant, we don't
         // need to recurse any deeper because the adjustment to the fixed or sticky
         // layer will apply to its subtree.
         if (!needsAsyncTransformUnapplied) {
           return TraversalFlag::Continue;
         }
 
+
         // Insert a translation so that the position of the anchor point is the same
         // before and after the change to the transform of aTransformedSubtreeRoot.
 
-        // Accumulate the transforms between this layer and the subtree root layer.
+        // A transform creates a containing block for fixed-position descendants,
+        // so there shouldn't be a transform in between the fixed layer and
+        // the subtree root layer.
+#ifdef DEBUG
         Matrix4x4 ancestorTransform;
         if (layer != aTransformedSubtreeRoot) {
           AccumulateLayerTransforms(layer->GetParent(), aTransformedSubtreeRoot,
                                     ancestorTransform);
         }
+        MOZ_ASSERT(ancestorTransform.IsIdentity());
+#endif
 
-        // Calculate the cumulative transforms between the subtree root with the
-        // old transform and the current transform.
-        Matrix4x4 oldCumulativeTransform = ancestorTransform * aPreviousTransformForRoot.ToUnknownMatrix();
-        Matrix4x4 newCumulativeTransform = ancestorTransform * aCurrentTransformForRoot.ToUnknownMatrix();
-        if (newCumulativeTransform.IsSingular()) {
-          return TraversalFlag::Skip;
-        }
-
-        // Add in the layer's local transform, if it isn't already included in
-        // |aPreviousTransformForRoot| and |aCurrentTransformForRoot| (this happens
-        // when the fixed/sticky layer is itself the transformed subtree root).
+        // Calculate the old and new transforms between the fixed layer and
+        // the subtree root, including the fixed layer's local transform
+        // if it's not already included in |aPreviousTransformForRoot| and
+        // |aCurrentTransformForRoot| (this happens when the fixed layer is
+        // itself the transformed subtree root).
+        Matrix4x4 oldTransform = aPreviousTransformForRoot.ToUnknownMatrix();
+        Matrix4x4 newTransform = aCurrentTransformForRoot.ToUnknownMatrix();
         Matrix4x4 localTransform;
         GetBaseTransform(layer, &localTransform);
         if (layer != aTransformedSubtreeRoot) {
-          oldCumulativeTransform = localTransform * oldCumulativeTransform;
-          newCumulativeTransform = localTransform * newCumulativeTransform;
+          oldTransform = localTransform * oldTransform;
+          newTransform = localTransform * newTransform;
         }
 
         // Now work out the translation necessary to make sure the layer doesn't
         // move given the new sub-tree root transform.
 
         // Get the layer's fixed anchor point, in the layer's local coordinate space
-        // (before any cumulative transform is applied).
+        // (before any transform is applied).
         LayerPoint anchor = layer->GetFixedPositionAnchor();
 
         // Offset the layer's anchor point to make sure fixed position content
         // respects content document fixed position margins.
         LayerPoint offsetAnchor = anchor + GetLayerFixedMarginsOffset(layer, aFixedLayerMargins);
 
         // Additionally transform the anchor to compensate for the change
-        // from the old cumulative transform to the new cumulative transform. We do
+        // from the old transform to the new transform. We do
         // this by using the old transform to take the offset anchor back into
-        // subtree root space, and then the inverse of the new cumulative transform
+        // subtree root space, and then the inverse of the new transform
         // to bring it back to layer space.
         LayerPoint transformedAnchor = ViewAs<LayerPixel>(
-            newCumulativeTransform.Inverse().TransformPoint(
-              (oldCumulativeTransform.TransformPoint(offsetAnchor.ToUnknownPoint()))));
+            newTransform.Inverse().TransformPoint(
+              (oldTransform.TransformPoint(offsetAnchor.ToUnknownPoint()))));
 
         // We want to translate the layer by the difference between |transformedAnchor|
         // and |anchor|. To achieve this, we will add a translation to the layer's
         // transform. This translation will apply on top of the layer's local
         // transform, but |anchor| and |transformedAnchor| are in a coordinate space
         // where the local transform isn't applied yet, so apply it and then subtract
         // to get the desired translation.
         auto localTransformTyped = ViewAs<LayerToParentLayerMatrix4x4>(localTransform);