Bug 1368386 - Make ProgressiveUpdate's aInvalidRegion parameter const to make it a bit easier to reason about. r?mattwoodrow draft
authorMarkus Stange <mstange@themasta.com>
Thu, 15 Jun 2017 17:18:37 -0400
changeset 595031 46c777d7911e8b2e91f91d31f506c3043b2dc591
parent 594149 da66c4a05fda49d457d9411a7092fed87cf9e53a
child 595032 51806cc4e056f5439a20136f55ff10dadfe64677
push id64223
push userbmo:mstange@themasta.com
push dateThu, 15 Jun 2017 22:26:05 +0000
reviewersmattwoodrow
bugs1368386
milestone56.0a1
Bug 1368386 - Make ProgressiveUpdate's aInvalidRegion parameter const to make it a bit easier to reason about. r?mattwoodrow The caller of RenderHighPrecision and RenderLowPrecision doesn't look at the variable that it passes as the aInvalidRegion parameter after the call, so any modifications that would have happened to this variable don't matter. MozReview-Commit-ID: B9PaXjZkxv2
gfx/layers/client/ClientTiledPaintedLayer.cpp
gfx/layers/client/ClientTiledPaintedLayer.h
gfx/layers/client/SingleTiledContentClient.h
gfx/layers/client/TiledContentClient.cpp
gfx/layers/client/TiledContentClient.h
--- a/gfx/layers/client/ClientTiledPaintedLayer.cpp
+++ b/gfx/layers/client/ClientTiledPaintedLayer.cpp
@@ -290,17 +290,17 @@ ClientTiledPaintedLayer::UseProgressiveD
       return false;
     }
   }
 
   return true;
 }
 
 bool
