3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
8 #include "SkPathHeap.h"
11 #include "SkFlattenableBuffers.h"
14 SK_DEFINE_INST_COUNT(SkPathHeap)
18 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
21 SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer)
22 : fHeap(kPathCount * sizeof(SkPath)) {
23 const int count = buffer.readInt();
25 fPaths.setCount(count);
26 SkPath** ptr = fPaths.begin();
27 SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath));
29 for (int i = 0; i < count; i++) {
32 *ptr++ = p; // record the pointer
33 p++; // move to the next storage location
37 SkPathHeap::~SkPathHeap() {
38 SkPath** iter = fPaths.begin();
39 SkPath** stop = fPaths.end();
46 int SkPathHeap::append(const SkPath& path) {
47 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
50 return fPaths.count();
53 void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
54 int count = fPaths.count();
56 buffer.writeInt(count);
57 SkPath* const* iter = fPaths.begin();
58 SkPath* const* stop = fPaths.end();
60 buffer.writePath(**iter);