blob: bd5269d327ca0cddb9efd202dfae0990cfb95c92 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SkPathHeap.h"
9#include "SkPath.h"
10#include "SkStream.h"
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000011#include "SkFlattenableBuffers.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include <new>
13
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000014SK_DEFINE_INST_COUNT(SkPathHeap)
15
reed@android.com8a1c16f2008-12-17 15:59:43 +000016#define kPathCount 64
17
18SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
19}
20
21SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer)
22 : fHeap(kPathCount * sizeof(SkPath)) {
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000023 const int count = buffer.readInt();
reed@android.com8a1c16f2008-12-17 15:59:43 +000024
25 fPaths.setCount(count);
26 SkPath** ptr = fPaths.begin();
27 SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath));
28
29 for (int i = 0; i < count; i++) {
30 new (p) SkPath;
djsollen@google.com2b2ede32012-04-12 13:24:04 +000031 buffer.readPath(p);
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 *ptr++ = p; // record the pointer
33 p++; // move to the next storage location
34 }
35}
36
37SkPathHeap::~SkPathHeap() {
38 SkPath** iter = fPaths.begin();
39 SkPath** stop = fPaths.end();
40 while (iter < stop) {
41 (*iter)->~SkPath();
42 iter++;
43 }
44}
45
46int SkPathHeap::append(const SkPath& path) {
47 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
48 new (p) SkPath(path);
49 *fPaths.append() = p;
50 return fPaths.count();
51}
52
53void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
54 int count = fPaths.count();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000056 buffer.writeInt(count);
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 SkPath** iter = fPaths.begin();
58 SkPath** stop = fPaths.end();
59 while (iter < stop) {
djsollen@google.com2b2ede32012-04-12 13:24:04 +000060 buffer.writePath(**iter);
reed@android.com8a1c16f2008-12-17 15:59:43 +000061 iter++;
62 }
63}
64