epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkPathHeap.h" |
| 9 | #include "SkPath.h" |
| 10 | #include "SkStream.h" |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 11 | #include "SkFlattenableBuffers.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include <new> |
| 13 | |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 14 | SK_DEFINE_INST_COUNT(SkPathHeap) |
| 15 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #define kPathCount 64 |
| 17 | |
| 18 | SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) { |
| 19 | } |
| 20 | |
| 21 | SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer) |
| 22 | : fHeap(kPathCount * sizeof(SkPath)) { |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 23 | const int count = buffer.readInt(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 24 | |
| 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.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 31 | buffer.readPath(p); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | *ptr++ = p; // record the pointer |
| 33 | p++; // move to the next storage location |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | SkPathHeap::~SkPathHeap() { |
| 38 | SkPath** iter = fPaths.begin(); |
| 39 | SkPath** stop = fPaths.end(); |
| 40 | while (iter < stop) { |
| 41 | (*iter)->~SkPath(); |
| 42 | iter++; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | int 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 | |
| 53 | void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 54 | int count = fPaths.count(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame^] | 55 | |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 56 | buffer.writeInt(count); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 57 | SkPath** iter = fPaths.begin(); |
| 58 | SkPath** stop = fPaths.end(); |
| 59 | while (iter < stop) { |
djsollen@google.com | 2b2ede3 | 2012-04-12 13:24:04 +0000 | [diff] [blame] | 60 | buffer.writePath(**iter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | iter++; |
| 62 | } |
| 63 | } |
| 64 | |