Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: src/core/SkPathHeap.cpp

Issue 190923002: Add deduping capability to SkPathHeap (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkPathHeap.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkPathHeap.h" 8 #include "SkPathHeap.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkTSearch.h"
12 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
13 #include <new> 14 #include <new>
14 15
15 #define kPathCount 64 16 #define kPathCount 64
16 17
17 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) { 18 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
18 } 19 }
19 20
20 SkPathHeap::SkPathHeap(SkReadBuffer& buffer) 21 SkPathHeap::SkPathHeap(SkReadBuffer& buffer)
21 : fHeap(kPathCount * sizeof(SkPath)) { 22 : fHeap(kPathCount * sizeof(SkPath)) {
(...skipping 20 matching lines...) Expand all
42 } 43 }
43 } 44 }
44 45
45 int SkPathHeap::append(const SkPath& path) { 46 int SkPathHeap::append(const SkPath& path) {
46 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath)); 47 SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
47 new (p) SkPath(path); 48 new (p) SkPath(path);
48 *fPaths.append() = p; 49 *fPaths.append() = p;
49 return fPaths.count(); 50 return fPaths.count();
50 } 51 }
51 52
53 SkPathHeap::LookupEntry::LookupEntry(const SkPath& path)
54 : fGenerationID(path.getGenerationID()), fStorageSlot(0) {
55 }
56
57 SkPathHeap::LookupEntry* SkPathHeap::addIfNotPresent(const SkPath& path) {
58 LookupEntry searchKey(path);
59 int index = SkTSearch<const LookupEntry, LookupEntry::Less>(
60 fLookupTable.begin(),
61 fLookupTable.count(),
62 searchKey,
63 sizeof(LookupEntry));
64 if (index < 0) {
65 index = ~index;
66 *fLookupTable.insert(index) = LookupEntry(path);
67 }
68
69 return &fLookupTable[index];;
70 }
71
72 int SkPathHeap::insert(const SkPath& path) {
73 SkPathHeap::LookupEntry* entry = this->addIfNotPresent(path);
74
75 if (entry->storageSlot() > 0) {
76 return entry->storageSlot();
77 }
78
79 int newSlot = this->append(path);
80 SkASSERT(newSlot > 0);
81 entry->setStorageSlot(newSlot);
82 return newSlot;
83 }
84
52 void SkPathHeap::flatten(SkWriteBuffer& buffer) const { 85 void SkPathHeap::flatten(SkWriteBuffer& buffer) const {
53 int count = fPaths.count(); 86 int count = fPaths.count();
54 87
55 buffer.writeInt(count); 88 buffer.writeInt(count);
56 SkPath* const* iter = fPaths.begin(); 89 SkPath* const* iter = fPaths.begin();
57 SkPath* const* stop = fPaths.end(); 90 SkPath* const* stop = fPaths.end();
58 while (iter < stop) { 91 while (iter < stop) {
59 buffer.writePath(**iter); 92 buffer.writePath(**iter);
60 iter++; 93 iter++;
61 } 94 }
62 } 95 }
OLDNEW
« no previous file with comments | « src/core/SkPathHeap.h ('k') | src/core/SkPictureRecord.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698