OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
9 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 struct BitmapRec : public SkResourceCache::Rec { | 67 struct BitmapRec : public SkResourceCache::Rec { |
68 BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b
ounds, | 68 BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b
ounds, |
69 const SkBitmap& result) | 69 const SkBitmap& result) |
70 : fKey(genID, scaleX, scaleY, bounds) | 70 : fKey(genID, scaleX, scaleY, bounds) |
71 , fBitmap(result) | 71 , fBitmap(result) |
72 {} | 72 {} |
73 | 73 |
74 const Key& getKey() const override { return fKey; } | 74 const Key& getKey() const override { return fKey; } |
75 size_t bytesUsed() const override { return sizeof(fKey) + fBitmap.getSize();
} | 75 size_t bytesUsed() const override { return sizeof(fKey) + fBitmap.getSize();
} |
76 | 76 |
| 77 const char* getCategory() const override { return "bitmap"; } |
| 78 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { |
| 79 return fBitmap.pixelRef()->diagnostic_only_getDiscardable(); |
| 80 } |
| 81 |
77 static bool Finder(const SkResourceCache::Rec& baseRec, void* contextBitmap)
{ | 82 static bool Finder(const SkResourceCache::Rec& baseRec, void* contextBitmap)
{ |
78 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); | 83 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); |
79 SkBitmap* result = (SkBitmap*)contextBitmap; | 84 SkBitmap* result = (SkBitmap*)contextBitmap; |
80 | 85 |
81 *result = rec.fBitmap; | 86 *result = rec.fBitmap; |
82 result->lockPixels(); | 87 result->lockPixels(); |
83 return SkToBool(result->getPixels()); | 88 return SkToBool(result->getPixels()); |
84 } | 89 } |
85 | 90 |
86 private: | 91 private: |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 { | 185 { |
181 fMipMap->attachToCacheAndRef(); | 186 fMipMap->attachToCacheAndRef(); |
182 } | 187 } |
183 | 188 |
184 virtual ~MipMapRec() { | 189 virtual ~MipMapRec() { |
185 fMipMap->detachFromCacheAndUnref(); | 190 fMipMap->detachFromCacheAndUnref(); |
186 } | 191 } |
187 | 192 |
188 const Key& getKey() const override { return fKey; } | 193 const Key& getKey() const override { return fKey; } |
189 size_t bytesUsed() const override { return sizeof(fKey) + fMipMap->size(); } | 194 size_t bytesUsed() const override { return sizeof(fKey) + fMipMap->size(); } |
| 195 const char* getCategory() const override { return "mipmap"; } |
| 196 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { |
| 197 return fMipMap->diagnostic_only_getDiscardable(); |
| 198 } |
190 | 199 |
191 static bool Finder(const SkResourceCache::Rec& baseRec, void* contextMip) { | 200 static bool Finder(const SkResourceCache::Rec& baseRec, void* contextMip) { |
192 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); | 201 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); |
193 const SkMipMap* mm = SkRef(rec.fMipMap); | 202 const SkMipMap* mm = SkRef(rec.fMipMap); |
194 // the call to ref() above triggers a "lock" in the case of discardable
memory, | 203 // the call to ref() above triggers a "lock" in the case of discardable
memory, |
195 // which means we can now check for null (in case the lock failed). | 204 // which means we can now check for null (in case the lock failed). |
196 if (NULL == mm->data()) { | 205 if (NULL == mm->data()) { |
197 mm->unref(); // balance our call to ref() | 206 mm->unref(); // balance our call to ref() |
198 return false; | 207 return false; |
199 } | 208 } |
(...skipping 25 matching lines...) Expand all Loading... |
225 | 234 |
226 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { | 235 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { |
227 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); | 236 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); |
228 if (mipmap) { | 237 if (mipmap) { |
229 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); | 238 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); |
230 CHECK_LOCAL(localCache, add, Add, rec); | 239 CHECK_LOCAL(localCache, add, Add, rec); |
231 src.pixelRef()->notifyAddedToCache(); | 240 src.pixelRef()->notifyAddedToCache(); |
232 } | 241 } |
233 return mipmap; | 242 return mipmap; |
234 } | 243 } |
OLD | NEW |