aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRecord.h
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-04-18 11:42:49 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-18 16:19:47 +0000
commit4304d11ada22ebfb6b64d87247ad24cde89c3a74 (patch)
treebbdd9576071af23d021900d344131366fecc19f8 /src/core/SkRecord.h
parentbc8ee52d4649afdc972599e5ef2a2a543867985d (diff)
Change SkRecord to use SkArenaAlloc
This CL uses the strategy of allocating raw bytes with the proper alignment so that SkRecord can manage the object lifetimes. Change-Id: I73604d41a3c6a12d1e2f7f8419f75b95c0190f68 Reviewed-on: https://skia-review.googlesource.com/13621 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkRecord.h')
-rw-r--r--src/core/SkRecord.h16
1 files changed, 11 insertions, 5 deletions
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