SkPathHeap.cpp revision aa537d4bdb2384cdcd0644a02a2ab7fb0ecdd3b3
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPathHeap.h" 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkPath.h" 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkStream.h" 11c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com#include "SkFlattenableBuffers.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include <new> 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 144d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.comSK_DEFINE_INST_COUNT(SkPathHeap) 154d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define kPathCount 64 178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) { 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer) 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com : fHeap(kPathCount * sizeof(SkPath)) { 23c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com const int count = buffer.readInt(); 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com fPaths.setCount(count); 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath** ptr = fPaths.begin(); 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath)); 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com for (int i = 0; i < count; i++) { 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com new (p) SkPath; 312b2ede3e713065e1bac461787b0aafb03eaf871fdjsollen@google.com buffer.readPath(p); 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *ptr++ = p; // record the pointer 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p++; // move to the next storage location 348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comSkPathHeap::~SkPathHeap() { 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath** iter = fPaths.begin(); 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath** stop = fPaths.end(); 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (iter < stop) { 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (*iter)->~SkPath(); 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com iter++; 438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comint SkPathHeap::append(const SkPath& path) { 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath)); 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com new (p) SkPath(path); 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *fPaths.append() = p; 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return fPaths.count(); 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comvoid SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const { 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count = fPaths.count(); 55fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 56c73dd5c6880739f26216f198c757028fd28df1a4djsollen@google.com buffer.writeInt(count); 57aa537d4bdb2384cdcd0644a02a2ab7fb0ecdd3b3commit-bot@chromium.org SkPath* const* iter = fPaths.begin(); 58aa537d4bdb2384cdcd0644a02a2ab7fb0ecdd3b3commit-bot@chromium.org SkPath* const* stop = fPaths.end(); 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com while (iter < stop) { 602b2ede3e713065e1bac461787b0aafb03eaf871fdjsollen@google.com buffer.writePath(**iter); 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com iter++; 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 64