From 979e3ee0357fbd179e9a7f69d4bccc8d080de330 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Mon, 1 May 2017 19:59:08 -0400 Subject: [PATCH] Bug 1359868 - Move the ComputePartialPrerenderArea() helper to nsLayoutUtils so it can be reused. r=mstange MozReview-Commit-ID: GVRBUfYwOFP --HG-- extra : rebase_source : 8e16daf7709cc107f21e3b8b0050df44e83089fb --- layout/base/nsLayoutUtils.cpp | 16 ++++++++++++++++ layout/base/nsLayoutUtils.h | 13 +++++++++++++ layout/painting/nsDisplayList.cpp | 15 +-------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index efc1ca9bee7e..ba9c11b23e44 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -9190,6 +9190,22 @@ nsLayoutUtils::GetCumulativeApzCallbackTransform(nsIFrame* aFrame) return delta; } +/* static */ nsRect +nsLayoutUtils::ComputePartialPrerenderArea(const nsRect& aDirtyRect, + const nsRect& aOverflow, + const nsSize& aPrerenderSize) +{ + // Simple calculation for now: center the pre-render area on the dirty rect, + // and clamp to the overflow area. Later we can do more advanced things like + // redistributing from one axis to another, or from one side to another. + nscoord xExcess = aPrerenderSize.width - aDirtyRect.width; + nscoord yExcess = aPrerenderSize.height - aDirtyRect.height; + nsRect result = aDirtyRect; + result.Inflate(xExcess / 2, yExcess / 2); + return result.MoveInsideAndClamp(aOverflow); +} + + /* static */ bool nsLayoutUtils::SupportsServoStyleBackend(nsIDocument* aDocument) { diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 0659528b1c39..e5d65f0c7859 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2875,6 +2875,19 @@ public: */ static CSSPoint GetCumulativeApzCallbackTransform(nsIFrame* aFrame); + /** + * Compute a rect to pre-render in cases where we want to render more of + * something than what is visible (usually to support async transformation). + * @param aDirtyRect the area that's visible + * @param aOverflow the total size of the thing we're rendering + * @param aPrerenderSize how large of an area we're willing to render + * @return A rectangle that includes |aDirtyRect|, is clamped to |aOverflow|, + * and is no larger than |aPrerenderSize|. + */ + static nsRect ComputePartialPrerenderArea(const nsRect& aDirtyRect, + const nsRect& aOverflow, + const nsSize& aPrerenderSize); + /* * Returns whether the given document supports being rendered with a * Servo-backed style system. This checks whether Stylo is enabled diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 9e89e000aae9..89c12f8b1ced 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -7184,20 +7184,7 @@ bool nsDisplayTransform::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder) { return mAllowAsyncAnimation; -} -static nsRect ComputePartialPrerenderArea(const nsRect& aDirtyRect, - const nsRect& aOverflow, - const nsSize& aPrerenderSize) -{ - // Simple calculation for now: center the pre-render area on the dirty rect, - // and clamp to the overflow area. Later we can do more advanced things like - // redistributing from one axis to another, or from one side to another. - nscoord xExcess = aPrerenderSize.width - aDirtyRect.width; - nscoord yExcess = aPrerenderSize.height - aDirtyRect.height; - nsRect result = aDirtyRect; - result.Inflate(xExcess / 2, yExcess / 2); - return result.MoveInsideAndClamp(aOverflow); } /* static */ auto @@ -7247,7 +7234,7 @@ nsDisplayTransform::ShouldPrerenderTransformedContent(nsDisplayListBuilder* aBui *aDirtyRect = overflow; return FullPrerender; } else if (gfxPrefs::PartiallyPrerenderAnimatedContent()) { - *aDirtyRect = ComputePartialPrerenderArea(*aDirtyRect, overflow, maxSize); + *aDirtyRect = nsLayoutUtils::ComputePartialPrerenderArea(*aDirtyRect, overflow, maxSize); return PartialPrerender; }