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