Bug 1359868 - Move the ComputePartialPrerenderArea() helper to nsLayoutUtils so it can be reused. r=mstange
authorBotond Ballo <botond@mozilla.com>
Mon, 01 May 2017 19:59:08 -0400
changeset 406362 6e2858fb7826109d65736e6a14e917fcca59addd
parent 406361 8178250f3a8b58fbb48f31b0095de2c0d2af802a
child 406363 ef01a708f156b3a9c8c9f7d46959fe61571a6692
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1359868
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1359868 - Move the ComputePartialPrerenderArea() helper to nsLayoutUtils so it can be reused. r=mstange MozReview-Commit-ID: GVRBUfYwOFP
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/painting/nsDisplayList.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -9318,16 +9318,32 @@ nsLayoutUtils::GetCumulativeApzCallbackT
     }
     frame = GetCrossDocParentFrame(frame);
     lastContent = content;
     content = frame ? frame->GetContent() : nullptr;
   }
   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)
 {
   return StyloEnabled() &&
          (aDocument->IsHTMLOrXHTML() || aDocument->IsSVGDocument()) &&
          static_cast<nsDocument*>(aDocument)->IsContentDocument();
 }
 
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2886,16 +2886,29 @@ public:
    * transforms on the content elements encountered along the way. Return the
    * accumulated value.
    * XXX: Note that this does not take into account CSS transforms, nor
    * differences in structure between the frame tree and the layer tree (which
    * is probably what we *want* to be computing).
    */
   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
    * globally, that the document is an HTML document, and that it is
    * being presented in a content docshell.
    */
   static bool SupportsServoStyleBackend(nsIDocument* aDocument);
 
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -7315,30 +7315,17 @@ nsDisplayOpacity::CanUseAsyncAnimations(
 
   return false;
 }
 
 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 void
 RecordAnimationFrameSizeTelemetry(nsIFrame* aFrame, const nsSize& overflow)
 {
   gfxSize scale = nsLayoutUtils::GetTransformToAncestorScale(aFrame);
   nsSize frameSize = nsSize(overflow.width * scale.width,
                             overflow.height * scale.height);
@@ -7401,17 +7388,17 @@ nsDisplayTransform::ShouldPrerenderTrans
   nsSize maxSize = Min(relativeLimit, absoluteLimit);
   gfxSize scale = nsLayoutUtils::GetTransformToAncestorScale(aFrame);
   nsSize frameSize = nsSize(overflow.Size().width * scale.width,
                             overflow.Size().height * scale.height);
   if (frameSize <= maxSize) {
     *aDirtyRect = overflow;
     return FullPrerender;
   } else if (gfxPrefs::PartiallyPrerenderAnimatedContent()) {
-    *aDirtyRect = ComputePartialPrerenderArea(*aDirtyRect, overflow, maxSize);
+    *aDirtyRect = nsLayoutUtils::ComputePartialPrerenderArea(*aDirtyRect, overflow, maxSize);
     return PartialPrerender;
   }
 
   EffectCompositor::SetPerformanceWarning(
     aFrame, eCSSProperty_transform,
     AnimationPerformanceWarning(
       AnimationPerformanceWarning::Type::ContentTooLarge,
       {