Index: src/utils/SkPictureUtils.cpp |
diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp |
index dfa772a2da5be93e24bc645608c41052218f6822..462161fd50d65c01b4812472935741a30016a17e 100644 |
--- a/src/utils/SkPictureUtils.cpp |
+++ b/src/utils/SkPictureUtils.cpp |
@@ -5,6 +5,7 @@ |
* found in the LICENSE file. |
*/ |
+#include "SkBBoxHierarchy.h" |
#include "SkBitmapDevice.h" |
#include "SkCanvas.h" |
#include "SkData.h" |
@@ -12,6 +13,7 @@ |
#include "SkPictureUtils.h" |
#include "SkPixelRef.h" |
#include "SkRRect.h" |
+#include "SkRecord.h" |
#include "SkShader.h" |
class PixelRefSet { |
@@ -215,3 +217,41 @@ SkData* SkPictureUtils::GatherPixelRefs(const SkPicture* pict, const SkRect& are |
} |
return data; |
} |
+ |
+class MeasureRecords : SkNoncopyable { |
+public: |
+ MeasureRecords() : fSize(0) { } |
+ |
+ template <typename T> void operator()(const T& op) { |
mtklein
2014/11/18 21:38:32
Maybe just this?
struct MeasureRecords {
templa
mtklein
2014/11/18 21:46:23
Oh, sadly I think you have to do
MeasureRecords v
tomhudson
2014/11/18 21:49:37
Acknowledged. (I think you posted this at the same
|
+ this->measure(op); |
+ } |
+ |
+ size_t measuredSize() const { return fSize; } |
+private: |
+ void measure(const SkRecords::DrawPicture& p) { |
+ this->fSize += SkPictureUtils::ApproximateBytesUsed(p.picture); |
mtklein
2014/11/18 21:38:32
I applaud your adherence to the style guide, but t
|
+ } |
+ template <typename T> void measure(const T&) { } |
+ |
+ size_t fSize; |
+}; |
+ |
+size_t SkPictureUtils::ApproximateBytesUsed(const SkPicture* pict) { |
+ size_t byteCount = sizeof(*pict); |
+ |
+ byteCount += pict->fRecord->bytesUsed(); |
+ if (pict->fBBH.get()) { |
+ byteCount += pict->fBBH->bytesUsed(); |
+ } |
+ byteCount += |
+ pict->fDeletionListeners.reserved() * sizeof(SkPicture::DeletionListener*) + |
+ pict->fDeletionListeners.count() * sizeof(SkPicture::DeletionListener); |
+ |
+ MeasureRecords visitor; |
+ for (unsigned curOp = 0; curOp < pict->fRecord->count(); curOp++) { |
+ pict->fRecord->visit<void>(curOp, visitor); |
+ } |
+ byteCount += visitor.measuredSize(); |
+ |
+ return byteCount; |
+} |