Bug 1023882 - Part 3 - Extract a RenderHighPrecision helper function. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 11 Jun 2014 12:42:45 -0400
changeset 207199 f2a65256e3cb6810fbbe44b94681f37285e1e1ba
parent 207198 d02aae5cb847f4c1909fa3d4aeffe5652c239281
child 207200 8ed48f1320b86952bdd4a8a5ea3e95943d19d69f
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis
bugs1023882
milestone32.0a2
Bug 1023882 - Part 3 - Extract a RenderHighPrecision helper function. r=Cwiiis
gfx/layers/client/ClientTiledThebesLayer.cpp
gfx/layers/client/ClientTiledThebesLayer.h
--- a/gfx/layers/client/ClientTiledThebesLayer.cpp
+++ b/gfx/layers/client/ClientTiledThebesLayer.cpp
@@ -187,16 +187,61 @@ ClientTiledThebesLayer::UseFastPath()
   const FrameMetrics& parentMetrics = GetParent()->GetFrameMetrics();
   bool multipleTransactionsNeeded = gfxPrefs::UseProgressiveTilePainting()
                                  || gfxPrefs::UseLowPrecisionBuffer()
                                  || !parentMetrics.mCriticalDisplayPort.IsEmpty();
   bool isFixed = GetIsFixedPosition() || GetParent()->GetIsFixedPosition();
   return !multipleTransactionsNeeded || isFixed || parentMetrics.mDisplayPort.IsEmpty();
 }
 
+bool
+ClientTiledThebesLayer::RenderHighPrecision(nsIntRegion& aInvalidRegion,
+                                            LayerManager::DrawThebesLayerCallback aCallback,
+                                            void* aCallbackData)
+{
+  // If we have no high-precision stuff to draw, or we have started drawing low-precision
+  // already, then we shouldn't do anything there.
+  if (aInvalidRegion.IsEmpty() || mPaintData.mLowPrecisionPaintCount != 0) {
+    return false;
+  }
+
+  // Only draw progressively when the resolution is unchanged.
+  if (gfxPrefs::UseProgressiveTilePainting() &&
+      !ClientManager()->HasShadowTarget() &&
+      mContentClient->mTiledBuffer.GetFrameResolution() == mPaintData.mResolution) {
+    // Store the old valid region, then clear it before painting.
+    // We clip the old valid region to the visible region, as it only gets
+    // used to decide stale content (currently valid and previously visible)
+    nsIntRegion oldValidRegion = mContentClient->mTiledBuffer.GetValidRegion();
+    oldValidRegion.And(oldValidRegion, mVisibleRegion);
+    if (!mPaintData.mCriticalDisplayPort.IsEmpty()) {
+      oldValidRegion.And(oldValidRegion, LayerIntRect::ToUntyped(mPaintData.mCriticalDisplayPort));
+    }
+
+    TILING_PRLOG_OBJ(("TILING 0x%p: Progressive update with old valid region %s\n", this, tmpstr.get()), oldValidRegion);
+
+    return mContentClient->mTiledBuffer.ProgressiveUpdate(mValidRegion, aInvalidRegion,
+                      oldValidRegion, &mPaintData, aCallback, aCallbackData);
+  }
+
+  // Otherwise do a non-progressive paint
+
+  mValidRegion = mVisibleRegion;
+  if (!mPaintData.mCriticalDisplayPort.IsEmpty()) {
+    mValidRegion.And(mValidRegion, LayerIntRect::ToUntyped(mPaintData.mCriticalDisplayPort));
+  }
+
+  TILING_PRLOG_OBJ(("TILING 0x%p: Non-progressive paint invalid region %s\n", this, tmpstr.get()), aInvalidRegion);
+  TILING_PRLOG_OBJ(("TILING 0x%p: Non-progressive paint new valid region %s\n", this, tmpstr.get()), mValidRegion);
+
+  mContentClient->mTiledBuffer.SetFrameResolution(mPaintData.mResolution);
+  mContentClient->mTiledBuffer.PaintThebes(mValidRegion, aInvalidRegion, aCallback, aCallbackData);
+  return true;
+}
+
 void
 ClientTiledThebesLayer::EndPaint(bool aFinish)
 {
   if (!aFinish && !mPaintData.mPaintFinished) {
     return;
   }
 
   mPaintData.mLastScrollOffset = mPaintData.mScrollOffset;
@@ -290,69 +335,33 @@ ClientTiledThebesLayer::RenderLayer()
     if (invalidRegion.IsEmpty() && lowPrecisionInvalidRegion.IsEmpty()) {
       EndPaint(true);
       return;
     }
   }
 
   TILING_PRLOG_OBJ(("TILING 0x%p: Invalid region %s\n", this, tmpstr.get()), invalidRegion);
 
