Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap ) { | 63 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap ) { |
| 64 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); | 64 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); |
| 65 SkBitmap* result = (SkBitmap*)contextBitmap; | 65 SkBitmap* result = (SkBitmap*)contextBitmap; |
| 66 | 66 |
| 67 *result = rec.fBitmap; | 67 *result = rec.fBitmap; |
| 68 result->lockPixels(); | 68 result->lockPixels(); |
| 69 return SkToBool(result->getPixels()); | 69 return SkToBool(result->getPixels()); |
| 70 } | 70 } |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc aleY, | 73 #define CHECK_LOCAL(localCache, localName, globalName, args...) \ |
| 74 SkBitmap* result) { | 74 (localCache) ? localCache->localName(args) : SkResourceCache::globalName(arg s) |
| 75 | |
| 76 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc aleY, SkBitmap* result, | |
| 77 SkResourceCache* localCache) { | |
| 75 if (0 == invScaleX || 0 == invScaleY) { | 78 if (0 == invScaleX || 0 == invScaleY) { |
| 76 // degenerate, and the key we use for mipmaps | 79 // degenerate, and the key we use for mipmaps |
| 77 return false; | 80 return false; |
| 78 } | 81 } |
| 79 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src)); | 82 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src)); |
| 80 return SkResourceCache::Find(key, BitmapRec::Visitor, result); | 83 |
| 84 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result); | |
|
danakj
2014/09/16 15:26:27
This is really awkward to read :(
Tho, given you
reed1
2014/09/16 17:31:12
I find it very nice for calls sites that want to a
| |
| 81 } | 85 } |
| 82 | 86 |
| 83 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca leY, | 87 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca leY, |
| 84 const SkBitmap& result) { | 88 const SkBitmap& result, SkResourceCache* localCache) { |
| 85 if (0 == invScaleX || 0 == invScaleY) { | 89 if (0 == invScaleX || 0 == invScaleY) { |
| 86 // degenerate, and the key we use for mipmaps | 90 // degenerate, and the key we use for mipmaps |
| 87 return; | 91 return; |
| 88 } | 92 } |
| 89 SkASSERT(result.isImmutable()); | 93 SkASSERT(result.isImmutable()); |
| 90 SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX , invScaleY, | 94 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, in vScaleY, |
| 91 get_bounds_from_bitmap(src), res ult))); | 95 get_bounds_from_bitmap(src), result) ); |
| 96 CHECK_LOCAL(localCache, add, Add, rec); | |
| 92 } | 97 } |
| 93 | 98 |
| 94 bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result ) { | 99 bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result , |
| 100 SkResourceCache* localCache) { | |
| 95 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); | 101 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); |
| 96 return SkResourceCache::Find(key, BitmapRec::Visitor, result); | 102 |
| 103 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result); | |
| 97 } | 104 } |
| 98 | 105 |
| 99 bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r esult) { | 106 bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r esult, |
| 107 SkResourceCache* localCache) { | |
| 100 SkASSERT(result.isImmutable()); | 108 SkASSERT(result.isImmutable()); |
| 101 | 109 |
| 102 if (subset.isEmpty() | 110 if (subset.isEmpty() |
| 103 || subset.top() < 0 | 111 || subset.top() < 0 |
| 104 || subset.left() < 0 | 112 || subset.left() < 0 |
| 105 || result.width() != subset.width() | 113 || result.width() != subset.width() |
| 106 || result.height() != subset.height()) { | 114 || result.height() != subset.height()) { |
| 107 return false; | 115 return false; |
| 108 } else { | 116 } else { |
| 109 SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar 1, | 117 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, s ubset, result)); |
| 110 subset, result))); | |
| 111 | 118 |
| 119 CHECK_LOCAL(localCache, add, Add, rec); | |
| 112 return true; | 120 return true; |
| 113 } | 121 } |
| 114 } | 122 } |
| 115 //////////////////////////////////////////////////////////////////////////////// ////////// | 123 //////////////////////////////////////////////////////////////////////////////// ////////// |
| 116 | 124 |
| 117 struct MipMapRec : public SkResourceCache::Rec { | 125 struct MipMapRec : public SkResourceCache::Rec { |
| 118 MipMapRec(const SkBitmap& src, const SkMipMap* result) | 126 MipMapRec(const SkBitmap& src, const SkMipMap* result) |
| 119 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) | 127 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) |
| 120 , fMipMap(SkRef(result)) | 128 , fMipMap(SkRef(result)) |
| 121 {} | 129 {} |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 148 } | 156 } |
| 149 return result; | 157 return result; |
| 150 } | 158 } |
| 151 | 159 |
| 152 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) { | 160 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) { |
| 153 if (result) { | 161 if (result) { |
| 154 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result))); | 162 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result))); |
| 155 } | 163 } |
| 156 } | 164 } |
| 157 | 165 |
| OLD | NEW |