Bug 1400034 - Back out changes that introduce scaling complexity to StackingContextHelper. r?ethlin,pchang draft
authorKartikaya Gupta <kgupta@mozilla.com>
Sun, 17 Sep 2017 10:37:42 -0400
changeset 666066 ed36b1d813bc06cd28dcf811a406991dc89c7ca5
parent 666065 877d536658e644bd0d1662d608cc2ca3a9fa8d9f
child 666067 71df87f7ec982c103a0f98fe5a0ab465c583f4de
push id80263
push userkgupta@mozilla.com
push dateSun, 17 Sep 2017 14:38:05 +0000
reviewersethlin, pchang
bugs1400034, 1399050, 1394308, 1391499
milestone57.0a1
Bug 1400034 - Back out changes that introduce scaling complexity to StackingContextHelper. r?ethlin,pchang This backs out bug 1399050, bug 1394308 (2 patches), and bug 1391499. I believe these patches sent us down a path that would make the code increasingly more complex, when in fact we can do a more "direct" translation from the gecko display list to the WR display list and make things a lot simpler and more correct. MozReview-Commit-ID: ZXXkI9DXiY
gfx/layers/wr/StackingContextHelper.cpp
gfx/layers/wr/StackingContextHelper.h
layout/painting/nsDisplayList.cpp
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -9,32 +9,26 @@
 #include "UnitTransforms.h"
 #include "nsDisplayList.h"
 
 namespace mozilla {
 namespace layers {
 
 StackingContextHelper::StackingContextHelper()
   : mBuilder(nullptr)
-  , mHasPerspectiveTransform(false)
-  , mXScale(1.0f)
-  , mYScale(1.0f)
 {
   // mOrigin remains at 0,0
 }
 
 StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
                                              wr::DisplayListBuilder& aBuilder,
                                              WebRenderLayer* aLayer,
                                              const Maybe<gfx::Matrix4x4>& aTransform,
                                              const nsTArray<wr::WrFilterOp>& aFilters)
   : mBuilder(&aBuilder)
-  , mHasPerspectiveTransform(false)
-  , mXScale(1.0f)
-  , mYScale(1.0f)
 {
   wr::LayoutRect scBounds = aParentSC.ToRelativeLayoutRect(aLayer->BoundsForStackingContext());
   Layer* layer = aLayer->GetLayer();
   mTransform = aTransform.valueOr(layer->GetTransform());
 
   float opacity = 1.0f;
   mBuilder->PushStackingContext(scBounds, 0, &opacity,
                                 mTransform.IsIdentity() ? nullptr : &mTransform,
@@ -48,19 +42,16 @@ StackingContextHelper::StackingContextHe
 StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
                                              wr::DisplayListBuilder& aBuilder,
                                              WebRenderLayer* aLayer,
                                              uint64_t aAnimationsId,
                                              float* aOpacityPtr,
                                              gfx::Matrix4x4* aTransformPtr,
                                              const nsTArray<wr::WrFilterOp>& aFilters)
   : mBuilder(&aBuilder)
-  , mHasPerspectiveTransform(false)
-  , mXScale(1.0f)
-  , mYScale(1.0f)
 {
   wr::LayoutRect scBounds = aParentSC.ToRelativeLayoutRect(aLayer->BoundsForStackingContext());
   if (aTransformPtr) {
     mTransform = *aTransformPtr;
   }
 
   mBuilder->PushStackingContext(scBounds,
                                 aAnimationsId,
@@ -81,74 +72,46 @@ StackingContextHelper::StackingContextHe
                                              gfx::Matrix4x4Typed<LayerPixel, LayerPixel>* aBoundTransform,
                                              uint64_t aAnimationsId,
                                              float* aOpacityPtr,
                                              gfx::Matrix4x4* aTransformPtr,
                                              gfx::Matrix4x4* aPerspectivePtr,
                                              const nsTArray<wr::WrFilterOp>& aFilters,
                                              const gfx::CompositionOp& aMixBlendMode)
   : mBuilder(&aBuilder)
-  , mHasPerspectiveTransform(false)
-  , mXScale(1.0f)
-  , mYScale(1.0f)
 {
   nsRect visibleRect;
-
-  if (aTransformPtr) {
-    mTransform = *aTransformPtr;
-  }
-
-  // Apply the inherited scale from parent
-  mTransform.PostScale(aParentSC.mXScale, aParentSC.mYScale, 1.0);
-  mTransform.NudgeToIntegersFixedEpsilon();
-
-  if (aPerspectivePtr) {
-    mHasPerspectiveTransform = true;
-  }
-
   bool is2d = !aTransformPtr || (aTransformPtr->Is2D() && !aPerspectivePtr);
   if (is2d) {
     nsRect itemBounds = aDisplayList->GetClippedBoundsWithRespectToASR(aDisplayListBuilder, aItem->GetActiveScrolledRoot());
     nsRect childrenVisible = aItem->GetVisibleRectForChildren();
     visibleRect = itemBounds.Intersect(childrenVisible);
-
-    // Calculate the correct scale for current stacking context
-    gfx::Size scale = mTransform.As2D().ScaleFactors(true);
-
-    // Restore the scale to default if the scale is too small
-    if (FuzzyEqualsAdditive(scale.width, 0.0f) ||
-        FuzzyEqualsAdditive(scale.height, 0.0f)) {
-      scale = gfx::Size(1.0f, 1.0f);
-    }
-
-    mTransform.PreScale(1.0f/scale.width, 1.0f/scale.height, 1.0);
-
-    // Store the inherited scale for child
-    this->mXScale = scale.width;
-    this->mYScale = scale.height;
   } else {
     visibleRect = aDisplayList->GetBounds(aDisplayListBuilder);
     // The position of bounds are calculated by transform and perspective matrix in 3d case. reset it to (0, 0)
     visibleRect.MoveTo(0, 0);
   }
   float appUnitsPerDevPixel = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
   LayerRect bounds = ViewAs<LayerPixel>(LayoutDeviceRect::FromAppUnits(visibleRect, appUnitsPerDevPixel),
                                         PixelCastJustification::WebRenderHasUnitResolution);
 
   // WR will only apply the 'translate' of the transform, so we need to do the scale/rotation manually.
   if (aBoundTransform && !aBoundTransform->IsIdentity() && is2d) {
     bounds.MoveTo(aBoundTransform->TransformPoint(bounds.TopLeft()));
   }
 
   wr::LayoutRect scBounds = aParentSC.ToRelativeLayoutRect(bounds);
+  if (aTransformPtr) {
+    mTransform = *aTransformPtr;
+  }
 
   mBuilder->PushStackingContext(scBounds,
                                 aAnimationsId,
                                 aOpacityPtr,
-                                aTransformPtr ? &mTransform : aTransformPtr,
+                                aTransformPtr,
                                 is2d ? wr::TransformStyle::Flat : wr::TransformStyle::Preserve3D,
                                 aPerspectivePtr,
                                 wr::ToMixBlendMode(aMixBlendMode),
                                 aFilters);
 
   mOrigin = bounds.TopLeft();
 }
 
@@ -157,35 +120,23 @@ StackingContextHelper::~StackingContextH
   if (mBuilder) {
     mBuilder->PopStackingContext();
   }
 }
 
 wr::LayoutRect
 StackingContextHelper::ToRelativeLayoutRect(const LayerRect& aRect) const
 {
-  // Multiply by the scale inherited from ancestors if exits
-  LayerRect aMaybeScaledRect = aRect;
-  if (mXScale != 1.0f || mYScale != 1.0f) {
-    aMaybeScaledRect.Scale(mXScale, mYScale);
-  }
-
-  return wr::ToLayoutRect(RoundedToInt(aMaybeScaledRect - mOrigin));
+  return wr::ToLayoutRect(RoundedToInt(aRect - mOrigin));
 }
 
 wr::LayoutRect
 StackingContextHelper::ToRelativeLayoutRect(const LayoutDeviceRect& aRect) const
 {
-  // Multiply by the scale inherited from ancestors if exits
-  LayoutDeviceRect aMaybeScaledRect = aRect;
-  if (mXScale != 1.0f || mYScale != 1.0f) {
-    aMaybeScaledRect.Scale(mXScale, mYScale);
-  }
-
-  return wr::ToLayoutRect(RoundedToInt(ViewAs<LayerPixel>(aMaybeScaledRect,
+  return wr::ToLayoutRect(RoundedToInt(ViewAs<LayerPixel>(aRect,
                                                           PixelCastJustification::WebRenderHasUnitResolution) - mOrigin));
 }
 
 wr::LayoutPoint
 StackingContextHelper::ToRelativeLayoutPoint(const LayerPoint& aPoint) const
 {
   return wr::ToLayoutPoint(aPoint - mOrigin);
 }
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -78,36 +78,20 @@ public:
   // same as the layer space. (TODO: try to make this more explicit somehow).
   // We also round the rectangle to ints after transforming since the output
   // is the final destination rect.
   wr::LayoutRect ToRelativeLayoutRect(const LayerRect& aRect) const;
   wr::LayoutRect ToRelativeLayoutRect(const LayoutDeviceRect& aRect) const;
   // Same but for points
   wr::LayoutPoint ToRelativeLayoutPoint(const LayerPoint& aPoint) const;
 
-  // Export the inherited scale
-  gfx::Size GetInheritedScale() const {
-    return gfx::Size(mXScale, mYScale);
-  }
-
-  // Provide interface to setup the inherited scale to support
-  // special cases, like OMTA
-  void SetInheritedScale(const gfx::Size& aScale) {
-    mXScale = aScale.width;
-    mYScale = aScale.height;
-  }
-
   bool IsBackfaceVisible() const { return mTransform.IsBackfaceVisible(); }
-  bool HasPerspectiveTransform() const { return mHasPerspectiveTransform; }
 
 private:
   wr::DisplayListBuilder* mBuilder;
   LayerPoint mOrigin;
   gfx::Matrix4x4 mTransform;
-  bool mHasPerspectiveTransform;
-  float mXScale;
-  float mYScale;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif /* GFX_STACKINGCONTEXTHELPER_H */
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -7910,16 +7910,25 @@ nsDisplayTransform::CreateWebRenderComma
 
   if (!animationInfo.GetAnimations().IsEmpty()) {
     animationsId = animationInfo.GetCompositorAnimationsId();
 
     // Update transfrom as nullptr in stacking context if there exists
     // transform animation, the transform value will be resolved
     // after animation sampling on the compositor
     transformForSC = nullptr;
+
+    // Pass default transform to compositor in case gecko fails to
+    // get animated value after animation sampling.
+    OptionalTransform transformForCompositor = newTransformMatrix;
+
+    OpAddCompositorAnimations
+      anim(CompositorAnimations(animationInfo.GetAnimations(), animationsId),
+           transformForCompositor, void_t());
+    aManager->WrBridge()->AddWebRenderParentCommand(anim);
   }
 
   gfx::Matrix4x4Typed<LayerPixel, LayerPixel> boundTransform = ViewAs< gfx::Matrix4x4Typed<LayerPixel, LayerPixel> >(newTransformMatrix);
   boundTransform._41 = 0.0f;
   boundTransform._42 = 0.0f;
   boundTransform._43 = 0.0f;
 
   nsTArray<mozilla::wr::WrFilterOp> filters;
@@ -7930,43 +7939,16 @@ nsDisplayTransform::CreateWebRenderComma
                            mStoredList.GetChildren(),
                            &boundTransform,
                            animationsId,
                            nullptr,
                            transformForSC,
                            nullptr,
                            filters);
 
-  if (animationsId) {
-    // Get the inheritedScale from parent and pass the scale to compositor
-    // to get correct sampling result
-    gfx::Size scale = aSc.GetInheritedScale();
-    for (layers::Animation& animation : animationInfo.GetAnimations()) {
-      if (animation.property() == eCSSProperty_transform) {
-        TransformData& transformData = animation.data().get_TransformData();
-        transformData.inheritedXScale() = scale.width;
-        transformData.inheritedYScale() = scale.height;
-        transformData.hasPerspectiveParent() = aSc.HasPerspectiveTransform();
-      }
-    }
-
-    // Pass default transform to compositor in case gecko fails to
-    // get animated value after animation sampling.
-    OptionalTransform transformForCompositor = newTransformMatrix;
-    OpAddCompositorAnimations
-      anim(CompositorAnimations(animationInfo.GetAnimations(), animationsId),
-           transformForCompositor, void_t());
-    aManager->WrBridge()->AddWebRenderParentCommand(anim);
-
-    // Since we passed a nullptr transformForSC to the StackingContextHelper,
-    // we now set up the correct inherited scale for the stacking context.
-    newTransformMatrix.PostScale(scale.width, scale.height, 1.0f);
-    sc.SetInheritedScale(newTransformMatrix.As2D().ScaleFactors(true));
-
-  }
   return mStoredList.CreateWebRenderCommands(aBuilder, aResources, sc, aParentCommands,
                                              aManager, aDisplayListBuilder);
 }
 
 bool
 nsDisplayTransform::UpdateScrollData(mozilla::layers::WebRenderScrollData* aData,
                                      mozilla::layers::WebRenderLayerScrollData* aLayerData)
 {