diff options
author | Mike Reed <reed@google.com> | 2017-12-24 19:50:57 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-25 02:51:32 +0000 |
commit | 7557bbbe19b0d56484fe039171e4d97b75f209b3 (patch) | |
tree | 8d88d739a1f97553bff2e0ac029f8693e6eed108 /src/core | |
parent | 0a9d728851aaef71355b397ac03c1ddcb9e4bf06 (diff) |
Revert "remove approxbytes api from SkPicture"
This reverts commit bfc11853a88cda6951ae97399577fadadf2adcd5.
Bug: skia:
Change-Id: Ied4baad0496a06a52bec6965f9c97e13ebe2ab0a
Reviewed-on: https://skia-review.googlesource.com/89442
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBigPicture.cpp | 11 | ||||
-rw-r--r-- | src/core/SkBigPicture.h | 5 | ||||
-rw-r--r-- | src/core/SkMiniRecorder.cpp | 2 | ||||
-rw-r--r-- | src/core/SkPictureRecorder.cpp | 7 | ||||
-rw-r--r-- | src/core/SkRecordedDrawable.cpp | 7 | ||||
-rw-r--r-- | src/core/SkRecorder.cpp | 1 |
6 files changed, 28 insertions, 5 deletions
diff --git a/src/core/SkBigPicture.cpp b/src/core/SkBigPicture.cpp index 62f54e08bb..2ae9248d47 100644 --- a/src/core/SkBigPicture.cpp +++ b/src/core/SkBigPicture.cpp @@ -15,8 +15,10 @@ SkBigPicture::SkBigPicture(const SkRect& cull, SkRecord* record, SnapshotArray* drawablePicts, - SkBBoxHierarchy* bbh) + SkBBoxHierarchy* bbh, + size_t approxBytesUsedBySubPictures) : fCullRect(cull) + , fApproxBytesUsedBySubPictures(approxBytesUsedBySubPictures) , fRecord(record) // Take ownership of caller's ref. , fDrawablePicts(drawablePicts) // Take ownership. , fBBH(bbh) // Take ownership of caller's ref. @@ -52,7 +54,12 @@ void SkBigPicture::partialPlayback(SkCanvas* canvas, } SkRect SkBigPicture::cullRect() const { return fCullRect; } -int SkBigPicture::approximateOpCount() const { return fRecord->count(); } +int SkBigPicture::approximateOpCount() const { return fRecord->count(); } +size_t SkBigPicture::approximateBytesUsed() const { + size_t bytes = sizeof(*this) + fRecord->bytesUsed() + fApproxBytesUsedBySubPictures; + if (fBBH) { bytes += fBBH->bytesUsed(); } + return bytes; +} int SkBigPicture::drawableCount() const { return fDrawablePicts ? fDrawablePicts->count() : 0; diff --git a/src/core/SkBigPicture.h b/src/core/SkBigPicture.h index 6edf4004c1..cbe492cc22 100644 --- a/src/core/SkBigPicture.h +++ b/src/core/SkBigPicture.h @@ -36,13 +36,15 @@ public: SkBigPicture(const SkRect& cull, SkRecord*, // We take ownership of the caller's ref. SnapshotArray*, // We take exclusive ownership. - SkBBoxHierarchy*); // We take ownership of the caller's ref. + SkBBoxHierarchy*, // We take ownership of the caller's ref. + size_t approxBytesUsedBySubPictures); // SkPicture overrides void playback(SkCanvas*, AbortCallback*) const override; SkRect cullRect() const override; int approximateOpCount() const override; + size_t approximateBytesUsed() const override; const SkBigPicture* asSkBigPicture() const override { return this; } // Used by GrLayerHoister @@ -59,6 +61,7 @@ private: SkPicture const* const* drawablePicts() const; const SkRect fCullRect; + const size_t fApproxBytesUsedBySubPictures; sk_sp<const SkRecord> fRecord; std::unique_ptr<const SnapshotArray> fDrawablePicts; sk_sp<const SkBBoxHierarchy> fBBH; diff --git a/src/core/SkMiniRecorder.cpp b/src/core/SkMiniRecorder.cpp index deda976bd0..ec089373e1 100644 --- a/src/core/SkMiniRecorder.cpp +++ b/src/core/SkMiniRecorder.cpp @@ -20,6 +20,7 @@ class SkEmptyPicture final : public SkPicture { public: void playback(SkCanvas*, AbortCallback*) const override { } + size_t approximateBytesUsed() const override { return sizeof(*this); } int approximateOpCount() const override { return 0; } SkRect cullRect() const override { return SkRect::MakeEmpty(); } }; @@ -52,6 +53,7 @@ public: SkRecords::Draw(c, nullptr, nullptr, 0, nullptr)(fOp); } + size_t approximateBytesUsed() const override { return sizeof(*this); } int approximateOpCount() const override { return 1; } SkRect cullRect() const override { return fCull; } diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index 6c23cc075e..a37cd4826c 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -83,7 +83,12 @@ sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPicture(uint32_t finishFlag fCullRect = bbhBound; } - return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH.release()); + size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); + for (int i = 0; pictList && i < pictList->count(); i++) { + subPictureBytes += pictList->begin()[i]->approximateBytesUsed(); + } + return sk_make_sp<SkBigPicture>(fCullRect, fRecord.release(), pictList, fBBH.release(), + subPictureBytes); } sk_sp<SkPicture> SkPictureRecorder::finishRecordingAsPictureWithCull(const SkRect& cullRect, diff --git a/src/core/SkRecordedDrawable.cpp b/src/core/SkRecordedDrawable.cpp index bb57885d5d..342701a365 100644 --- a/src/core/SkRecordedDrawable.cpp +++ b/src/core/SkRecordedDrawable.cpp @@ -31,9 +31,14 @@ SkPicture* SkRecordedDrawable::onNewPictureSnapshot() { pictList = fDrawableList->newDrawableSnapshot(); } + size_t subPictureBytes = 0; + for (int i = 0; pictList && i < pictList->count(); i++) { + subPictureBytes += pictList->begin()[i]->approximateBytesUsed(); + } // SkBigPicture will take ownership of a ref on both fRecord and fBBH. // We're not willing to give up our ownership, so we must ref them for SkPicture. - return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get())); + return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeRef(fBBH.get()), + subPictureBytes); } void SkRecordedDrawable::flatten(SkWriteBuffer& buffer) const { diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 26fcaa4af4..9374b60264 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -302,6 +302,7 @@ void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, const SkPaint* paint) { if (fDrawPictureMode == Record_DrawPictureMode) { + fApproxBytesUsedBySubPictures += pic->approximateBytesUsed(); APPEND(DrawPicture, this->copy(paint), sk_ref_sp(pic), matrix ? *matrix : SkMatrix::I()); } else { SkASSERT(fDrawPictureMode == Playback_DrawPictureMode); |