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>
This commit is contained in:
parent
55b137ca7d
commit
e1bad065be
@ -31,9 +31,6 @@ public:
|
||||
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
|
||||
|
@ -85,10 +85,12 @@ sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture(uint32_t finishFlag
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -43,9 +43,6 @@ public:
|
||||
// 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;
|
||||
|
@ -102,7 +102,6 @@ DEF_TEST(PictureNegativeSpace, r) {
|
||||
|
||||
{
|
||||
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 @@ DEF_TEST(PictureNegativeSpace, r) {
|
||||
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}));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -468,13 +468,6 @@ static void test_cull_rect_reset(skiatest::Reporter* reporter) {
|
||||
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 @@ DEF_TEST(DontOptimizeSaveLayerDrawDrawRestore, reporter) {
|
||||
|
||||
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 @@ struct CountingBBH : public SkBBoxHierarchy_Base {
|
||||
|
||||
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 @@ private:
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user