Make GrOp base class responsible for merging bounds.

Change-Id: If85c00554f46c9601ca3fc3ef95bbf7c5bc81dc0
Reviewed-on: https://skia-review.googlesource.com/c/164686
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/ccpr/GrCCDrawPathsOp.cpp b/src/gpu/ccpr/GrCCDrawPathsOp.cpp
index 4b3780d..3787971 100644
--- a/src/gpu/ccpr/GrCCDrawPathsOp.cpp
+++ b/src/gpu/ccpr/GrCCDrawPathsOp.cpp
@@ -216,7 +216,6 @@
     }
 
     fDraws.append(std::move(that->fDraws), &fOwningPerOpListPaths->fAllocator);
-    this->joinBounds(*that);
 
     SkDEBUGCODE(fNumDraws += that->fNumDraws);
     SkDEBUGCODE(that->fNumDraws = 0);
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index ac2f6d6..68b8b8e 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -961,7 +961,6 @@
         }
 
         fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrAAFillRectOp.cpp b/src/gpu/ops/GrAAFillRectOp.cpp
index 120f714..f1987a7 100644
--- a/src/gpu/ops/GrAAFillRectOp.cpp
+++ b/src/gpu/ops/GrAAFillRectOp.cpp
@@ -302,7 +302,6 @@
 
         fRectData.push_back_n(that->fRectData.count(), that->fRectData.begin());
         fRectCnt += that->fRectCnt;
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index 50bc406..c59d53f 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -882,7 +882,6 @@
         }
 
         fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index 4029b3d..1ecceb1 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -325,7 +325,6 @@
         }
 
         fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrAAStrokeRectOp.cpp b/src/gpu/ops/GrAAStrokeRectOp.cpp
index 248f502..625635e 100644
--- a/src/gpu/ops/GrAAStrokeRectOp.cpp
+++ b/src/gpu/ops/GrAAStrokeRectOp.cpp
@@ -424,7 +424,6 @@
     }
 
     fRects.push_back_n(that->fRects.count(), that->fRects.begin());
-    this->joinBounds(*that);
     return CombineResult::kMerged;
 }
 
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index b616c29..7c14c6c 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -517,7 +517,6 @@
     that->fGeoCount = 0;
     fGeoCount = newGeoCount;
 
-    this->joinBounds(*that);
     return CombineResult::kMerged;
 }
 
diff --git a/src/gpu/ops/GrClearOp.h b/src/gpu/ops/GrClearOp.h
index e62667d..7e19d61 100644
--- a/src/gpu/ops/GrClearOp.h
+++ b/src/gpu/ops/GrClearOp.h
@@ -72,7 +72,6 @@
         }
         if (cb->contains(this)) {
             fClip = cb->fClip;
-            this->replaceBounds(*t);
             fColor = cb->fColor;
             return CombineResult::kMerged;
         } else if (cb->fColor == fColor && this->contains(cb)) {
diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp
index 08ca0f0..2a36607 100644
--- a/src/gpu/ops/GrDashOp.cpp
+++ b/src/gpu/ops/GrDashOp.cpp
@@ -731,7 +731,6 @@
         }
 
         fLines.push_back_n(that->fLines.count(), that->fLines.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp
index a653941..0bff89c 100644
--- a/src/gpu/ops/GrDefaultPathRenderer.cpp
+++ b/src/gpu/ops/GrDefaultPathRenderer.cpp
@@ -462,7 +462,6 @@
         }
 
         fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrDrawAtlasOp.cpp b/src/gpu/ops/GrDrawAtlasOp.cpp
index 107b0be..c4b44aa 100644
--- a/src/gpu/ops/GrDrawAtlasOp.cpp
+++ b/src/gpu/ops/GrDrawAtlasOp.cpp
@@ -173,7 +173,6 @@
     fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin());
     fQuadCount += that->quadCount();
 
-    this->joinBounds(*that);
     return CombineResult::kMerged;
 }
 
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index b4aa619..da8eb3a 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -539,7 +539,6 @@
     fVertexCount += that->fVertexCount;
     fIndexCount += that->fIndexCount;
 
-    this->joinBounds(*that);
     return CombineResult::kMerged;
 }
 
diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp
index 6d7345b..79a9062 100644
--- a/src/gpu/ops/GrLatticeOp.cpp
+++ b/src/gpu/ops/GrLatticeOp.cpp
@@ -306,7 +306,6 @@
         }
 
         fPatches.move_back_n(that->fPatches.count(), that->fPatches.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrNonAAFillRectOp.cpp b/src/gpu/ops/GrNonAAFillRectOp.cpp
index 9e5a8e2..b8b4a73 100644
--- a/src/gpu/ops/GrNonAAFillRectOp.cpp
+++ b/src/gpu/ops/GrNonAAFillRectOp.cpp
@@ -216,7 +216,6 @@
             return CombineResult::kCannotCombine;
         }
         fRects.push_back_n(that->fRects.count(), that->fRects.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
@@ -366,7 +365,6 @@
         }
 
         fRects.push_back_n(that->fRects.count(), that->fRects.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrOp.cpp b/src/gpu/ops/GrOp.cpp
index d6420af..2d591bd 100644
--- a/src/gpu/ops/GrOp.cpp
+++ b/src/gpu/ops/GrOp.cpp
@@ -41,8 +41,11 @@
     auto result = this->onCombineIfPossible(that, caps);
     // Merging a chained 'that' would cause problems given the way op lists currently manage chains.
     SkASSERT(!(thatWasChained && result == CombineResult::kMerged));
-    if (fChainHead && result == CombineResult::kMerged) {
-        fChainHead->joinBounds(*that);
+    if (result == CombineResult::kMerged) {
+        this->joinBounds(*that);
+        if (fChainHead) {
+            fChainHead->joinBounds(*that);
+        }
     }
     return result;
 }
diff --git a/src/gpu/ops/GrOp.h b/src/gpu/ops/GrOp.h
index c8f7157..e7dea06 100644
--- a/src/gpu/ops/GrOp.h
+++ b/src/gpu/ops/GrOp.h
@@ -264,6 +264,9 @@
                         HasAABloat::kNo, IsZeroArea::kNo);
     }
 
+    static uint32_t GenOpClassID() { return GenID(&gCurrOpClassID); }
+
+private:
     void joinBounds(const GrOp& that) {
         if (that.hasAABloat()) {
             fBoundsFlags |= kAABloat_BoundsFlag;
@@ -274,14 +277,6 @@
         return fBounds.joinPossiblyEmptyRect(that.fBounds);
     }
 
-    void replaceBounds(const GrOp& that) {
-        fBounds = that.fBounds;
-        fBoundsFlags = that.fBoundsFlags;
-    }
-
-    static uint32_t GenOpClassID() { return GenID(&gCurrOpClassID); }
-
-private:
     virtual CombineResult onCombineIfPossible(GrOp*, const GrCaps&) {
         return CombineResult::kCannotCombine;
     }
diff --git a/src/gpu/ops/GrOvalOpFactory.cpp b/src/gpu/ops/GrOvalOpFactory.cpp
index d8809b0..6df0cb4 100644
--- a/src/gpu/ops/GrOvalOpFactory.cpp
+++ b/src/gpu/ops/GrOvalOpFactory.cpp
@@ -1519,7 +1519,6 @@
         fRoundCaps |= that->fRoundCaps;
 
         fCircles.push_back_n(that->fCircles.count(), that->fCircles.begin());
-        this->joinBounds(*that);
         fVertCount += that->fVertCount;
         fIndexCount += that->fIndexCount;
         fAllFill = fAllFill && that->fAllFill;
@@ -1830,7 +1829,6 @@
         }
 
         fCircles.push_back_n(that->fCircles.count(), that->fCircles.begin());
-        this->joinBounds(*that);
         fVertCount += that->fVertCount;
         fIndexCount += that->fIndexCount;
         return CombineResult::kMerged;
@@ -2077,7 +2075,6 @@
         }
 
         fEllipses.push_back_n(that->fEllipses.count(), that->fEllipses.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
@@ -2309,7 +2306,6 @@
         }
 
         fEllipses.push_back_n(that->fEllipses.count(), that->fEllipses.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
@@ -2767,7 +2763,6 @@
         }
 
         fRRects.push_back_n(that->fRRects.count(), that->fRRects.begin());
-        this->joinBounds(*that);
         fVertCount += that->fVertCount;
         fIndexCount += that->fIndexCount;
         fAllFill = fAllFill && that->fAllFill;
@@ -3033,7 +3028,6 @@
         }
 
         fRRects.push_back_n(that->fRRects.count(), that->fRRects.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrRegionOp.cpp b/src/gpu/ops/GrRegionOp.cpp
index f78fa94..0ba2a27 100644
--- a/src/gpu/ops/GrRegionOp.cpp
+++ b/src/gpu/ops/GrRegionOp.cpp
@@ -158,7 +158,6 @@
         }
 
         fRegions.push_back_n(that->fRegions.count(), that->fRegions.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp
index 0a7d191..d92f2a3 100644
--- a/src/gpu/ops/GrShadowRRectOp.cpp
+++ b/src/gpu/ops/GrShadowRRectOp.cpp
@@ -601,7 +601,6 @@
     CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
         ShadowCircularRRectOp* that = t->cast<ShadowCircularRRectOp>();
         fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin());
-        this->joinBounds(*that);
         fVertCount += that->fVertCount;
         fIndexCount += that->fIndexCount;
         return CombineResult::kMerged;
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index 9ade557..d771972 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -883,7 +883,6 @@
         }
 
         fShapes.push_back_n(that->fShapes.count(), that->fShapes.begin());
-        this->joinBounds(*that);
         return CombineResult::kMerged;
     }
 
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index 59170e0..5660699 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -1012,7 +1012,6 @@
         }
         fProxies[0].fQuadCnt += that->fQuads.count();
         fQuads.push_back_n(that->fQuads.count(), that->fQuads.begin());
-        this->joinBounds(*that);
         fPerspective |= that->fPerspective;
         fDomain |= that->fDomain;
         if (upgradeToCoverageAAOnMerge) {