Bug 1363922 - Part 2: Estimate scale of frames using their transformation relative to the root frame. r=mstange
MozReview-Commit-ID: HTDaOz7sz5c
--- 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)
{