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

Unified Diff: tests/Writer32Test.cpp

Issue 167113003: Add capture snapshot as data to SkWriter32, use it to optimise record->playback. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clarified the snapshotAsData api comment. Created 6 years, 9 months 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/core/SkWriter32.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/Writer32Test.cpp
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index a471099b38ac4f73e5697a1525dfa59b04a9dbd0..f9b6f6a03fc16e8f575a1eebb69b1032eeb4598b 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -280,3 +280,36 @@ DEF_TEST(Writer32_misc, reporter) {
test_ptr(reporter);
test_rewind(reporter);
}
+
+DEF_TEST(Writer32_snapshot, reporter) {
+ int32_t array[] = { 1, 2, 4, 11 };
+ SkSWriter32<sizeof(array) + 4> writer;
+ writer.write(array, sizeof(array));
+ check_contents(reporter, writer, array, sizeof(array));
+ const void* beforeData = writer.contiguousArray();
+ SkAutoDataUnref snapshot(writer.snapshotAsData());
+ // check the snapshot forced a copy of the static data
+ REPORTER_ASSERT(reporter, snapshot->data() != beforeData);
+ REPORTER_ASSERT(reporter, snapshot->size() == writer.bytesWritten());
+}
+
+DEF_TEST(Writer32_snapshot_dynamic, reporter) {
+ int32_t array[] = { 1, 2, 4, 11 };
+ SkWriter32 writer;
+ writer.write(array, sizeof(array));
+ check_contents(reporter, writer, array, sizeof(array));
+ // force a capacity increase so we can test COW behaviour
+ writer.write(array, sizeof(array));
+ writer.rewindToOffset(sizeof(array));
+ const void* beforeData = writer.contiguousArray();
+ SkAutoDataUnref snapshot(writer.snapshotAsData());
+ // check the snapshot still points to the same data as the writer
+ REPORTER_ASSERT(reporter, writer.contiguousArray() == beforeData);
+ REPORTER_ASSERT(reporter, snapshot->data() == beforeData);
+ REPORTER_ASSERT(reporter, snapshot->size() == writer.bytesWritten());
+ // write more data that would fit in the buffer
+ writer.write(array, sizeof(array));
+ // test it triggered COW anyway
+ REPORTER_ASSERT(reporter, writer.contiguousArray() != beforeData);
+}
+
« no previous file with comments | « src/core/SkWriter32.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698