| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 struct BitmapRec : public SkResourceCache::Rec { | 54 struct BitmapRec : public SkResourceCache::Rec { |
| 55 BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b
ounds, | 55 BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b
ounds, |
| 56 const SkBitmap& result) | 56 const SkBitmap& result) |
| 57 : fKey(genID, scaleX, scaleY, bounds) | 57 : fKey(genID, scaleX, scaleY, bounds) |
| 58 , fBitmap(result) | 58 , fBitmap(result) |
| 59 {} | 59 {} |
| 60 | 60 |
| 61 BitmapKey fKey; | 61 BitmapKey fKey; |
| 62 SkBitmap fBitmap; | 62 SkBitmap fBitmap; |
| 63 | 63 |
| 64 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } | 64 const Key& getKey() const SK_OVERRIDE { return fKey; } |
| 65 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap
.getSize(); } | 65 size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap.getSize
(); } |
| 66 | 66 |
| 67 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap
) { | 67 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap
) { |
| 68 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); | 68 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); |
| 69 SkBitmap* result = (SkBitmap*)contextBitmap; | 69 SkBitmap* result = (SkBitmap*)contextBitmap; |
| 70 | 70 |
| 71 *result = rec.fBitmap; | 71 *result = rec.fBitmap; |
| 72 result->lockPixels(); | 72 result->lockPixels(); |
| 73 return SkToBool(result->getPixels()); | 73 return SkToBool(result->getPixels()); |
| 74 } | 74 } |
| 75 }; | 75 }; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) | 132 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) |
| 133 , fMipMap(result) | 133 , fMipMap(result) |
| 134 { | 134 { |
| 135 fMipMap->attachToCacheAndRef(); | 135 fMipMap->attachToCacheAndRef(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 virtual ~MipMapRec() { | 138 virtual ~MipMapRec() { |
| 139 fMipMap->detachFromCacheAndUnref(); | 139 fMipMap->detachFromCacheAndUnref(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } | 142 const Key& getKey() const SK_OVERRIDE { return fKey; } |
| 143 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap
->size(); } | 143 size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap->size()
; } |
| 144 | 144 |
| 145 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) { | 145 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) { |
| 146 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); | 146 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); |
| 147 const SkMipMap* mm = SkRef(rec.fMipMap); | 147 const SkMipMap* mm = SkRef(rec.fMipMap); |
| 148 // the call to ref() above triggers a "lock" in the case of discardable
memory, | 148 // the call to ref() above triggers a "lock" in the case of discardable
memory, |
| 149 // which means we can now check for null (in case the lock failed). | 149 // which means we can now check for null (in case the lock failed). |
| 150 if (NULL == mm->data()) { | 150 if (NULL == mm->data()) { |
| 151 mm->unref(); // balance our call to ref() | 151 mm->unref(); // balance our call to ref() |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 178 | 178 |
| 179 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { | 179 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { |
| 180 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); | 180 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); |
| 181 if (mipmap) { | 181 if (mipmap) { |
| 182 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); | 182 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); |
| 183 CHECK_LOCAL(localCache, add, Add, rec); | 183 CHECK_LOCAL(localCache, add, Add, rec); |
| 184 } | 184 } |
| 185 return mipmap; | 185 return mipmap; |
| 186 } | 186 } |
| 187 | 187 |
| OLD | NEW |