aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/core.gypi1
-rw-r--r--src/core/SkRecord.cpp21
-rw-r--r--src/core/SkRecord.h20
3 files changed, 28 insertions, 14 deletions
diff --git a/gyp/core.gypi b/gyp/core.gypi
index 01838a34bb..a4d5c2c60a 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -154,6 +154,7 @@
'<(skia_src_path)/core/SkReadBuffer.h',
'<(skia_src_path)/core/SkReadBuffer.cpp',
'<(skia_src_path)/core/SkReader32.h',
+ '<(skia_src_path)/core/SkRecord.cpp',
'<(skia_src_path)/core/SkRecordDraw.cpp',
'<(skia_src_path)/core/SkRecordOpts.cpp',
'<(skia_src_path)/core/SkRecorder.cpp',
diff --git a/src/core/SkRecord.cpp b/src/core/SkRecord.cpp
new file mode 100644
index 0000000000..e2d919b777
--- /dev/null
+++ b/src/core/SkRecord.cpp
@@ -0,0 +1,21 @@
+#include "SkRecord.h"
+
+SkRecord::~SkRecord() {
+ Destroyer destroyer;
+ for (unsigned i = 0; i < this->count(); i++) {
+ this->mutate<void>(i, destroyer);
+ }
+}
+
+void SkRecord::grow() {
+ SkASSERT(fCount == fReserved);
+ fReserved = SkTMax<unsigned>(kFirstReserveCount, fReserved*2);
+ fRecords.realloc(fReserved);
+ fTypes.realloc(fReserved);
+}
+
+size_t SkRecord::bytesUsed() const {
+ return fAlloc.approxBytesAllocated() +
+ fReserved * (sizeof(Record) + sizeof(Type8)) +
+ sizeof(SkRecord);
+}
diff --git a/src/core/SkRecord.h b/src/core/SkRecord.h
index 8179b06376..a8b4256adf 100644
--- a/src/core/SkRecord.h
+++ b/src/core/SkRecord.h
@@ -31,13 +31,7 @@ class SkRecord : public SkNVRefCnt<SkRecord> {
};
public:
SkRecord() : fCount(0), fReserved(0) {}
-
- ~SkRecord() {
- Destroyer destroyer;
- for (unsigned i = 0; i < this->count(); i++) {
- this->mutate<void>(i, destroyer);
- }
- }
+ ~SkRecord();
// Returns the number of canvas commands in this SkRecord.
unsigned count() const { return fCount; }
@@ -76,11 +70,8 @@ public:
template <typename T>
T* append() {
if (fCount == fReserved) {
- fReserved = SkTMax<unsigned>(kFirstReserveCount, fReserved*2);
- fRecords.realloc(fReserved);
- fTypes.realloc(fReserved);
+ this->grow();
}
-
fTypes[fCount] = T::kType;
return fRecords[fCount++].set(this->allocCommand<T>());
}
@@ -115,9 +106,7 @@ public:
// Does not return the bytes in any pointers embedded in the Records; callers
// need to iterate with a visitor to measure those they care for.
- size_t bytesUsed() const { return fAlloc.approxBytesAllocated() +
- fReserved * (sizeof(Record) + sizeof(Type8)) +
- sizeof(SkRecord); }
+ size_t bytesUsed() const;
private:
// Implementation notes!
@@ -184,6 +173,9 @@ private:
template <typename T>
SK_WHEN(!SkTIsEmpty<T>, T*) allocCommand() { return this->alloc<T>(); }
+ // Called when we've run out of room to record new commands.
+ void grow();
+
// An untyped pointer to some bytes in fAlloc. This is the interface for polymorphic dispatch:
// visit() and mutate() work with the parallel fTypes array to do the work of a vtable.
struct Record {