diff options
author | 2014-11-20 09:18:31 -0800 | |
---|---|---|
committer | 2014-11-20 09:18:32 -0800 | |
commit | 08d1fccf6eeec0a9fd5421e59e4d05daccf6e339 (patch) | |
tree | 4b4e6e07b4f4371a443d057591665a5ac0bcbdd3 /src | |
parent | cdeeb095a629b0db9f0ddff09516f2b78255c047 (diff) |
Add SkNVRefCnt, prune down SkPicture's size
SkNVRefCnt is a variant of SkRefCnt that's Not Virtual, so weighs 4 bytes
instead of 8 or 16. There's only benefit to doing this if the deriving class
does not otherwise need a vtable, e.g. SkPicture.
I've stripped out some cruft from SkPicture, rearranged fields to pack tightly,
and added compile asserts for the sizes of SkPicture, SkRecord, and
SkVarAlloc.
BUG=skia:3144
Review URL: https://codereview.chromium.org/741793002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkRecord.h | 9 | ||||
-rw-r--r-- | src/core/SkRecorder.cpp | 16 | ||||
-rw-r--r-- | src/core/SkVarAlloc.h | 1 |
3 files changed, 15 insertions, 11 deletions
diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h index 357f4fb16b..403110d385 100644 --- a/src/core/SkRecord.h +++ b/src/core/SkRecord.h @@ -231,12 +231,15 @@ private: // fRecords and fTypes need to be data structures that can append fixed length data, and need to // support efficient random access and forward iteration. (They don't need to be contiguous.) - SkVarAlloc fAlloc; - SkAutoTMalloc<Record> fRecords; - SkAutoTMalloc<Type8> fTypes; // fCount and fReserved measure both fRecords and fTypes, which always grow in lock step. unsigned fCount; unsigned fReserved; + SkAutoTMalloc<Record> fRecords; + SkAutoTMalloc<Type8> fTypes; + SkVarAlloc fAlloc; + // Strangely the order of these fields matters. If the unsigneds don't go first we're 56 bytes. + // tomhudson and mtklein have no idea why. }; +SK_COMPILE_ASSERT(sizeof(SkRecord) <= 48, SkRecordSize); #endif//SkRecord_DEFINED diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 7ddd369bc9..33d89d9079 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -31,25 +31,25 @@ void SkRecorder::forgetRecord() { } // ReleaseProc for SkData, assuming the data was allocated via sk_malloc, and its contents are an -// array of SkRefCnt* which need to be unref'd. +// array of SkPicture* which need to be unref'd. // static void unref_all_malloc_releaseProc(const void* ptr, size_t length, void* context) { SkASSERT(ptr == context); // our context is our ptr, allocated via sk_malloc - int count = SkToInt(length / sizeof(SkRefCnt*)); - SkASSERT(count * sizeof(SkRefCnt*) == length); // our length is snug for the array + int count = SkToInt(length / sizeof(SkPicture*)); + SkASSERT(count * sizeof(SkPicture*) == length); // our length is snug for the array - SkRefCnt* const* array = reinterpret_cast<SkRefCnt* const*>(ptr); + SkPicture* const* array = reinterpret_cast<SkPicture* const*>(ptr); for (int i = 0; i < count; ++i) { SkSafeUnref(array[i]); } sk_free(context); } -// Return an uninitialized SkData sized for "count" SkRefCnt pointers. They will be unref'd when +// Return an uninitialized SkData sized for "count" SkPicture pointers. They will be unref'd when // the SkData is destroyed. // -static SkData* new_uninitialized_refcnt_ptrs(int count) { - size_t length = count * sizeof(SkRefCnt*); +static SkData* new_uninitialized_picture_ptrs(int count) { + size_t length = count * sizeof(SkPicture*); void* array = sk_malloc_throw(length); void* context = array; return SkData::NewWithProc(array, length, unref_all_malloc_releaseProc, context); @@ -60,7 +60,7 @@ SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFl if (0 == count) { return NULL; } - SkData* data = new_uninitialized_refcnt_ptrs(count); + SkData* data = new_uninitialized_picture_ptrs(count); SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data()); for (int i = 0; i < count; ++i) { pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags); diff --git a/src/core/SkVarAlloc.h b/src/core/SkVarAlloc.h index 9eac658828..2e8f19c8fe 100644 --- a/src/core/SkVarAlloc.h +++ b/src/core/SkVarAlloc.h @@ -37,5 +37,6 @@ private: struct Block; Block* fBlock; }; +SK_COMPILE_ASSERT(sizeof(SkVarAlloc) <= 24, SkVarAllocSize); #endif//SkVarAlloc_DEFINED |