calculate root bounds directly

This is a long-standing TODO.  No reason to ask
the BBH subclasses to calculate the root bounds
when we can simply union them up ourselves.

Change-Id: I9dbd883c43247400e4e9d56c74d4203d34f698e1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270276
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkBBoxHierarchy.h b/src/core/SkBBoxHierarchy.h
index 8d6f8af..fc1cd10 100644
--- a/src/core/SkBBoxHierarchy.h
+++ b/src/core/SkBBoxHierarchy.h
@@ -31,9 +31,6 @@
     virtual void search(const SkRect& query, SkTDArray<int>* results) const = 0;
 
     virtual size_t bytesUsed() const = 0;
-
-    // Get the root bound.
-    virtual SkRect getRootBound() const = 0;
 };
 
 #endif
diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp
index ea436b9..ea785e9 100644
--- a/src/core/SkPictureRecorder.cpp
+++ b/src/core/SkPictureRecorder.cpp
@@ -85,10 +85,12 @@
         bbh->insert(bounds, fRecord->count());
 
         // Now that we've calculated content bounds, we can update fCullRect, often trimming it.
-        // TODO: get updated fCullRect from bounds instead of forcing the BBH to return it?
-        SkRect bbhBound = bbh->getRootBound();
+        SkRect bbhBound = SkRect::MakeEmpty();
+        for (int i = 0; i < fRecord->count(); i++) {
+            bbhBound.join(bounds[i]);
+        }
         SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound))
-            || (bbhBound.isEmpty() && fCullRect.isEmpty()));
+              || (bbhBound.isEmpty() && fCullRect.isEmpty()));
         fCullRect = bbhBound;
     }
 
diff --git a/src/core/SkRTree.cpp b/src/core/SkRTree.cpp
index 5688350..f4a3511 100644
--- a/src/core/SkRTree.cpp
+++ b/src/core/SkRTree.cpp
@@ -9,14 +9,6 @@
 
 SkRTree::SkRTree() : fCount(0) {}
 
-SkRect SkRTree::getRootBound() const {
-    if (fCount) {
-        return fRoot.fBounds;
-    } else {
-        return SkRect::MakeEmpty();
-    }
-}
-
 void SkRTree::insert(const SkRect boundsArray[], int N) {
     SkASSERT(0 == fCount);
 
diff --git a/src/core/SkRTree.h b/src/core/SkRTree.h
index 038dd7b..735b945 100644
--- a/src/core/SkRTree.h
+++ b/src/core/SkRTree.h
@@ -43,9 +43,6 @@
     // Insertion count (not overall node count, which may be greater).
     int getCount() const { return fCount; }
 
-    // Get the root bound.
-    SkRect getRootBound() const override;
-
     // These values were empirically determined to produce reasonable performance in most cases.
     static const int kMinChildren = 6,
                      kMaxChildren = 11;
diff --git a/tests/PictureBBHTest.cpp b/tests/PictureBBHTest.cpp
index 78acda7..298f141 100644
--- a/tests/PictureBBHTest.cpp
+++ b/tests/PictureBBHTest.cpp
@@ -102,7 +102,6 @@
 
     {
         sk_sp<SkBBoxHierarchy> bbh = factory();
-        auto base = (SkBBoxHierarchy_Base*)bbh.get();
         auto canvas = recorder.beginRecording(cull, bbh);
             canvas->save();
             canvas->clipRect(cull);
@@ -112,8 +111,6 @@
         auto pic = recorder.finishRecordingAsPicture();
         REPORTER_ASSERT(r, pic->approximateOpCount() == 5);
         REPORTER_ASSERT(r, pic->cullRect() == (SkRect{-20,-20,-10,-10}));
-
-        REPORTER_ASSERT(r, base->getRootBound() == (SkRect{-20,-20,-10,-10}));
     }
 
     {
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 8274a3b..174c08d 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -468,13 +468,6 @@
     REPORTER_ASSERT(reporter, 0 == finalCullRect.fTop);
     REPORTER_ASSERT(reporter, 100 == finalCullRect.fBottom);
     REPORTER_ASSERT(reporter, 100 == finalCullRect.fRight);
-
-    auto pictureBBH = (const SkBBoxHierarchy_Base*)picture->bbh();
-    SkRect bbhCullRect = pictureBBH->getRootBound();
-    REPORTER_ASSERT(reporter, 0 == bbhCullRect.fLeft);
-    REPORTER_ASSERT(reporter, 0 == bbhCullRect.fTop);
-    REPORTER_ASSERT(reporter, 100 == bbhCullRect.fBottom);
-    REPORTER_ASSERT(reporter, 100 == bbhCullRect.fRight);
 }
 
 
@@ -668,9 +661,8 @@
 
 struct CountingBBH : public SkBBoxHierarchy_Base {
     mutable int searchCalls;
-    SkRect rootBound;
 
-    CountingBBH(const SkRect& bound) : searchCalls(0), rootBound(bound) {}
+    CountingBBH() : searchCalls(0) {}
 
     void search(const SkRect& query, SkTDArray<int>* results) const override {
         this->searchCalls++;
@@ -678,7 +670,6 @@
 
     void insert(const SkRect[], int) override {}
     virtual size_t bytesUsed() const override { return 0; }
-    SkRect getRootBound() const override { return rootBound; }
 };
 
 class SpoonFedBBHFactory : public SkBBHFactory {
@@ -695,7 +686,7 @@
 DEF_TEST(Picture_SkipBBH, r) {
     SkRect bound = SkRect::MakeWH(320, 240);
 
-    auto bbh = sk_make_sp<CountingBBH>(bound);
+    auto bbh = sk_make_sp<CountingBBH>();
     SpoonFedBBHFactory factory(bbh);
 
     SkPictureRecorder recorder;