OLD | NEW |
| (Empty) |
1 #include "SkPathHeap.h" | |
2 #include "SkPath.h" | |
3 #include "SkStream.h" | |
4 #include "SkFlattenable.h" | |
5 #include <new> | |
6 | |
7 #define kPathCount 64 | |
8 | |
9 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) { | |
10 } | |
11 | |
12 SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer) | |
13 : fHeap(kPathCount * sizeof(SkPath)) { | |
14 int count = buffer.readS32(); | |
15 | |
16 fPaths.setCount(count); | |
17 SkPath** ptr = fPaths.begin(); | |
18 SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath)); | |
19 | |
20 for (int i = 0; i < count; i++) { | |
21 new (p) SkPath; | |
22 p->unflatten(buffer); | |
23 *ptr++ = p; // record the pointer | |
24 p++; // move to the next storage location | |
25 } | |
26 } | |
27 | |
28 SkPathHeap::~SkPathHeap() { | |
29 SkPath** iter = fPaths.begin(); | |
30 SkPath** stop = fPaths.end(); | |
31 while (iter < stop) { | |
32 (*iter)->~SkPath(); | |
33 iter++; | |
34 } | |
35 } | |
36 | |
37 int SkPathHeap::append(const SkPath& path) { | |
38 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath)); | |
39 new (p) SkPath(path); | |
40 *fPaths.append() = p; | |
41 return fPaths.count(); | |
42 } | |
43 | |
44 void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const { | |
45 int count = fPaths.count(); | |
46 | |
47 buffer.write32(count); | |
48 SkPath** iter = fPaths.begin(); | |
49 SkPath** stop = fPaths.end(); | |
50 while (iter < stop) { | |
51 (*iter)->flatten(buffer); | |
52 iter++; | |
53 } | |
54 } | |
55 | |
OLD | NEW |