From 5a246bb48708cfdbf5b63f8df7e2b09b3704cae4 Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 14 Aug 2014 19:17:18 -0700 Subject: [PATCH] int SkPicture::approximateOpCount() NOTREECHECKS=true BUG=skia: R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/470333002 --- include/core/SkPicture.h | 7 +++++++ src/core/SkPicture.cpp | 12 ++++++++++++ src/core/SkPictureData.h | 4 +++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index 1e8b364145..2a89277f5e 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -197,6 +197,13 @@ public: // Takes ref on listener. void addDeletionListener(DeletionListener* listener) const; + /** Return the approximate number of operations in this picture. This + * number may be greater or less than the number of SkCanvas calls + * recorded: some calls may be recorded as more than one operation, or some + * calls may be optimized away. + */ + int approximateOpCount() const; + private: // V2 : adds SkPixelRef's generation ID. // V3 : PictInfo tag at beginning, and EOF tag at the end diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index fa4c103d5c..ab00000de4 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -455,3 +455,15 @@ void SkPicture::callDeletionListeners() { fDeletionListeners.unrefAll(); } + +// fRecord OK +int SkPicture::approximateOpCount() const { + SkASSERT(fRecord.get() || fData.get()); + if (fRecord.get()) { + return fRecord->count(); + } + if (fData.get()) { + return fData->opCount(); + } + return 0; +} diff --git a/src/core/SkPictureData.h b/src/core/SkPictureData.h index 3e3ab59a44..df898cf9f2 100644 --- a/src/core/SkPictureData.h +++ b/src/core/SkPictureData.h @@ -89,6 +89,8 @@ public: bool containsBitmaps() const; + int opCount() const { return fContentInfo.numOperations(); } + const SkData* opData() const { return fOpData; } protected: @@ -128,7 +130,7 @@ public: return &(*fPaints)[index - 1]; } - void initIterator(SkPictureStateTree::Iterator* iter, + void initIterator(SkPictureStateTree::Iterator* iter, const SkTDArray& draws, SkCanvas* canvas) const { if (NULL != fStateTree) {