test we already have SkPicture::drawsNothing()

I was about to add a new call here, but for users like Flutter that are
using an R-tree, we may already have a precise drawsNothing() call.

There are a couple simple specializations of SkPicture, but they'll
already return the right answer:

   - an SkEmptyPicture will return empty bounds
   - a single-draw SkMiniPicture will return the bounds of that draw

That leaves the general SkBigPicture case.  With an R-tree we'll
calculate the bounds of every draw in the picture, unioning them up into
the cullRect() of the picture itself.

So cullRect().isEmpty() should mostly just work as drawsNothing()
already?

Bug: skia:9411
Change-Id: I5e5dfc21cb7c5c77d173ebee2e91e7bef880367b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/240973
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2019-09-12 12:51:27 -05:00 committed by Skia Commit-Bot
parent 043dba039e
commit 6d20d99daa

View File

@ -879,3 +879,33 @@ DEF_TEST(Picture_empty_serial, reporter) {
REPORTER_ASSERT(reporter, pic2);
}
DEF_TEST(Picture_drawsNothing, r) {
// Tests that pic->cullRect().isEmpty() is a good way to test a picture
// recorded with an R-tree draws nothing.
struct {
bool draws_nothing;
void (*fn)(SkCanvas*);
} cases[] = {
{ true, [](SkCanvas* c) { } },
{ true, [](SkCanvas* c) { c->save(); c->restore(); } },
{ true, [](SkCanvas* c) { c->save(); c->clipRect({0,0,5,5}); c->restore(); } },
{ true, [](SkCanvas* c) { c->clipRect({0,0,5,5}); } },
{ false, [](SkCanvas* c) { c->drawRect({0,0,5,5}, SkPaint{}); } },
{ false, [](SkCanvas* c) { c->save(); c->drawRect({0,0,5,5}, SkPaint{}); c->restore(); } },
{ false, [](SkCanvas* c) {
c->drawRect({0,0, 5, 5}, SkPaint{});
c->drawRect({5,5,10,10}, SkPaint{});
}},
};
for (const auto& c : cases) {
SkPictureRecorder rec;
SkRTreeFactory factory;
c.fn(rec.beginRecording(10,10, &factory));
sk_sp<SkPicture> pic = rec.finishRecordingAsPicture();
REPORTER_ASSERT(r, pic->cullRect().isEmpty() == c.draws_nothing);
}
}