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

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

Issue 668223002: SkResourceCache::Key namespace support. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused SkPictureShader headers 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/ImageCacheTest.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 "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkResourceCache.h" 9 #include "SkResourceCache.h"
10 #include "SkMipMap.h" 10 #include "SkMipMap.h"
11 #include "SkPixelRef.h" 11 #include "SkPixelRef.h"
12 12
13 #include <stddef.h>
14
13 // This can be defined by the caller's build system 15 // This can be defined by the caller's build system
14 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE 16 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE
15 17
16 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 18 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT
17 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024 19 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024
18 #endif 20 #endif
19 21
20 #ifndef SK_DEFAULT_IMAGE_CACHE_LIMIT 22 #ifndef SK_DEFAULT_IMAGE_CACHE_LIMIT
21 #define SK_DEFAULT_IMAGE_CACHE_LIMIT (2 * 1024 * 1024) 23 #define SK_DEFAULT_IMAGE_CACHE_LIMIT (2 * 1024 * 1024)
22 #endif 24 #endif
23 25
24 void SkResourceCache::Key::init(size_t length) { 26 void SkResourceCache::Key::init(void* nameSpace, size_t length) {
25 SkASSERT(SkAlign4(length) == length); 27 SkASSERT(SkAlign4(length) == length);
26 // 2 is fCount32 and fHash 28
27 fCount32 = SkToS32(2 + (length >> 2)); 29 // fCount32 and fHash are not hashed
28 // skip both of our fields whe computing the murmur 30 static const int kUnhashedLocal32s = 2;
29 fHash = SkChecksum::Murmur3(this->as32() + 2, (fCount32 - 2) << 2); 31 static const int kLocal32s = kUnhashedLocal32s + (sizeof(fNamespace) >> 2);
32
33 SK_COMPILE_ASSERT(sizeof(Key) == (kLocal32s << 2), unaccounted_key_locals);
34 SK_COMPILE_ASSERT(sizeof(Key) == offsetof(Key, fNamespace) + sizeof(fNamespa ce),
35 namespace_field_must_be_last);
36
37 fCount32 = SkToS32(kLocal32s + (length >> 2));
38 fNamespace = nameSpace;
39 // skip unhashed fields when computing the murmur
40 fHash = SkChecksum::Murmur3(this->as32() + kUnhashedLocal32s,
41 (fCount32 - kUnhashedLocal32s) << 2);
30 } 42 }
31 43
32 #include "SkTDynamicHash.h" 44 #include "SkTDynamicHash.h"
33 45
34 class SkResourceCache::Hash : 46 class SkResourceCache::Hash :
35 public SkTDynamicHash<SkResourceCache::Rec, SkResourceCache::Key> {}; 47 public SkTDynamicHash<SkResourceCache::Rec, SkResourceCache::Key> {};
36 48
37 49
38 /////////////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////////////
39 51
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 533 }
522 534
523 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { 535 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) {
524 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); 536 return SkResourceCache::SetSingleAllocationByteLimit(newLimit);
525 } 537 }
526 538
527 void SkGraphics::PurgeResourceCache() { 539 void SkGraphics::PurgeResourceCache() {
528 return SkResourceCache::PurgeAll(); 540 return SkResourceCache::PurgeAll();
529 } 541 }
530 542
OLDNEW
« no previous file with comments | « src/core/SkResourceCache.h ('k') | tests/ImageCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698