Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / core / SkPathHeap.cpp
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 "SkReadBuffer.h"
12 #include "SkWriteBuffer.h"
13 #include <new>
14
15 #define kPathCount  64
16
17 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
18 }
19
20 SkPathHeap::SkPathHeap(SkReadBuffer& buffer)
21             : fHeap(kPathCount * sizeof(SkPath)) {
22     const int count = buffer.readInt();
23
24     fPaths.setCount(count);
25     SkPath** ptr = fPaths.begin();
26     SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath));
27
28     for (int i = 0; i < count; i++) {
29         new (p) SkPath;
30         buffer.readPath(p);
31         *ptr++ = p; // record the pointer
32         p++;        // move to the next storage location
33     }
34 }
35
36 SkPathHeap::~SkPathHeap() {
37     SkPath** iter = fPaths.begin();
38     SkPath** stop = fPaths.end();
39     while (iter < stop) {
40         (*iter)->~SkPath();
41         iter++;
42     }
43 }
44
45 int SkPathHeap::append(const SkPath& path) {
46     SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
47     new (p) SkPath(path);
48     *fPaths.append() = p;
49     return fPaths.count();
50 }
51
52 void SkPathHeap::flatten(SkWriteBuffer& buffer) const {
53     int count = fPaths.count();
54
55     buffer.writeInt(count);
56     SkPath* const* iter = fPaths.begin();
57     SkPath* const* stop = fPaths.end();
58     while (iter < stop) {
59         buffer.writePath(**iter);
60         iter++;
61     }
62 }