Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: tests/PictureTest.cpp

Issue 490253003: Implement SkPicture::bytesUsed() for SkRecord backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: More tweaks for object size Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkPictureUtils.cpp ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/PictureTest.cpp
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 5bc60371c997f957f56a0f122602812822c813fb..df10ea5968e6b02e79516a3948d20501782304eb 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -24,6 +24,7 @@
#include "SkPixelRef.h"
#include "SkRRect.h"
#include "SkRandom.h"
+#include "SkRecord.h"
#include "SkShader.h"
#include "SkStream.h"
@@ -1721,6 +1722,29 @@ static void test_gen_id(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, hasData->uniqueID() != empty->uniqueID());
}
+static void test_bytes_used(skiatest::Reporter* reporter) {
+ SkPictureRecorder recorder;
+
+ recorder.beginRecording(0, 0);
+ SkAutoTUnref<SkPicture> empty(recorder.endRecording());
+
+ // Sanity check to make sure we aren't under-measuring.
+ REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(empty.get()) >=
+ sizeof(SkPicture) + sizeof(SkRecord));
+
+ // Protect against any unintentional bloat.
+ REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(empty.get()) <= 184);
+
+ // Sanity check of nested SkPictures.
+ SkPictureRecorder r2;
+ r2.beginRecording(0, 0);
+ r2.getRecordingCanvas()->drawPicture(empty.get());
+ SkAutoTUnref<SkPicture> nested(r2.endRecording());
+
+ REPORTER_ASSERT(reporter, SkPictureUtils::ApproximateBytesUsed(nested.get()) >
+ SkPictureUtils::ApproximateBytesUsed(empty.get()));
+}
+
DEF_TEST(Picture, reporter) {
#ifdef SK_DEBUG
test_deleting_empty_picture();
@@ -1743,6 +1767,7 @@ DEF_TEST(Picture, reporter) {
test_hierarchical(reporter);
test_gen_id(reporter);
test_savelayer_extraction(reporter);
+ test_bytes_used(reporter);
}
static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
@@ -1837,6 +1862,7 @@ struct CountingBBH : public SkBBoxHierarchy {
}
virtual void insert(SkAutoTMalloc<SkRect>*, int) SK_OVERRIDE {}
+ virtual size_t bytesUsed() const { return 0; }
};
class SpoonFedBBHFactory : public SkBBHFactory {
« no previous file with comments | « src/utils/SkPictureUtils.cpp ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698