Bug 1461849. Snapping surface transform. r=mstange draft
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Wed, 16 May 2018 18:14:46 -0400
changeset 797301 ee2a8fa5ef852e9f4065a0c4f9cdecb8215de032
parent 797300 698f4a7e0fb802698f3e86b9fa8e654c5d604ec4
child 797302 ae96a49c162944f1db8b0a374c1132e6a788d912
push id110453
push userbmo:jmuizelaar@mozilla.com
push dateFri, 18 May 2018 21:24:06 +0000
reviewersmstange
bugs1461849
milestone62.0a1
Bug 1461849. Snapping surface transform. r=mstange Capture a snapping surface transform. This is used by svg/blob code to compute an fractional offset to the nearest intermediate surface. MozReview-Commit-ID: 6EFNvluvzvA
gfx/layers/wr/StackingContextHelper.cpp
gfx/layers/wr/StackingContextHelper.h
--- a/gfx/layers/wr/StackingContextHelper.cpp
+++ b/gfx/layers/wr/StackingContextHelper.cpp
@@ -46,16 +46,21 @@ StackingContextHelper::StackingContextHe
   // 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
       && !aParentSC.mIsPreserve3D) {
     mInheritedTransform = transform2d * aParentSC.mInheritedTransform;
     mScale = mInheritedTransform.ScaleFactors(true);
+    if (aAnimation) {
+      mSnappingSurfaceTransform = gfx::Matrix::Scaling(mScale.width, mScale.height);
+    } else {
+      mSnappingSurfaceTransform = transform2d * aParentSC.mSnappingSurfaceTransform;
+    }
   } else {
     mInheritedTransform = aParentSC.mInheritedTransform;
     mScale = aParentSC.mScale;
   }
 
   auto rasterSpace = mRasterizeLocally
     ? wr::GlyphRasterSpace::Local(std::max(mScale.width, mScale.height))
     : wr::GlyphRasterSpace::Screen();
--- a/gfx/layers/wr/StackingContextHelper.h
+++ b/gfx/layers/wr/StackingContextHelper.h
@@ -54,25 +54,37 @@ public:
   // Export the inherited scale
   gfx::Size GetInheritedScale() const { return mScale; }
 
   const gfx::Matrix& GetInheritedTransform() const
   {
     return mInheritedTransform;
   }
 
+  const gfx::Matrix& GetSnappingSurfaceTransform() const
+  {
+    return mSnappingSurfaceTransform;
+  }
+
   const Maybe<gfx::Matrix4x4>& GetTransformForScrollData() const;
 
   bool AffectsClipPositioning() const { return mAffectsClipPositioning; }
   Maybe<wr::WrClipId> ReferenceFrameId() const { return mReferenceFrameId; }
 
 private:
   wr::DisplayListBuilder* mBuilder;
   gfx::Size mScale;
   gfx::Matrix mInheritedTransform;
+
+  // 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;
   bool mIsPreserve3D;
   bool mRasterizeLocally;
 };
 
 } // namespace layers