aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-14 20:51:26 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-14 20:51:26 +0000
commit19382421b916aab00be7265815ba4e2690adf2c9 (patch)
tree8e69446ccf2e3548e9f2986a5eba67a641e76b59 /tests
parentb638a3a941fc9514b3f26165bfaaa7b48a580139 (diff)
Convert SkWriter32 to use an SkTDArray for its internal storage.
This reduces the allocation overhead of a null picture (create, beginRecording(), endRecording) from about 18K to about 1.9K. (There's still lots more to prune.) SkPictureFlat can exploit the fact that Writer32 is contiguous simplify its memory management. The Writer32 itself becomes the scratch buffer. Remove lots and lots of arbitrary magic numbers that were size guesses and minimum allocation sizes. Keep your eyes open for the big obvious DUH why we save 16K per picture! (Spoiler alert. It's because that first save we issue in beginRecording() forces the old SkWriter32 to allocate 16K.) Tests passing, DM passing. bench --match writer: ~20% faster null bench_record: ~30% faster bench_record on buildbot .skps: ~3-6% slower, ranging 25% faster to 20% slower bench_pictures on buildbot .skps: ~1-2% faster, ranging 13% faster to 28% slower BUG=skia:1850 R=reed@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/137433003 git-svn-id: http://skia.googlecode.com/svn/trunk@13073 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/AndroidPaintTest.cpp2
-rw-r--r--tests/ColorFilterTest.cpp2
-rw-r--r--tests/PathTest.cpp2
-rw-r--r--tests/SerializationTest.cpp6
-rw-r--r--tests/Writer32Test.cpp106
5 files changed, 56 insertions, 62 deletions
diff --git a/tests/AndroidPaintTest.cpp b/tests/AndroidPaintTest.cpp
index a638da9351..0f6c1e9a96 100644
--- a/tests/AndroidPaintTest.cpp
+++ b/tests/AndroidPaintTest.cpp
@@ -9,7 +9,7 @@
#include "TestClassDef.h"
static size_t Reconstruct(const SkPaint& src, SkPaint* dst) {
- SkOrderedWriteBuffer writer(64 /*arbitrary*/);
+ SkOrderedWriteBuffer writer;
src.flatten(writer);
const size_t size = writer.bytesWritten();
diff --git a/tests/ColorFilterTest.cpp b/tests/ColorFilterTest.cpp
index 8444b73a1d..7ad19b7aff 100644
--- a/tests/ColorFilterTest.cpp
+++ b/tests/ColorFilterTest.cpp
@@ -17,7 +17,7 @@
#include "SkOrderedWriteBuffer.h"
static SkColorFilter* reincarnate_colorfilter(SkFlattenable* obj) {
- SkOrderedWriteBuffer wb(1024);
+ SkOrderedWriteBuffer wb;
wb.writeFlattenable(obj);
size_t size = wb.size();
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 3f07ae04bc..063f05d5ed 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -1838,7 +1838,7 @@ static void test_isNestedRects(skiatest::Reporter* reporter) {
static void write_and_read_back(skiatest::Reporter* reporter,
const SkPath& p) {
- SkWriter32 writer(100);
+ SkWriter32 writer;
writer.writePath(p);
size_t size = writer.bytesWritten();
SkAutoMalloc storage(size);
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index a2601d22a7..38e7051d59 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -111,7 +111,7 @@ template<> struct SerializationUtils<SkScalar> {
template<typename T>
static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) {
- SkOrderedWriteBuffer writer(1024);
+ SkOrderedWriteBuffer writer;
writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
SerializationUtils<T>::Write(writer, testObj);
size_t bytesWritten = writer.bytesWritten();
@@ -142,7 +142,7 @@ static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) {
template<typename T>
static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
skiatest::Reporter* reporter) {
- SkOrderedWriteBuffer writer(1024);
+ SkOrderedWriteBuffer writer;
writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
SerializationUtils<T>::Write(writer, testObj);
size_t bytesWritten = writer.bytesWritten();
@@ -181,7 +181,7 @@ static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
template<typename T>
static void TestArraySerialization(T* data, skiatest::Reporter* reporter) {
- SkOrderedWriteBuffer writer(1024);
+ SkOrderedWriteBuffer writer;
writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
SerializationUtils<T>::Write(writer, data, kArraySize);
size_t bytesWritten = writer.bytesWritten();
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index 2032fefae7..a76c35d34c 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -24,13 +24,13 @@ static void test_reserve(skiatest::Reporter* reporter) {
// There used to be a bug where we'd assert your first reservation had to
// fit in external storage if you used it. This would crash in debug mode.
uint8_t storage[4];
- SkWriter32 writer(0, storage, sizeof(storage));
+ SkWriter32 writer(storage, sizeof(storage));
writer.reserve(40);
}
static void test_string_null(skiatest::Reporter* reporter) {
uint8_t storage[8];
- SkWriter32 writer(0, storage, sizeof(storage));
+ SkWriter32 writer(storage, sizeof(storage));
// Can we write NULL?
writer.writeString(NULL);
@@ -39,7 +39,7 @@ static void test_string_null(skiatest::Reporter* reporter) {
}
static void test_rewind(skiatest::Reporter* reporter) {
- SkSWriter32<32> writer(32);
+ SkSWriter32<32> writer;
int32_t array[3] = { 1, 2, 4 };
REPORTER_ASSERT(reporter, 0 == writer.bytesWritten());
@@ -58,7 +58,7 @@ static void test_rewind(skiatest::Reporter* reporter) {
// test rewinding past allocated chunks. This used to crash because we
// didn't truncate our link-list after freeing trailing blocks
{
- SkWriter32 writer(64);
+ SkWriter32 writer;
for (int i = 0; i < 100; ++i) {
writer.writeInt(i);
}
@@ -71,7 +71,7 @@ static void test_rewind(skiatest::Reporter* reporter) {
}
static void test_ptr(skiatest::Reporter* reporter) {
- SkSWriter32<32> writer(32);
+ SkSWriter32<32> writer;
void* p0 = reporter;
void* p1 = &writer;
@@ -186,65 +186,59 @@ static void testWritePad(skiatest::Reporter* reporter, SkWriter32* writer) {
}
}
-DEF_TEST(Writer32, reporter) {
- // dynamic allocator
- {
- SkWriter32 writer(256 * 4);
- test1(reporter, &writer);
+DEF_TEST(Writer32_dynamic, reporter) {
+ SkWriter32 writer;
+ test1(reporter, &writer);
- writer.reset();
- test2(reporter, &writer);
+ writer.reset();
+ test2(reporter, &writer);
- writer.reset();
- testWritePad(reporter, &writer);
- }
+ writer.reset();
+ testWritePad(reporter, &writer);
+}
- // storage-block
- {
- SkWriter32 writer(0);
- uint32_t storage[256];
- writer.reset(storage, sizeof(storage));
- // These three writes are small enough to fit in storage.
- test1(reporter, &writer);
- REPORTER_ASSERT(reporter, writer.wroteOnlyToStorage());
-
- writer.reset(storage, sizeof(storage));
- test2(reporter, &writer);
- REPORTER_ASSERT(reporter, writer.wroteOnlyToStorage());
-
- writer.reset(storage, sizeof(storage));
- testWritePad(reporter, &writer);
- REPORTER_ASSERT(reporter, writer.wroteOnlyToStorage());
-
- // Try overflowing the storage-block.
- uint32_t smallStorage[8];
- writer.reset(smallStorage, sizeof(smallStorage));
- test2(reporter, &writer);
- REPORTER_ASSERT(reporter, !writer.wroteOnlyToStorage());
- }
+DEF_TEST(Writer32_contiguous, reporter) {
+ uint32_t storage[256];
+ SkWriter32 writer;
+ writer.reset(storage, sizeof(storage));
+ // This write is small enough to fit in storage, so it's contiguous.
+ test1(reporter, &writer);
+ REPORTER_ASSERT(reporter, writer.contiguousArray() != NULL);
+
+ // This write is too big for the 32 byte storage block we provide.
+ writer.reset(storage, 32);
+ test2(reporter, &writer);
+ // Some data is in storage, some in writer's internal storage.
+ REPORTER_ASSERT(reporter, writer.contiguousArray() == NULL);
+
+ writer.reset();
+ test2(reporter, &writer);
+ // There is no external storage. All the data is in internal storage,
+ // so we can always read it contiguously.
+ REPORTER_ASSERT(reporter, writer.contiguousArray() != NULL);
+}
- // small storage
- {
- SkSWriter32<8 * sizeof(intptr_t)> writer(100);
- test1(reporter, &writer);
- writer.reset(); // should just rewind our storage
- test2(reporter, &writer);
+DEF_TEST(Writer32_small, reporter) {
+ SkSWriter32<8 * sizeof(intptr_t)> writer;
+ test1(reporter, &writer);
+ writer.reset(); // should just rewind our storage
+ test2(reporter, &writer);
- writer.reset();
- testWritePad(reporter, &writer);
- }
+ writer.reset();
+ testWritePad(reporter, &writer);
+}
- // large storage
- {
- SkSWriter32<1024 * sizeof(intptr_t)> writer(100);
- test1(reporter, &writer);
- writer.reset(); // should just rewind our storage
- test2(reporter, &writer);
+DEF_TEST(Writer32_large, reporter) {
+ SkSWriter32<1024 * sizeof(intptr_t)> writer;
+ test1(reporter, &writer);
+ writer.reset(); // should just rewind our storage
+ test2(reporter, &writer);
- writer.reset();
- testWritePad(reporter, &writer);
- }
+ writer.reset();
+ testWritePad(reporter, &writer);
+}
+DEF_TEST(Writer32_misc, reporter) {
test_reserve(reporter);
test_string_null(reporter);
test_ptr(reporter);