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:
parent
043dba039e
commit
6d20d99daa
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user