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"
16 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
19 SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer)
20 : fHeap(kPathCount * sizeof(SkPath)) {
21 const int count = buffer.readInt();
23 fPaths.setCount(count);
24 SkPath** ptr = fPaths.begin();
25 SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath));
27 for (int i = 0; i < count; i++) {
30 *ptr++ = p; // record the pointer
31 p++; // move to the next storage location
35 SkPathHeap::~SkPathHeap() {
36 SkPath** iter = fPaths.begin();
37 SkPath** stop = fPaths.end();
44 int SkPathHeap::append(const SkPath& path) {
45 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
48 return fPaths.count();
51 void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
52 int count = fPaths.count();
54 buffer.writeInt(count);
55 SkPath* const* iter = fPaths.begin();
56 SkPath* const* stop = fPaths.end();
58 buffer.writePath(**iter);