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

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

Issue 378413002: Revert of Slim Skia down to just one murmur3 implementation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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/SkImageFilter.cpp ('k') | no next file » | 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"
9 #include "SkScaledImageCache.h" 8 #include "SkScaledImageCache.h"
10 #include "SkMipMap.h" 9 #include "SkMipMap.h"
11 #include "SkPixelRef.h" 10 #include "SkPixelRef.h"
12 #include "SkRect.h" 11 #include "SkRect.h"
13 12
14 // This can be defined by the caller's build system 13 // This can be defined by the caller's build system
15 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE 14 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE
16 15
17 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 16 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT
18 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024 17 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024
19 #endif 18 #endif
20 19
21 #ifndef SK_DEFAULT_IMAGE_CACHE_LIMIT 20 #ifndef SK_DEFAULT_IMAGE_CACHE_LIMIT
22 #define SK_DEFAULT_IMAGE_CACHE_LIMIT (2 * 1024 * 1024) 21 #define SK_DEFAULT_IMAGE_CACHE_LIMIT (2 * 1024 * 1024)
23 #endif 22 #endif
24 23
25 static inline SkScaledImageCache::ID* rec_to_id(SkScaledImageCache::Rec* rec) { 24 static inline SkScaledImageCache::ID* rec_to_id(SkScaledImageCache::Rec* rec) {
26 return reinterpret_cast<SkScaledImageCache::ID*>(rec); 25 return reinterpret_cast<SkScaledImageCache::ID*>(rec);
27 } 26 }
28 27
29 static inline SkScaledImageCache::Rec* id_to_rec(SkScaledImageCache::ID* id) { 28 static inline SkScaledImageCache::Rec* id_to_rec(SkScaledImageCache::ID* id) {
30 return reinterpret_cast<SkScaledImageCache::Rec*>(id); 29 return reinterpret_cast<SkScaledImageCache::Rec*>(id);
31 } 30 }
32 31
32 // Implemented from en.wikipedia.org/wiki/MurmurHash.
33 static uint32_t compute_hash(const uint32_t data[], int count) {
34 uint32_t hash = 0;
35
36 for (int i = 0; i < count; ++i) {
37 uint32_t k = data[i];
38 k *= 0xcc9e2d51;
39 k = (k << 15) | (k >> 17);
40 k *= 0x1b873593;
41
42 hash ^= k;
43 hash = (hash << 13) | (hash >> 19);
44 hash *= 5;
45 hash += 0xe6546b64;
46 }
47
48 // hash ^= size;
49 hash ^= hash >> 16;
50 hash *= 0x85ebca6b;
51 hash ^= hash >> 13;
52 hash *= 0xc2b2ae35;
53 hash ^= hash >> 16;
54
55 return hash;
56 }
57
33 struct SkScaledImageCache::Key { 58 struct SkScaledImageCache::Key {
34 Key(uint32_t genID, 59 Key(uint32_t genID,
35 SkScalar scaleX, 60 SkScalar scaleX,
36 SkScalar scaleY, 61 SkScalar scaleY,
37 SkIRect bounds) 62 SkIRect bounds)
38 : fGenID(genID) 63 : fGenID(genID)
39 , fScaleX(scaleX) 64 , fScaleX(scaleX)
40 , fScaleY(scaleY) 65 , fScaleY(scaleY)
41 , fBounds(bounds) { 66 , fBounds(bounds) {
42 fHash = SkChecksum::Murmur3(&fGenID, 28); 67 fHash = compute_hash(&fGenID, 7);
43 } 68 }
44 69
45 bool operator<(const Key& other) const { 70 bool operator<(const Key& other) const {
46 const uint32_t* a = &fGenID; 71 const uint32_t* a = &fGenID;
47 const uint32_t* b = &other.fGenID; 72 const uint32_t* b = &other.fGenID;
48 for (int i = 0; i < 7; ++i) { 73 for (int i = 0; i < 7; ++i) {
49 if (a[i] < b[i]) { 74 if (a[i] < b[i]) {
50 return true; 75 return true;
51 } 76 }
52 if (a[i] > b[i]) { 77 if (a[i] > b[i]) {
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 return SkScaledImageCache::GetBytesUsed(); 786 return SkScaledImageCache::GetBytesUsed();
762 } 787 }
763 788
764 size_t SkGraphics::GetImageCacheByteLimit() { 789 size_t SkGraphics::GetImageCacheByteLimit() {
765 return SkScaledImageCache::GetByteLimit(); 790 return SkScaledImageCache::GetByteLimit();
766 } 791 }
767 792
768 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { 793 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) {
769 return SkScaledImageCache::SetByteLimit(newLimit); 794 return SkScaledImageCache::SetByteLimit(newLimit);
770 } 795 }
OLDNEW
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698