Bug 1363922 - Part 2: Estimate scale of frames using their transformation relative to the root frame. r=mstange draft
authorBas Schouten <bschouten@mozilla.com>
Thu, 24 Aug 2017 18:22:52 +0200
changeset 652221 6c05cd077d32c533d54b6e5169c9359d47fd5162
parent 652220 63e6c623a627fa5ca36d719cb470981f05cc00a5
child 728028 2900c1f2c37bebaae9996fe4d38ebe365966f95b
push id75993
push userbschouten@mozilla.com
push dateThu, 24 Aug 2017 16:23:18 +0000
reviewersmstange
bugs1363922
milestone57.0a1
Bug 1363922 - Part 2: Estimate scale of frames using their transformation relative to the root frame. r=mstange MozReview-Commit-ID: HTDaOz7sz5c
layout/painting/FrameLayerBuilder.cpp
--- a/layout/painting/FrameLayerBuilder.cpp
+++ b/layout/painting/FrameLayerBuilder.cpp
@@ -5869,50 +5869,34 @@ PredictScaleForContent(nsIFrame* aFrame,
   }
   return gfxSize(1.0, 1.0);
 }
 
 gfxSize
 FrameLayerBuilder::GetPaintedLayerScaleForFrame(nsIFrame* aFrame)
 {
   MOZ_ASSERT(aFrame, "need a frame");
-  nsIFrame* last = nullptr;
-  for (nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
-    last = f;
-
-    if (nsLayoutUtils::IsPopup(f)) {
-      // Don't examine ancestors of a popup. It won't make sense to check
-      // the transform from some content inside the popup to some content
-      // which is an ancestor of the popup.
-      break;
-    }
-
-    const SmallPointerArray<DisplayItemData>& array = aFrame->DisplayItemData();
-
-    for (uint32_t i = 0; i < array.Length(); i++) {
-      Layer* layer = DisplayItemData::AssertDisplayItemData(array.ElementAt(i))->mLayer;
-      ContainerLayer* container = layer->AsContainerLayer();
-      if (!container ||
-          !layer->Manager()->IsWidgetLayerManager()) {
-        continue;
-      }
-      for (Layer* l = container->GetFirstChild(); l; l = l->GetNextSibling()) {
-        PaintedDisplayItemLayerUserData* data =
-            static_cast<PaintedDisplayItemLayerUserData*>
-              (l->GetUserData(&gPaintedDisplayItemLayerUserData));
-        if (data) {
-          return PredictScaleForContent(aFrame, f, gfxSize(data->mXScale, data->mYScale));
-        }
-      }
-    }
-  }
-
-  float presShellResolution = last->PresContext()->PresShell()->GetResolution();
-  return PredictScaleForContent(aFrame, last,
-      gfxSize(presShellResolution, presShellResolution));
+
+  nsIFrame* root = aFrame->PresContext()->GetRootPresContext()->PresShell()->GetRootFrame();
+
+  MOZ_ASSERT(root);
+
+  Matrix4x4 transform = Matrix4x4::Scaling(root->PresContext()->PresShell()->GetResolution(),
+                                           root->PresContext()->PresShell()->GetResolution(), 1.0);
+  if (aFrame != root) {
+    // aTransform is applied first, then the scale is applied to the result
+    transform = nsLayoutUtils::GetTransformToAncestor(aFrame, root) * transform;
+  }
+
+  Matrix transform2d;
+  if (transform.CanDraw2D(&transform2d)) {
+    return ThebesMatrix(transform2d).ScaleFactors(true);
+  }
+
+  return gfxSize(1.0, 1.0);
 }
 
 #ifdef MOZ_DUMP_PAINTING
 static void DebugPaintItem(DrawTarget& aDrawTarget,
                            nsPresContext* aPresContext,
                            nsDisplayItem *aItem,
                            nsDisplayListBuilder* aBuilder)
 {