Bug 1412272 - Have ComputePartialPrerenderArea() handle the cases where aDirtyRect is larger than aPrerenderSize. r=mstange draft
authorBotond Ballo <botond@mozilla.com>
Wed, 01 Nov 2017 15:27:16 -0400
changeset 690247 b04aedafa8432004a716f0cb4b4c5dc6c418dfda
parent 690034 cd7217cf05a2332a8fd7b498767a07b2c31ea657
child 738527 16d38ac85ec655c092a1182485023d393e322456
push id87250
push userbballo@mozilla.com
push dateWed, 01 Nov 2017 19:30:33 +0000
reviewersmstange
bugs1412272
milestone58.0a1
Bug 1412272 - Have ComputePartialPrerenderArea() handle the cases where aDirtyRect is larger than aPrerenderSize. r=mstange Rendering at least aDirtyRect is more important than staying under aPrerenderSize, so that's what we do. MozReview-Commit-ID: 8Ze1biaNzqX
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9802,18 +9802,18 @@ nsLayoutUtils::GetCumulativeApzCallbackT
 /* 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;
+  nscoord xExcess = std::max(aPrerenderSize.width - aDirtyRect.width, 0);
+  nscoord yExcess = std::max(aPrerenderSize.height - aDirtyRect.height, 0);
   nsRect result = aDirtyRect;
   result.Inflate(xExcess / 2, yExcess / 2);
   return result.MoveInsideAndClamp(aOverflow);
 }
 
 static
 bool
 LineHasNonEmptyContentWorker(nsIFrame* aFrame)
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -3039,17 +3039,20 @@ public:
 
   /**
    * 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|.
+   *         and is no larger than |aPrerenderSize| (unless |aPrerenderSize|
+   *         is smaller than |aDirtyRect|, in which case the returned rect
+   *         will still include |aDirtyRect| and thus be larger than
+   *         |aPrerenderSize|).
    */
   static nsRect ComputePartialPrerenderArea(const nsRect& aDirtyRect,
                                             const nsRect& aOverflow,
                                             const nsSize& aPrerenderSize);
 
   /*
    * Checks whether a node is an invisible break.
    * If not, returns the first frame on the next line if such a next line exists.