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

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

Issue 592843003: Add SkCachedData and use it for SkMipMap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 2 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
« no previous file with comments | « src/core/SkResourceCache.h ('k') | tests/CachedDataTest.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 * 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 "SkCachedData.h"
8 #include "SkChecksum.h" 9 #include "SkChecksum.h"
9 #include "SkResourceCache.h" 10 #include "SkResourceCache.h"
10 #include "SkMipMap.h" 11 #include "SkMipMap.h"
11 #include "SkPixelRef.h" 12 #include "SkPixelRef.h"
12 13
13 // This can be defined by the caller's build system 14 // This can be defined by the caller's build system
14 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE 15 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE
15 16
16 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 17 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT
17 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024 18 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 257
257 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { 258 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
258 size_t prevLimit = fTotalByteLimit; 259 size_t prevLimit = fTotalByteLimit;
259 fTotalByteLimit = newLimit; 260 fTotalByteLimit = newLimit;
260 if (newLimit < prevLimit) { 261 if (newLimit < prevLimit) {
261 this->purgeAsNeeded(); 262 this->purgeAsNeeded();
262 } 263 }
263 return prevLimit; 264 return prevLimit;
264 } 265 }
265 266
267 SkCachedData* SkResourceCache::newCachedData(size_t bytes) {
268 if (fDiscardableFactory) {
269 SkDiscardableMemory* dm = fDiscardableFactory(bytes);
270 return dm ? SkNEW_ARGS(SkCachedData, (bytes, dm)) : NULL;
271 } else {
272 return SkNEW_ARGS(SkCachedData, (sk_malloc_throw(bytes), bytes));
273 }
274 }
275
266 /////////////////////////////////////////////////////////////////////////////// 276 ///////////////////////////////////////////////////////////////////////////////
267 277
268 void SkResourceCache::detach(Rec* rec) { 278 void SkResourceCache::detach(Rec* rec) {
269 Rec* prev = rec->fPrev; 279 Rec* prev = rec->fPrev;
270 Rec* next = rec->fNext; 280 Rec* next = rec->fNext;
271 281
272 if (!prev) { 282 if (!prev) {
273 SkASSERT(fHead == rec); 283 SkASSERT(fHead == rec);
274 fHead = next; 284 fHead = next;
275 } else { 285 } else {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 SkResourceCache::DiscardableFactory SkResourceCache::GetDiscardableFactory() { 445 SkResourceCache::DiscardableFactory SkResourceCache::GetDiscardableFactory() {
436 SkAutoMutexAcquire am(gMutex); 446 SkAutoMutexAcquire am(gMutex);
437 return get_cache()->discardableFactory(); 447 return get_cache()->discardableFactory();
438 } 448 }
439 449
440 SkBitmap::Allocator* SkResourceCache::GetAllocator() { 450 SkBitmap::Allocator* SkResourceCache::GetAllocator() {
441 SkAutoMutexAcquire am(gMutex); 451 SkAutoMutexAcquire am(gMutex);
442 return get_cache()->allocator(); 452 return get_cache()->allocator();
443 } 453 }
444 454
455 SkCachedData* SkResourceCache::NewCachedData(size_t bytes) {
456 SkAutoMutexAcquire am(gMutex);
457 return get_cache()->newCachedData(bytes);
458 }
459
445 void SkResourceCache::Dump() { 460 void SkResourceCache::Dump() {
446 SkAutoMutexAcquire am(gMutex); 461 SkAutoMutexAcquire am(gMutex);
447 get_cache()->dump(); 462 get_cache()->dump();
448 } 463 }
449 464
450 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) { 465 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) {
451 SkAutoMutexAcquire am(gMutex); 466 SkAutoMutexAcquire am(gMutex);
452 return get_cache()->setSingleAllocationByteLimit(size); 467 return get_cache()->setSingleAllocationByteLimit(size);
453 } 468 }
454 469
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 } 508 }
494 509
495 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { 510 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) {
496 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); 511 return SkResourceCache::SetSingleAllocationByteLimit(newLimit);
497 } 512 }
498 513
499 void SkGraphics::PurgeResourceCache() { 514 void SkGraphics::PurgeResourceCache() {
500 return SkResourceCache::PurgeAll(); 515 return SkResourceCache::PurgeAll();
501 } 516 }
502 517
OLDNEW
« no previous file with comments | « src/core/SkResourceCache.h ('k') | tests/CachedDataTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698