Index: src/utils/SkPictureUtils.cpp |
diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp |
index dfa772a2da5be93e24bc645608c41052218f6822..73c61bb042871ca21907d396a8ffd9b48a5518cb 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,29 @@ SkData* SkPictureUtils::GatherPixelRefs(const SkPicture* pict, const SkRect& are |
} |
return data; |
} |
+ |
+struct MeasureRecords { |
+ template <typename T> size_t operator()(const T& op) { return 0; } |
+ size_t operator()(const SkRecords::DrawPicture& op) { |
+ return SkPictureUtils::ApproximateBytesUsed(op.picture); |
+ } |
+}; |
+ |
+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++) { |
+ byteCount += pict->fRecord->visit<size_t>(curOp, visitor); |
+ } |
+ |
+ return byteCount; |
+} |