| 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 "SkScaledImageCache.h" | 8 #include "SkScaledImageCache.h" |
| 9 #include "SkMipMap.h" | 9 #include "SkMipMap.h" |
| 10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 Rec(const Key& key, const SkMipMap* mip) : fKey(key) { | 109 Rec(const Key& key, const SkMipMap* mip) : fKey(key) { |
| 110 fLockCount = 1; | 110 fLockCount = 1; |
| 111 fMip = mip; | 111 fMip = mip; |
| 112 mip->ref(); | 112 mip->ref(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 ~Rec() { | 115 ~Rec() { |
| 116 SkSafeUnref(fMip); | 116 SkSafeUnref(fMip); |
| 117 } | 117 } |
| 118 | 118 |
| 119 static const Key& GetKey(const Rec& rec) { return rec.fKey; } |
| 120 static uint32_t Hash(const Key& key) { return key.fHash; } |
| 121 |
| 119 size_t bytesUsed() const { | 122 size_t bytesUsed() const { |
| 120 return fMip ? fMip->getSize() : fBitmap.getSize(); | 123 return fMip ? fMip->getSize() : fBitmap.getSize(); |
| 121 } | 124 } |
| 122 | 125 |
| 123 Rec* fNext; | 126 Rec* fNext; |
| 124 Rec* fPrev; | 127 Rec* fPrev; |
| 125 | 128 |
| 126 // this guy wants to be 64bit aligned | 129 // this guy wants to be 64bit aligned |
| 127 Key fKey; | 130 Key fKey; |
| 128 | 131 |
| 129 int32_t fLockCount; | 132 int32_t fLockCount; |
| 130 | 133 |
| 131 // we use either fBitmap or fMip, but not both | 134 // we use either fBitmap or fMip, but not both |
| 132 SkBitmap fBitmap; | 135 SkBitmap fBitmap; |
| 133 const SkMipMap* fMip; | 136 const SkMipMap* fMip; |
| 134 }; | 137 }; |
| 135 | 138 |
| 136 #include "SkTDynamicHash.h" | 139 #include "SkTDynamicHash.h" |
| 137 | 140 |
| 138 namespace { // can't use static functions w/ template parameters | 141 class SkScaledImageCache::Hash : |
| 139 const SkScaledImageCache::Key& key_from_rec(const SkScaledImageCache::Rec& rec)
{ | 142 public SkTDynamicHash<SkScaledImageCache::Rec, SkScaledImageCache::Key> {}; |
| 140 return rec.fKey; | |
| 141 } | |
| 142 | |
| 143 uint32_t hash_from_key(const SkScaledImageCache::Key& key) { | |
| 144 return key.fHash; | |
| 145 } | |
| 146 | |
| 147 } // namespace | |
| 148 | |
| 149 class SkScaledImageCache::Hash : public SkTDynamicHash<SkScaledImageCache::Rec, | |
| 150 SkScaledImageCache::Key, | |
| 151 key_from_rec, | |
| 152 hash_from_key> {}; | |
| 153 | 143 |
| 154 | 144 |
| 155 /////////////////////////////////////////////////////////////////////////////// | 145 /////////////////////////////////////////////////////////////////////////////// |
| 156 | 146 |
| 157 // experimental hash to speed things up | 147 // experimental hash to speed things up |
| 158 #define USE_HASH | 148 #define USE_HASH |
| 159 | 149 |
| 160 #if !defined(USE_HASH) | 150 #if !defined(USE_HASH) |
| 161 static inline SkScaledImageCache::Rec* find_rec_in_list( | 151 static inline SkScaledImageCache::Rec* find_rec_in_list( |
| 162 SkScaledImageCache::Rec* head, const Key & key) { | 152 SkScaledImageCache::Rec* head, const Key & key) { |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 return SkScaledImageCache::GetBytesUsed(); | 776 return SkScaledImageCache::GetBytesUsed(); |
| 787 } | 777 } |
| 788 | 778 |
| 789 size_t SkGraphics::GetImageCacheByteLimit() { | 779 size_t SkGraphics::GetImageCacheByteLimit() { |
| 790 return SkScaledImageCache::GetByteLimit(); | 780 return SkScaledImageCache::GetByteLimit(); |
| 791 } | 781 } |
| 792 | 782 |
| 793 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { | 783 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { |
| 794 return SkScaledImageCache::SetByteLimit(newLimit); | 784 return SkScaledImageCache::SetByteLimit(newLimit); |
| 795 } | 785 } |
| OLD | NEW |