aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar tomhudson <tomhudson@chromium.org>2014-11-19 10:41:14 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-19 10:41:14 -0800
commit158fcaa031d105dc999d9813fee8927db56a871c (patch)
tree8a1415b2822e67cad2e31e2957cac735415f7c03 /tests
parent72f92acd47a884b9a1cc961a822a2d4e586b54c1 (diff)
Implement SkPicture::bytesUsed() for SkRecord backend
BUG=chromium:230419 R=mtklein@google.com,reed@google.com Review URL: https://codereview.chromium.org/490253003
Diffstat (limited to 'tests')
-rw-r--r--tests/PictureTest.cpp26
-rw-r--r--tests/RecordDrawTest.cpp1
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index c9298335f1..c2c19c546b 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 {
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp
index e5dd9fe654..b7538f1e9a 100644
--- a/tests/RecordDrawTest.cpp
+++ b/tests/RecordDrawTest.cpp
@@ -109,6 +109,7 @@ struct TestBBH : public SkBBoxHierarchy {
}
virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const SK_OVERRIDE {}
+ virtual size_t bytesUsed() const SK_OVERRIDE { return 0; }
struct Entry {
unsigned opIndex;