OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
9 #include "SkBitmapHeap.h" | 9 #include "SkBitmapHeap.h" |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 // will be the only one able to modify it, so it does not | 31 // will be the only one able to modify it, so it does not |
32 // need to be an atomic operation. | 32 // need to be an atomic operation. |
33 fRefCount = count; | 33 fRefCount = count; |
34 } else { | 34 } else { |
35 sk_atomic_add(&fRefCount, count); | 35 sk_atomic_add(&fRefCount, count); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 /////////////////////////////////////////////////////////////////////////////// | 39 /////////////////////////////////////////////////////////////////////////////// |
40 | 40 |
41 int SkBitmapHeap::LookupEntry::Compare(const SkBitmapHeap::LookupEntry *a, | 41 bool SkBitmapHeap::LookupEntry::Less(const SkBitmapHeap::LookupEntry& a, |
42 const SkBitmapHeap::LookupEntry *b) { | 42 const SkBitmapHeap::LookupEntry& b) { |
43 if (a->fGenerationId < b->fGenerationId) { | 43 if (a.fGenerationId < b.fGenerationId) { |
44 return -1; | 44 return true; |
45 } else if (a->fGenerationId > b->fGenerationId) { | 45 } else if (a.fGenerationId > b.fGenerationId) { |
46 return 1; | 46 return false; |
47 } else if (a->fPixelOffset < b->fPixelOffset) { | 47 } else if (a.fPixelOffset < b.fPixelOffset) { |
48 return -1; | 48 return true; |
49 } else if (a->fPixelOffset > b->fPixelOffset) { | 49 } else if (a.fPixelOffset > b.fPixelOffset) { |
50 return 1; | 50 return false; |
51 } else if (a->fWidth < b->fWidth) { | 51 } else if (a.fWidth < b.fWidth) { |
52 return -1; | 52 return true; |
53 } else if (a->fWidth > b->fWidth) { | 53 } else if (a.fWidth > b.fWidth) { |
54 return 1; | 54 return false; |
55 } else if (a->fHeight < b->fHeight) { | 55 } else if (a.fHeight < b.fHeight) { |
56 return -1; | 56 return true; |
57 } else if (a->fHeight > b->fHeight) { | |
58 return 1; | |
59 } | 57 } |
60 return 0; | 58 return false; |
61 } | 59 } |
62 | 60 |
63 /////////////////////////////////////////////////////////////////////////////// | 61 /////////////////////////////////////////////////////////////////////////////// |
64 | 62 |
65 SkBitmapHeap::SkBitmapHeap(int32_t preferredSize, int32_t ownerCount) | 63 SkBitmapHeap::SkBitmapHeap(int32_t preferredSize, int32_t ownerCount) |
66 : INHERITED() | 64 : INHERITED() |
67 , fExternalStorage(NULL) | 65 , fExternalStorage(NULL) |
68 , fMostRecentlyUsed(NULL) | 66 , fMostRecentlyUsed(NULL) |
69 , fLeastRecentlyUsed(NULL) | 67 , fLeastRecentlyUsed(NULL) |
70 , fPreferredCount(preferredSize) | 68 , fPreferredCount(preferredSize) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 SkASSERT(0 == fBytesAllocated); | 222 SkASSERT(0 == fBytesAllocated); |
225 } else { | 223 } else { |
226 fLeastRecentlyUsed->fLessRecentlyUsed = NULL; | 224 fLeastRecentlyUsed->fLessRecentlyUsed = NULL; |
227 } | 225 } |
228 } | 226 } |
229 | 227 |
230 return origBytesAllocated - fBytesAllocated; | 228 return origBytesAllocated - fBytesAllocated; |
231 } | 229 } |
232 | 230 |
233 int SkBitmapHeap::findInLookupTable(const LookupEntry& indexEntry, SkBitmapHeapE
ntry** entry) { | 231 int SkBitmapHeap::findInLookupTable(const LookupEntry& indexEntry, SkBitmapHeapE
ntry** entry) { |
234 int index = SkTSearch<const LookupEntry>((const LookupEntry**)fLookupTable.b
egin(), | 232 int index = SkTSearch<const LookupEntry, LookupEntry::Less>( |
| 233 (const LookupEntry**)fLookupTable.b
egin(), |
235 fLookupTable.count(), | 234 fLookupTable.count(), |
236 &indexEntry, sizeof(void*), LookupE
ntry::Compare); | 235 &indexEntry, sizeof(void*)); |
237 | 236 |
238 if (index < 0) { | 237 if (index < 0) { |
239 // insert ourselves into the bitmapIndex | 238 // insert ourselves into the bitmapIndex |
240 index = ~index; | 239 index = ~index; |
241 *fLookupTable.insert(index) = SkNEW_ARGS(LookupEntry, (indexEntry)); | 240 *fLookupTable.insert(index) = SkNEW_ARGS(LookupEntry, (indexEntry)); |
242 } else if (entry != NULL) { | 241 } else if (entry != NULL) { |
243 // populate the entry if needed | 242 // populate the entry if needed |
244 *entry = fStorage[fLookupTable[index]->fStorageSlot]; | 243 *entry = fStorage[fLookupTable[index]->fStorageSlot]; |
245 } | 244 } |
246 | 245 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 for (int i = 0; i < fDeferredEntries.count(); i++) { | 393 for (int i = 0; i < fDeferredEntries.count(); i++) { |
395 SkASSERT(fOwnerCount != IGNORE_OWNERS); | 394 SkASSERT(fOwnerCount != IGNORE_OWNERS); |
396 SkBitmapHeapEntry* heapEntry = this->getEntry(fDeferredEntries[i]); | 395 SkBitmapHeapEntry* heapEntry = this->getEntry(fDeferredEntries[i]); |
397 SkASSERT(heapEntry != NULL); | 396 SkASSERT(heapEntry != NULL); |
398 heapEntry->addReferences(fOwnerCount); | 397 heapEntry->addReferences(fOwnerCount); |
399 } | 398 } |
400 } | 399 } |
401 fDeferAddingOwners = false; | 400 fDeferAddingOwners = false; |
402 fDeferredEntries.reset(); | 401 fDeferredEntries.reset(); |
403 } | 402 } |
OLD | NEW |