diff options
author | Mike Klein <mtklein@chromium.org> | 2017-04-11 10:36:48 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-11 16:51:17 +0000 |
commit | 0fa156fcfba3b430801b5448ddfc254732bf7386 (patch) | |
tree | ca6806767079c45eeeda0ce14175f275e0e14f9a | |
parent | 7a542c559a6e584107b94e6254ac3c7f9f24b591 (diff) |
remove inline allocation in SkRecord
This is part one of many to making SkPicture simpler.
SkMiniPicture covers the really small allocations,
so there's really no reason for us to have these inline allocations.
BUG=skia:6484
Change-Id: I0e27ac747a6b15cf178db9639128fef757bc137b
Reviewed-on: https://skia-review.googlesource.com/13137
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Herb Derby <herb@google.com>
-rw-r--r-- | src/core/SkRecord.cpp | 16 | ||||
-rw-r--r-- | src/core/SkRecord.h | 14 |
2 files changed, 9 insertions, 21 deletions
diff --git a/src/core/SkRecord.cpp b/src/core/SkRecord.cpp index 3685b2d16d..3d098c6c89 100644 --- a/src/core/SkRecord.cpp +++ b/src/core/SkRecord.cpp @@ -8,6 +8,9 @@ #include "SkRecord.h" #include <algorithm> +SkRecord::SkRecord() + : fCount(0), fReserved(0), fAlloc(8/*first malloc at 256 bytes*/) {} + SkRecord::~SkRecord() { Destroyer destroyer; for (int i = 0; i < this->count(); i++) { @@ -17,19 +20,14 @@ SkRecord::~SkRecord() { void SkRecord::grow() { SkASSERT(fCount == fReserved); - SkASSERT(fReserved > 0); - fReserved *= 2; + fReserved = fReserved ? fReserved * 2 : 4; fRecords.realloc(fReserved); } size_t SkRecord::bytesUsed() const { - size_t bytes = fAlloc.approxBytesAllocated() + sizeof(SkRecord); - // If fReserved <= kInlineRecords, we've already accounted for fRecords with sizeof(SkRecord). - // When we go over that limit, they're allocated on the heap (and the inline space is wasted). - if (fReserved > kInlineRecords) { - bytes += fReserved * sizeof(Record); - } - return bytes; + return sizeof(SkRecord) + + fReserved * sizeof(Record) + + fAlloc.approxBytesAllocated(); } void SkRecord::defrag() { diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h index 09344fa37f..3766e3447e 100644 --- a/src/core/SkRecord.h +++ b/src/core/SkRecord.h @@ -26,17 +26,8 @@ // get this wrong. class SkRecord : public SkRefCnt { - enum { - // TODO: tune these two constants. - kInlineRecords = 4, // Ideally our lower limit on recorded ops per picture. - kInlineAllocLgBytes = 8, // 1<<8 == 256 bytes inline, then SkVarAlloc starting at 512 bytes. - }; public: - SkRecord() - : fCount(0) - , fReserved(kInlineRecords) - , fAlloc(kInlineAllocLgBytes+1, // First malloc'd block is 2x as large as fInlineAlloc. - fInlineAlloc, sizeof(fInlineAlloc)) {} + SkRecord(); ~SkRecord(); // Returns the number of canvas commands in this SkRecord. @@ -187,12 +178,11 @@ private: // fRecords needs to be a data structure that can append fixed length data, and need to // support efficient random access and forward iteration. (It doesn't need to be contiguous.) int fCount, fReserved; - SkAutoSTMalloc<kInlineRecords, Record> fRecords; + SkAutoTMalloc<Record> fRecords; // fAlloc needs to be a data structure which can append variable length data in contiguous // chunks, returning a stable handle to that data for later retrieval. SkVarAlloc fAlloc; - char fInlineAlloc[1 << kInlineAllocLgBytes]; }; #endif//SkRecord_DEFINED |