OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 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 | 9 |
10 #include "SkGradientBitmapCache.h" | 10 #include "SkGradientBitmapCache.h" |
11 | 11 |
12 struct SkGradientBitmapCache::Entry { | 12 struct SkGradientBitmapCache::Entry { |
13 Entry* fPrev; | 13 Entry* fPrev; |
14 Entry* fNext; | 14 Entry* fNext; |
15 | 15 |
16 void* fBuffer; | 16 void* fBuffer; |
17 size_t fSize; | 17 size_t fSize; |
18 SkBitmap fBitmap; | 18 SkBitmap fBitmap; |
19 | 19 |
20 Entry(const void* buffer, size_t size, const SkBitmap& bm) | 20 Entry(const void* buffer, size_t size, const SkBitmap& bm) |
21 : fPrev(NULL), | 21 : fPrev(nullptr), |
22 fNext(NULL), | 22 fNext(nullptr), |
23 fBitmap(bm) { | 23 fBitmap(bm) { |
24 fBuffer = sk_malloc_throw(size); | 24 fBuffer = sk_malloc_throw(size); |
25 fSize = size; | 25 fSize = size; |
26 memcpy(fBuffer, buffer, size); | 26 memcpy(fBuffer, buffer, size); |
27 } | 27 } |
28 | 28 |
29 ~Entry() { sk_free(fBuffer); } | 29 ~Entry() { sk_free(fBuffer); } |
30 | 30 |
31 bool equals(const void* buffer, size_t size) const { | 31 bool equals(const void* buffer, size_t size) const { |
32 return (fSize == size) && !memcmp(fBuffer, buffer, size); | 32 return (fSize == size) && !memcmp(fBuffer, buffer, size); |
33 } | 33 } |
34 }; | 34 }; |
35 | 35 |
36 SkGradientBitmapCache::SkGradientBitmapCache(int max) : fMaxEntries(max) { | 36 SkGradientBitmapCache::SkGradientBitmapCache(int max) : fMaxEntries(max) { |
37 fEntryCount = 0; | 37 fEntryCount = 0; |
38 fHead = fTail = NULL; | 38 fHead = fTail = nullptr; |
39 | 39 |
40 this->validate(); | 40 this->validate(); |
41 } | 41 } |
42 | 42 |
43 SkGradientBitmapCache::~SkGradientBitmapCache() { | 43 SkGradientBitmapCache::~SkGradientBitmapCache() { |
44 this->validate(); | 44 this->validate(); |
45 | 45 |
46 Entry* entry = fHead; | 46 Entry* entry = fHead; |
47 while (entry) { | 47 while (entry) { |
48 Entry* next = entry->fNext; | 48 Entry* next = entry->fNext; |
(...skipping 14 matching lines...) Expand all Loading... |
63 SkASSERT(fTail != entry); | 63 SkASSERT(fTail != entry); |
64 entry->fNext->fPrev = entry->fPrev; | 64 entry->fNext->fPrev = entry->fPrev; |
65 } else { | 65 } else { |
66 SkASSERT(fTail == entry); | 66 SkASSERT(fTail == entry); |
67 fTail = entry->fPrev; | 67 fTail = entry->fPrev; |
68 } | 68 } |
69 return entry; | 69 return entry; |
70 } | 70 } |
71 | 71 |
72 void SkGradientBitmapCache::attachToHead(Entry* entry) const { | 72 void SkGradientBitmapCache::attachToHead(Entry* entry) const { |
73 entry->fPrev = NULL; | 73 entry->fPrev = nullptr; |
74 entry->fNext = fHead; | 74 entry->fNext = fHead; |
75 if (fHead) { | 75 if (fHead) { |
76 fHead->fPrev = entry; | 76 fHead->fPrev = entry; |
77 } else { | 77 } else { |
78 fTail = entry; | 78 fTail = entry; |
79 } | 79 } |
80 fHead = entry; | 80 fHead = entry; |
81 } | 81 } |
82 | 82 |
83 bool SkGradientBitmapCache::find(const void* buffer, size_t size, SkBitmap* bm)
const { | 83 bool SkGradientBitmapCache::find(const void* buffer, size_t size, SkBitmap* bm)
const { |
(...skipping 30 matching lines...) Expand all Loading... |
114 } | 114 } |
115 | 115 |
116 /////////////////////////////////////////////////////////////////////////////// | 116 /////////////////////////////////////////////////////////////////////////////// |
117 | 117 |
118 #ifdef SK_DEBUG | 118 #ifdef SK_DEBUG |
119 | 119 |
120 void SkGradientBitmapCache::validate() const { | 120 void SkGradientBitmapCache::validate() const { |
121 SkASSERT(fEntryCount >= 0 && fEntryCount <= fMaxEntries); | 121 SkASSERT(fEntryCount >= 0 && fEntryCount <= fMaxEntries); |
122 | 122 |
123 if (fEntryCount > 0) { | 123 if (fEntryCount > 0) { |
124 SkASSERT(NULL == fHead->fPrev); | 124 SkASSERT(nullptr == fHead->fPrev); |
125 SkASSERT(NULL == fTail->fNext); | 125 SkASSERT(nullptr == fTail->fNext); |
126 | 126 |
127 if (fEntryCount == 1) { | 127 if (fEntryCount == 1) { |
128 SkASSERT(fHead == fTail); | 128 SkASSERT(fHead == fTail); |
129 } else { | 129 } else { |
130 SkASSERT(fHead != fTail); | 130 SkASSERT(fHead != fTail); |
131 } | 131 } |
132 | 132 |
133 Entry* entry = fHead; | 133 Entry* entry = fHead; |
134 int count = 0; | 134 int count = 0; |
135 while (entry) { | 135 while (entry) { |
136 count += 1; | 136 count += 1; |
137 entry = entry->fNext; | 137 entry = entry->fNext; |
138 } | 138 } |
139 SkASSERT(count == fEntryCount); | 139 SkASSERT(count == fEntryCount); |
140 | 140 |
141 entry = fTail; | 141 entry = fTail; |
142 while (entry) { | 142 while (entry) { |
143 count -= 1; | 143 count -= 1; |
144 entry = entry->fPrev; | 144 entry = entry->fPrev; |
145 } | 145 } |
146 SkASSERT(0 == count); | 146 SkASSERT(0 == count); |
147 } else { | 147 } else { |
148 SkASSERT(NULL == fHead); | 148 SkASSERT(nullptr == fHead); |
149 SkASSERT(NULL == fTail); | 149 SkASSERT(nullptr == fTail); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 #endif | 153 #endif |
OLD | NEW |