SkPathHeap.cpp revision ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976e
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 */ 8#include "SkPathHeap.h" 9#include "SkPath.h" 10#include "SkStream.h" 11#include "SkFlattenable.h" 12#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)) { 21 int count = buffer.readS32(); 22 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; 29 p->unflatten(buffer); 30 *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(); 53 54 buffer.write32(count); 55 SkPath** iter = fPaths.begin(); 56 SkPath** stop = fPaths.end(); 57 while (iter < stop) { 58 (*iter)->flatten(buffer); 59 iter++; 60 } 61} 62 63