diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index c469fbdbb941..820d5275b3cb 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -3370,24 +3370,28 @@ ScrollFrameHelper::DecideScrollableLayer(nsDisplayListBuilder* aBuilder, // scrollport. displayportBase = aDirtyRect->Intersect(mScrollPort); - const nsPresContext* rootPresContext = - pc->GetToplevelContentDocumentPresContext(); - if (!rootPresContext) { - rootPresContext = pc->GetRootPresContext(); - } - if (rootPresContext) { - const nsIPresShell* const rootPresShell = rootPresContext->PresShell(); - nsIFrame* rootFrame = rootPresShell->GetRootScrollFrame(); - if (!rootFrame) { - rootFrame = rootPresShell->GetRootFrame(); + // Only restrict to the root composition bounds if necessary, + // as the required coordinate transformation is expensive. + if (wasUsingDisplayPort) { + const nsPresContext* rootPresContext = + pc->GetToplevelContentDocumentPresContext(); + if (!rootPresContext) { + rootPresContext = pc->GetRootPresContext(); } - if (rootFrame) { - nsRect rootCompBounds = - nsRect(nsPoint(0, 0), nsLayoutUtils::CalculateCompositionSizeForFrame(rootFrame)); + if (rootPresContext) { + const nsIPresShell* const rootPresShell = rootPresContext->PresShell(); + nsIFrame* rootFrame = rootPresShell->GetRootScrollFrame(); + if (!rootFrame) { + rootFrame = rootPresShell->GetRootFrame(); + } + if (rootFrame) { + nsRect rootCompBounds = + nsRect(nsPoint(0, 0), nsLayoutUtils::CalculateCompositionSizeForFrame(rootFrame)); - nsLayoutUtils::TransformRect(rootFrame, mOuter, rootCompBounds); + nsLayoutUtils::TransformRect(rootFrame, mOuter, rootCompBounds); - displayportBase = displayportBase.Intersect(rootCompBounds); + displayportBase = displayportBase.Intersect(rootCompBounds); + } } }