blob: c6e2129e9ed3df017dd93452ff7e0457233f1946 [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
14#define kPathCount 64
15
16SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
17}
18
19SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer)
20 : fHeap(kPathCount * sizeof(SkPath)) {
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000021 const int count = buffer.readInt();
reed@android.com8a1c16f2008-12-17 15:59:43 +000022
23 fPaths.setCount(count);
24 SkPath** ptr = fPaths.begin();
25 SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath));
26
27 for (int i = 0; i < count; i++) {
28 new (p) SkPath;
djsollen@google.com2b2ede32012-04-12 13:24:04 +000029 buffer.readPath(p);
reed@android.com8a1c16f2008-12-17 15:59:43 +000030 *ptr++ = p; // record the pointer
31 p++; // move to the next storage location
32 }
33}
34
35SkPathHeap::~SkPathHeap() {
36 SkPath** iter = fPaths.begin();
37 SkPath** stop = fPaths.end();
38 while (iter < stop) {
39 (*iter)->~SkPath();
40 iter++;
41 }
42}
43
44int SkPathHeap::append(const SkPath& path) {
45 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
46 new (p) SkPath(path);
47 *fPaths.append() = p;
48 return fPaths.count();
49}
50
51void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
52 int count = fPaths.count();
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000054 buffer.writeInt(count);
commit-bot@chromium.orgaa537d42013-02-28 19:03:13 +000055 SkPath* const* iter = fPaths.begin();
56 SkPath* const* stop = fPaths.end();
reed@android.com8a1c16f2008-12-17 15:59:43 +000057 while (iter < stop) {
djsollen@google.com2b2ede32012-04-12 13:24:04 +000058 buffer.writePath(**iter);
reed@android.com8a1c16f2008-12-17 15:59:43 +000059 iter++;
60 }
61}