diff options
author | Mike Klein <mtklein@chromium.org> | 2017-04-10 09:50:25 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-20 15:02:19 +0000 |
commit | 26eb16f1e3b9c2c26042e5078636b3e5ac42b9ea (patch) | |
tree | bbc0428f4606c089e50e5b51e0d3d074774bd8cc /src/core | |
parent | 097d0939e319493765074025d2d34c4179662f7b (diff) |
calculate cull rects for SkMiniPictures
This is the other half of https://skia-review.googlesource.com/c/7874/,
adding the cull-shrinking feature of SkBigPictures to SkMiniPictures.
Like SkBigPictures, shrink only when we're asked to build an R-tree.
(We don't actually build a tree for one rect, of course.)
We could do unconditionally, but SkPictureImageFilter uses the cull rect
as its crop. It's unclear to me what this image filter unit test I've
changed here was intending... had it had two draws we would have shrunk
its cull, but because it was hitting the 1-draw SkMiniPicture path it
kept the larger user-supplied cull.
As the test doesn't appear to have been written with cull shrinking in
mind, I've removed its SkRTreeFactory to keep that feature explicitly
disabled there.
BUG=skia:5974
Change-Id: I4118d2e85f2a69adef2e7a7fa9b9b8c17607a94f
Reviewed-on: https://skia-review.googlesource.com/12624
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkMiniRecorder.cpp | 23 | ||||
-rw-r--r-- | src/core/SkPictureRecorder.cpp | 4 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/core/SkMiniRecorder.cpp b/src/core/SkMiniRecorder.cpp index 51ff5acbbc..b5d21a9efc 100644 --- a/src/core/SkMiniRecorder.cpp +++ b/src/core/SkMiniRecorder.cpp @@ -27,10 +27,27 @@ public: bool willPlayBackBitmaps() const override { return false; } }; +// Calculate conservative bounds for each type of draw op that can be its own mini picture. +// These are fairly easy because we know they can't be affected by any matrix or saveLayers. +static SkRect adjust_for_paint(SkRect bounds, const SkPaint& paint) { + return paint.canComputeFastBounds() ? paint.computeFastBounds(bounds, &bounds) + : SkRect::MakeLargest(); +} +static SkRect bounds(const DrawRect& op) { + return adjust_for_paint(op.rect, op.paint); +} +static SkRect bounds(const DrawPath& op) { + return op.path.isInverseFillType() ? SkRect::MakeLargest() + : adjust_for_paint(op.path.getBounds(), op.paint); +} +static SkRect bounds(const DrawTextBlob& op) { + return adjust_for_paint(op.blob->bounds().makeOffset(op.x, op.y), op.paint); +} + template <typename T> class SkMiniPicture final : public SkPicture { public: - SkMiniPicture(SkRect cull, T* op) : fCull(cull) { + SkMiniPicture(const SkRect* cull, T* op) : fCull(cull ? *cull : bounds(*op)) { memcpy(&fOp, op, sizeof(fOp)); // We take ownership of op's guts. } @@ -59,7 +76,7 @@ SkMiniRecorder::~SkMiniRecorder() { if (fState != State::kEmpty) { // We have internal state pending. // Detaching then deleting a picture is an easy way to clean up. - (void)this->detachAsPicture(SkRect::MakeEmpty()); + (void)this->detachAsPicture(nullptr); } SkASSERT(fState == State::kEmpty); } @@ -84,7 +101,7 @@ bool SkMiniRecorder::drawTextBlob(const SkTextBlob* b, SkScalar x, SkScalar y, c #undef TRY_TO_STORE -sk_sp<SkPicture> SkMiniRecorder::detachAsPicture(const SkRect& cull) { +sk_sp<SkPicture> SkMiniRecorder::detachAsPicture(const SkRect* cull) { #define CASE(Type) \ case State::k##Type: \ fState = State::kEmpty; \ diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index 701df7d44f..7abb12bfa7 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -56,7 +56,9 @@ sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture(uint32_t finishFlag fRecorder->restoreToCount(1); // If we were missing any restores, add them now. if (fRecord->count() == 0) { - return fMiniRecorder.detachAsPicture(fCullRect); + auto pic = fMiniRecorder.detachAsPicture(fBBH ? nullptr : &fCullRect); + fBBH.reset(nullptr); + return pic; } // TODO: delay as much of this work until just before first playback? |