-ClientTiledPaintedLayer::RenderHighPrecision(nsIntRegion& aInvalidRegion,
+ClientTiledPaintedLayer::RenderHighPrecision(const nsIntRegion& aInvalidRegion,
                                             const nsIntRegion& aVisibleRegion,
                                             LayerManager::DrawPaintedLayerCallback aCallback,
                                             void* aCallbackData)
 {
   // If we have started drawing low-precision already, then we
   // shouldn't do anything there.
   if (mPaintData.mLowPrecisionPaintCount != 0) {
     return false;
@@ -340,21 +340,23 @@ ClientTiledPaintedLayer::RenderHighPreci
   mContentClient->GetTiledBuffer()->SetFrameResolution(mPaintData.mResolution);
   mContentClient->GetTiledBuffer()->PaintThebes(mValidRegion, aInvalidRegion, aInvalidRegion,
                                                 aCallback, aCallbackData);
   mPaintData.mPaintFinished = true;
   return true;
 }
 
 bool
-ClientTiledPaintedLayer::RenderLowPrecision(nsIntRegion& aInvalidRegion,
+ClientTiledPaintedLayer::RenderLowPrecision(const nsIntRegion& aInvalidRegion,
                                            const nsIntRegion& aVisibleRegion,
                                            LayerManager::DrawPaintedLayerCallback aCallback,
                                            void* aCallbackData)
 {
+  nsIntRegion invalidRegion = aInvalidRegion;
+
   // Render the low precision buffer, if the visible region is larger than the
   // critical display port.
   if (!mPaintData.mCriticalDisplayPort ||
       !nsIntRegion(mPaintData.mCriticalDisplayPort->ToUnknownRect()).Contains(aVisibleRegion)) {
     nsIntRegion oldValidRegion = mContentClient->GetLowPrecisionTiledBuffer()->GetValidRegion();
     oldValidRegion.And(oldValidRegion, aVisibleRegion);
 
     bool updatedBuffer = false;
@@ -364,35 +366,35 @@ ClientTiledPaintedLayer::RenderLowPrecis
         mContentClient->GetLowPrecisionTiledBuffer()->HasFormatChanged()) {
       if (!mLowPrecisionValidRegion.IsEmpty()) {
         updatedBuffer = true;
       }
       oldValidRegion.SetEmpty();
       mLowPrecisionValidRegion.SetEmpty();
       mContentClient->GetLowPrecisionTiledBuffer()->ResetPaintedAndValidState();
       mContentClient->GetLowPrecisionTiledBuffer()->SetFrameResolution(mPaintData.mResolution);
-      aInvalidRegion = aVisibleRegion;
+      invalidRegion = aVisibleRegion;
     }
 
     // Invalidate previously valid content that is no longer visible
     if (mPaintData.mLowPrecisionPaintCount == 1) {
       mLowPrecisionValidRegion.And(mLowPrecisionValidRegion, aVisibleRegion);
     }
     mPaintData.mLowPrecisionPaintCount++;
 
     // Remove the valid high-precision region from the invalid low-precision
     // region. We don't want to spend time drawing things twice.
-    aInvalidRegion.Sub(aInvalidRegion, mValidRegion);
+    invalidRegion.SubOut(mValidRegion);
 
-    TILING_LOG("TILING %p: Progressive paint: low-precision invalid region is %s\n", this, Stringify(aInvalidRegion).c_str());
+    TILING_LOG("TILING %p: Progressive paint: low-precision invalid region is %s\n", this, Stringify(invalidRegion).c_str());
     TILING_LOG("TILING %p: Progressive paint: low-precision old valid region is %s\n", this, Stringify(oldValidRegion).c_str());
 
-    if (!aInvalidRegion.IsEmpty()) {
+    if (!invalidRegion.IsEmpty()) {
       updatedBuffer = mContentClient->GetLowPrecisionTiledBuffer()->ProgressiveUpdate(
-                            mLowPrecisionValidRegion, aInvalidRegion, oldValidRegion,
+                            mLowPrecisionValidRegion, invalidRegion, oldValidRegion,
                             &mPaintData, aCallback, aCallbackData);
     }
 
     TILING_LOG("TILING %p: Progressive paint: low-precision new valid region is %s\n", this, Stringify(mLowPrecisionValidRegion).c_str());
     return updatedBuffer;
   }
   if (!mLowPrecisionValidRegion.IsEmpty()) {
     TILING_LOG("TILING %p: Clearing low-precision buffer\n", this);
--- a/gfx/layers/client/ClientTiledPaintedLayer.h
+++ b/gfx/layers/client/ClientTiledPaintedLayer.h
@@ -109,26 +109,26 @@ private:
    * is not being scrolled.
    */
   bool UseProgressiveDraw();
 
   /**
    * Helper function to do the high-precision paint.
    * This function returns true if it updated the paint buffer.
    */
-  bool RenderHighPrecision(nsIntRegion& aInvalidRegion,
+  bool RenderHighPrecision(const nsIntRegion& aInvalidRegion,
                            const nsIntRegion& aVisibleRegion,
                            LayerManager::DrawPaintedLayerCallback aCallback,
                            void* aCallbackData);
 
   /**
    * Helper function to do the low-precision paint.
    * This function returns true if it updated the paint buffer.
    */
-  bool RenderLowPrecision(nsIntRegion& aInvalidRegion,
+  bool RenderLowPrecision(const nsIntRegion& aInvalidRegion,
                           const nsIntRegion& aVisibleRegion,
                           LayerManager::DrawPaintedLayerCallback aCallback,
                           void* aCallbackData);
 
   /**
    * This causes the paint to be marked as finished, and updates any data
    * necessary to persist until the next paint.
    */
--- a/gfx/layers/client/SingleTiledContentClient.h
+++ b/gfx/layers/client/SingleTiledContentClient.h
@@ -41,17 +41,17 @@ public:
                    const nsIntRegion& aPaintRegion,
                    const nsIntRegion& aDirtyRegion,
                    LayerManager::DrawPaintedLayerCallback aCallback,
                    void* aCallbackData,
                    bool aIsProgressive = false) override;
  
   bool SupportsProgressiveUpdate() override { return false; }
   bool ProgressiveUpdate(nsIntRegion& aValidRegion,
-                         nsIntRegion& aInvalidRegion,
+                         const nsIntRegion& aInvalidRegion,
                          const nsIntRegion& aOldValidRegion,
                          BasicTiledLayerPaintData* aPaintData,
                          LayerManager::DrawPaintedLayerCallback aCallback,
                          void* aCallbackData) override
   {
     MOZ_ASSERT(false, "ProgressiveUpdate not supported!");
     return false;
   }
--- a/gfx/layers/client/TiledContentClient.cpp
+++ b/gfx/layers/client/TiledContentClient.cpp
@@ -1332,33 +1332,34 @@ ClientMultiTiledLayerBuffer::ComputeProg
   // so the paint is finished. If there's still a separate low precision
   // paint to do, it will get marked as unfinished later.
   aPaintData->mPaintFinished = true;
   return false;
 }
 
 bool
 ClientMultiTiledLayerBuffer::ProgressiveUpdate(nsIntRegion& aValidRegion,
-                                               nsIntRegion& aInvalidRegion,
+                                               const nsIntRegion& aInvalidRegion,
                                                const nsIntRegion& aOldValidRegion,
                                                BasicTiledLayerPaintData* aPaintData,
                                                LayerManager::DrawPaintedLayerCallback aCallback,
                                                void* aCallbackData)
 {
   TILING_LOG("TILING %p: Progressive update valid region %s\n", &mPaintedLayer, Stringify(aValidRegion).c_str());
   TILING_LOG("TILING %p: Progressive update invalid region %s\n", &mPaintedLayer, Stringify(aInvalidRegion).c_str());
   TILING_LOG("TILING %p: Progressive update old valid region %s\n", &mPaintedLayer, Stringify(aOldValidRegion).c_str());
 
   bool repeat = false;
   bool isBufferChanged = false;
+  nsIntRegion remainingInvalidRegion = aInvalidRegion;
   do {
     // Compute the region that should be updated. Repeat as many times as
     // is required.
     nsIntRegion regionToPaint;
-    repeat = ComputeProgressiveUpdateRegion(aInvalidRegion,
+    repeat = ComputeProgressiveUpdateRegion(remainingInvalidRegion,
                                             aOldValidRegion,
                                             regionToPaint,
                                             aPaintData,
                                             repeat);
 
     TILING_LOG("TILING %p: Progressive update computed paint region %s repeat %d\n", &mPaintedLayer, Stringify(regionToPaint).c_str(), repeat);
 
     // There's no further work to be done.
@@ -1373,23 +1374,23 @@ ClientMultiTiledLayerBuffer::Progressive
 
     // aValidRegion may have been altered by InvalidateRegion, but we still
     // want to display stale content until it gets progressively updated.
     // Create a region that includes stale content.
     nsIntRegion validOrStale;
     validOrStale.Or(aValidRegion, aOldValidRegion);
 
     // Paint the computed region and subtract it from the invalid region.
-    PaintThebes(validOrStale, regionToPaint, aInvalidRegion,
+    PaintThebes(validOrStale, regionToPaint, remainingInvalidRegion,
                 aCallback, aCallbackData, true);
-    aInvalidRegion.Sub(aInvalidRegion, regionToPaint);
+    remainingInvalidRegion.SubOut(regionToPaint);
   } while (repeat);
 
   TILING_LOG("TILING %p: Progressive update final valid region %s buffer changed %d\n", &mPaintedLayer, Stringify(aValidRegion).c_str(), isBufferChanged);
-  TILING_LOG("TILING %p: Progressive update final invalid region %s\n", &mPaintedLayer, Stringify(aInvalidRegion).c_str());
+  TILING_LOG("TILING %p: Progressive update final invalid region %s\n", &mPaintedLayer, Stringify(remainingInvalidRegion).c_str());
 
   // Return false if nothing has been drawn, or give what has been drawn
   // to the shadow layer to upload.
   return isBufferChanged;
 }
 
 void
 TiledContentClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
--- a/gfx/layers/client/TiledContentClient.h
+++ b/gfx/layers/client/TiledContentClient.h
@@ -292,17 +292,17 @@ public:
                    const nsIntRegion& aPaintRegion,
                    const nsIntRegion& aDirtyRegion,
                    LayerManager::DrawPaintedLayerCallback aCallback,
                    void* aCallbackData,
                    bool aIsProgressive = false) = 0;
 
   virtual bool SupportsProgressiveUpdate() = 0;
   virtual bool ProgressiveUpdate(nsIntRegion& aValidRegion,
-                         nsIntRegion& aInvalidRegion,
+                         const nsIntRegion& aInvalidRegion,
                          const nsIntRegion& aOldValidRegion,
                          BasicTiledLayerPaintData* aPaintData,
                          LayerManager::DrawPaintedLayerCallback aCallback,
                          void* aCallbackData) = 0;
   virtual void ResetPaintedAndValidState() = 0;
 
   virtual const nsIntRegion& GetValidRegion() = 0;
 
@@ -351,17 +351,17 @@ public:
                    bool aIsProgressive = false) override;
 
   virtual bool SupportsProgressiveUpdate() override { return true; }
   /**
    * Performs a progressive update of a given tiled buffer.
    * See ComputeProgressiveUpdateRegion below for parameter documentation.
    */
   bool ProgressiveUpdate(nsIntRegion& aValidRegion,
-                         nsIntRegion& aInvalidRegion,
+                         const nsIntRegion& aInvalidRegion,
                          const nsIntRegion& aOldValidRegion,
                          BasicTiledLayerPaintData* aPaintData,
                          LayerManager::DrawPaintedLayerCallback aCallback,
                          void* aCallbackData) override;
   
   void ResetPaintedAndValidState() override {
     mPaintedRegion.SetEmpty();
     mValidRegion.SetEmpty();