OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkDiscardableMemory.h" | 8 #include "SkDiscardableMemory.h" |
9 #include "SkDiscardableMemoryPool.h" | 9 #include "SkDiscardableMemoryPool.h" |
10 #include "SkOnce.h" | 10 #include "SkLazyPtr.h" |
11 #include "SkTInternalLList.h" | 11 #include "SkTInternalLList.h" |
12 #include "SkThread.h" | 12 #include "SkThread.h" |
13 | 13 |
14 // Note: | 14 // Note: |
15 // A PoolDiscardableMemory is memory that is counted in a pool. | 15 // A PoolDiscardableMemory is memory that is counted in a pool. |
16 // A DiscardableMemoryPool is a pool of PoolDiscardableMemorys. | 16 // A DiscardableMemoryPool is a pool of PoolDiscardableMemorys. |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class PoolDiscardableMemory; | 20 class PoolDiscardableMemory; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 fBudget = budget; | 241 fBudget = budget; |
242 this->dumpDownTo(fBudget); | 242 this->dumpDownTo(fBudget); |
243 } | 243 } |
244 void DiscardableMemoryPool::dumpPool() { | 244 void DiscardableMemoryPool::dumpPool() { |
245 SkAutoMutexAcquire autoMutexAcquire(fMutex); | 245 SkAutoMutexAcquire autoMutexAcquire(fMutex); |
246 this->dumpDownTo(0); | 246 this->dumpDownTo(0); |
247 } | 247 } |
248 | 248 |
249 //////////////////////////////////////////////////////////////////////////////// | 249 //////////////////////////////////////////////////////////////////////////////// |
250 SK_DECLARE_STATIC_MUTEX(gMutex); | 250 SK_DECLARE_STATIC_MUTEX(gMutex); |
251 SkDiscardableMemoryPool* gPool = NULL; | 251 SkDiscardableMemoryPool* create_global_pool() { |
252 void create_global_pool(int) { | 252 return SkDiscardableMemoryPool::Create(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_
POOL_SIZE, |
253 SkASSERT(NULL == gPool); | 253 &gMutex); |
254 gPool = SkDiscardableMemoryPool::Create( | |
255 SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE, &gMutex); | |
256 } | 254 } |
257 void cleanup_global_pool() { | 255 |
258 gPool->unref(); | |
259 } | |
260 } // namespace | 256 } // namespace |
261 | 257 |
262 SkDiscardableMemoryPool* SkDiscardableMemoryPool::Create( | 258 SkDiscardableMemoryPool* SkDiscardableMemoryPool::Create(size_t size, SkBaseMute
x* mutex) { |
263 size_t size, SkBaseMutex* mutex) { | |
264 return SkNEW_ARGS(DiscardableMemoryPool, (size, mutex)); | 259 return SkNEW_ARGS(DiscardableMemoryPool, (size, mutex)); |
265 } | 260 } |
266 | 261 |
267 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { | 262 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { |
268 SK_DECLARE_STATIC_ONCE(create_pool_once); | 263 SK_DECLARE_STATIC_LAZY_PTR(SkDiscardableMemoryPool, global, create_global_po
ol); |
269 SkOnce(&create_pool_once, create_global_pool, 0, &cleanup_global_pool); | 264 return global.get(); |
270 SkASSERT(NULL != gPool); | |
271 return gPool; | |
272 } | 265 } |
273 | 266 |
274 // defined in SkImageGenerator.h | 267 // defined in SkImageGenerator.h |
275 void SkPurgeGlobalDiscardableMemoryPool() { | 268 void SkPurgeGlobalDiscardableMemoryPool() { |
276 SkGetGlobalDiscardableMemoryPool()->dumpPool(); | 269 SkGetGlobalDiscardableMemoryPool()->dumpPool(); |
277 } | 270 } |
278 //////////////////////////////////////////////////////////////////////////////// | 271 //////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |