OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCachedData.h" | 8 #include "SkCachedData.h" |
9 #include "SkDiscardableMemory.h" | 9 #include "SkDiscardableMemory.h" |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 switch (fStorageType) { | 144 switch (fStorageType) { |
145 case kMalloc_StorageType: | 145 case kMalloc_StorageType: |
146 this->setData(fStorage.fMalloc); | 146 this->setData(fStorage.fMalloc); |
147 break; | 147 break; |
148 case kDiscardableMemory_StorageType: | 148 case kDiscardableMemory_StorageType: |
149 if (fStorage.fDM->lock()) { | 149 if (fStorage.fDM->lock()) { |
150 void* ptr = fStorage.fDM->data(); | 150 void* ptr = fStorage.fDM->data(); |
151 SkASSERT(ptr); | 151 SkASSERT(ptr); |
152 this->setData(ptr); | 152 this->setData(ptr); |
153 } else { | 153 } else { |
154 this->setData(NULL); // signal failure to lock, contents are g
one | 154 this->setData(nullptr); // signal failure to lock, contents ar
e gone |
155 } | 155 } |
156 break; | 156 break; |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 void SkCachedData::inMutexUnlock() { | 160 void SkCachedData::inMutexUnlock() { |
161 fMutex.assertHeld(); | 161 fMutex.assertHeld(); |
162 | 162 |
163 SkASSERT(fIsLocked); | 163 SkASSERT(fIsLocked); |
164 fIsLocked = false; | 164 fIsLocked = false; |
165 | 165 |
166 switch (fStorageType) { | 166 switch (fStorageType) { |
167 case kMalloc_StorageType: | 167 case kMalloc_StorageType: |
168 // nothing to do/check | 168 // nothing to do/check |
169 break; | 169 break; |
170 case kDiscardableMemory_StorageType: | 170 case kDiscardableMemory_StorageType: |
171 if (fData) { // did the previous lock succeed? | 171 if (fData) { // did the previous lock succeed? |
172 fStorage.fDM->unlock(); | 172 fStorage.fDM->unlock(); |
173 } | 173 } |
174 break; | 174 break; |
175 } | 175 } |
176 this->setData(NULL); // signal that we're in an unlocked state | 176 this->setData(nullptr); // signal that we're in an unlocked state |
177 } | 177 } |
178 | 178 |
179 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 179 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
180 | 180 |
181 #ifdef SK_DEBUG | 181 #ifdef SK_DEBUG |
182 void SkCachedData::validate() const { | 182 void SkCachedData::validate() const { |
183 if (fIsLocked) { | 183 if (fIsLocked) { |
184 SkASSERT((fInCache && fRefCnt > 1) || !fInCache); | 184 SkASSERT((fInCache && fRefCnt > 1) || !fInCache); |
185 switch (fStorageType) { | 185 switch (fStorageType) { |
186 case kMalloc_StorageType: | 186 case kMalloc_StorageType: |
187 SkASSERT(fData == fStorage.fMalloc); | 187 SkASSERT(fData == fStorage.fMalloc); |
188 break; | 188 break; |
189 case kDiscardableMemory_StorageType: | 189 case kDiscardableMemory_StorageType: |
190 // fData can be null or the actual value, depending if DM's lock
succeeded | 190 // fData can be null or the actual value, depending if DM's lock
succeeded |
191 break; | 191 break; |
192 } | 192 } |
193 } else { | 193 } else { |
194 SkASSERT((fInCache && 1 == fRefCnt) || (0 == fRefCnt)); | 194 SkASSERT((fInCache && 1 == fRefCnt) || (0 == fRefCnt)); |
195 SkASSERT(NULL == fData); | 195 SkASSERT(nullptr == fData); |
196 } | 196 } |
197 } | 197 } |
198 #endif | 198 #endif |
OLD | NEW |