diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkRecord.cpp | 8 | ||||
-rw-r--r-- | src/core/SkRecord.h | 16 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/core/SkRecord.cpp b/src/core/SkRecord.cpp index 3d098c6c89..4df4131340 100644 --- a/src/core/SkRecord.cpp +++ b/src/core/SkRecord.cpp @@ -8,9 +8,6 @@ #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++) { @@ -25,9 +22,8 @@ void SkRecord::grow() { } size_t SkRecord::bytesUsed() const { - return sizeof(SkRecord) - + fReserved * sizeof(Record) - + fAlloc.approxBytesAllocated(); + size_t bytes = fApproxBytesAllocated + sizeof(SkRecord); + return bytes; } void SkRecord::defrag() { diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h index 3766e3447e..1360f358b3 100644 --- a/src/core/SkRecord.h +++ b/src/core/SkRecord.h @@ -8,10 +8,10 @@ #ifndef SkRecord_DEFINED #define SkRecord_DEFINED +#include "SkArenaAlloc.h" #include "SkRecords.h" #include "SkTLogic.h" #include "SkTemplates.h" -#include "SkVarAlloc.h" // SkRecord represents a sequence of SkCanvas calls, saved for future use. // These future uses may include: replay, optimization, serialization, or combinations of those. @@ -27,7 +27,7 @@ class SkRecord : public SkRefCnt { public: - SkRecord(); + SkRecord() = default; ~SkRecord(); // Returns the number of canvas commands in this SkRecord. @@ -55,7 +55,11 @@ public: // Here T can be any class, not just those from SkRecords. Throws on failure. template <typename T> T* alloc(size_t count = 1) { - return (T*)fAlloc.alloc(sizeof(T) * count); + struct RawBytes { + alignas(T) char data[sizeof(T)]; + }; + fApproxBytesAllocated += count * sizeof(T) + alignof(T); + return (T*)fAlloc.makeArrayDefault<RawBytes>(count); } // Add a new command of type T to the end of this SkRecord. @@ -177,12 +181,14 @@ 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; + int fCount{0}, + fReserved{0}; 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; + SkArenaAlloc fAlloc{256}; + size_t fApproxBytesAllocated{0}; }; #endif//SkRecord_DEFINED |