-  if (!invalidRegion.IsEmpty() && mPaintData.mLowPrecisionPaintCount == 0) {
-    bool updatedBuffer = false;
-    // Only draw progressively when the resolution is unchanged.
-    if (gfxPrefs::UseProgressiveTilePainting() &&
-        !ClientManager()->HasShadowTarget() &&
-        mContentClient->mTiledBuffer.GetFrameResolution() == mPaintData.mResolution) {
-      // Store the old valid region, then clear it before painting.
-      // We clip the old valid region to the visible region, as it only gets
-      // used to decide stale content (currently valid and previously visible)
-      nsIntRegion oldValidRegion = mContentClient->mTiledBuffer.GetValidRegion();
-      oldValidRegion.And(oldValidRegion, mVisibleRegion);
-      if (!mPaintData.mCriticalDisplayPort.IsEmpty()) {
-        oldValidRegion.And(oldValidRegion, LayerIntRect::ToUntyped(mPaintData.mCriticalDisplayPort));
-      }
-
-      TILING_PRLOG_OBJ(("TILING 0x%p: Progressive update with old valid region %s\n", this, tmpstr.get()), oldValidRegion);
+  bool updatedHighPrecision = RenderHighPrecision(invalidRegion, callback, data);
+  if (updatedHighPrecision) {
+    ClientManager()->Hold(this);
+    mContentClient->UseTiledLayerBuffer(TiledContentClient::TILED_BUFFER);
 
-      updatedBuffer =
-        mContentClient->mTiledBuffer.ProgressiveUpdate(mValidRegion, invalidRegion,
-                                                       oldValidRegion, &mPaintData,
-                                                       callback, data);
-    } else {
-      updatedBuffer = true;
-      mValidRegion = mVisibleRegion;
-      if (!mPaintData.mCriticalDisplayPort.IsEmpty()) {
-        mValidRegion.And(mValidRegion, LayerIntRect::ToUntyped(mPaintData.mCriticalDisplayPort));
-      }
-
-      TILING_PRLOG_OBJ(("TILING 0x%p: Painting: valid region %s\n", this, tmpstr.get()), mValidRegion);
-      TILING_PRLOG_OBJ(("TILING 0x%p: and invalid region %s\n", this, tmpstr.get()), invalidRegion);
-
-      mContentClient->mTiledBuffer.SetFrameResolution(mPaintData.mResolution);
-      mContentClient->mTiledBuffer.PaintThebes(mValidRegion, invalidRegion,
-                                               callback, data);
+    // If there are low precision updates, mark the paint as unfinished and
+    // request a repeat transaction.
+    if (!lowPrecisionInvalidRegion.IsEmpty() && mPaintData.mPaintFinished) {
+      ClientManager()->SetRepeatTransaction();
+      mPaintData.mLowPrecisionPaintCount = 1;
+      mPaintData.mPaintFinished = false;
     }
 
-    if (updatedBuffer) {
-      ClientManager()->Hold(this);
-      mContentClient->UseTiledLayerBuffer(TiledContentClient::TILED_BUFFER);
-
-      // If there are low precision updates, mark the paint as unfinished and
-      // request a repeat transaction.
-      if (!lowPrecisionInvalidRegion.IsEmpty() && mPaintData.mPaintFinished) {
-        ClientManager()->SetRepeatTransaction();
-        mPaintData.mLowPrecisionPaintCount = 1;
-        mPaintData.mPaintFinished = false;
-      }
-
-      // Return so that low precision updates aren't performed in the same
-      // transaction as high-precision updates.
-      EndPaint(false);
-      return;
-    }
+    // Return so that low precision updates aren't performed in the same
+    // transaction as high-precision updates.
+    EndPaint(false);
+    return;
   }
 
   TILING_PRLOG_OBJ(("TILING 0x%p: Low-precision valid region is %s\n", this, tmpstr.get()), mLowPrecisionValidRegion);
   TILING_PRLOG_OBJ(("TILING 0x%p: Low-precision invalid region is %s\n", this, tmpstr.get()), lowPrecisionInvalidRegion);
 
   // Render the low precision buffer, if there's area to invalidate and the
   // visible region is larger than the critical display port.
   bool updatedLowPrecision = false;
--- a/gfx/layers/client/ClientTiledThebesLayer.h
+++ b/gfx/layers/client/ClientTiledThebesLayer.h
@@ -83,16 +83,24 @@ private:
 
   /**
    * Determine if we can use a fast path to just do a single high-precision,
    * non-progressive paint.
    */
   bool UseFastPath();
 
   /**
+   * Helper functions to do the high-precision paint.
+   * This function returns true if it updated the paint buffer.
+   */
+  bool RenderHighPrecision(nsIntRegion& aInvalidRegion,
+                           LayerManager::DrawThebesLayerCallback aCallback,
+                           void* aCallbackData);
+
+  /**
    * When a paint ends, updates any data necessary to persist until the next
    * paint. If aFinish is true, this will cause the paint to be marked as
    * finished.
    */
   void EndPaint(bool aFinish);
 
   RefPtr<TiledContentClient> mContentClient;
   nsIntRegion mLowPrecisionValidRegion;