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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); | 108 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); |
109 } | 109 } |
110 | 110 |
111 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
leY, | 111 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
leY, |
112 const SkBitmap& result, SkResourceCache* localCache) { | 112 const SkBitmap& result, SkResourceCache* localCache) { |
113 if (0 == invScaleX || 0 == invScaleY) { | 113 if (0 == invScaleX || 0 == invScaleY) { |
114 // degenerate, and the key we use for mipmaps | 114 // degenerate, and the key we use for mipmaps |
115 return; | 115 return; |
116 } | 116 } |
117 SkASSERT(result.isImmutable()); | 117 SkASSERT(result.isImmutable()); |
118 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, in
vScaleY, | 118 BitmapRec* rec = new BitmapRec(src.getGenerationID(), invScaleX, invScaleY, |
119 get_bounds_from_bitmap(src), result)
); | 119 get_bounds_from_bitmap(src), result); |
120 CHECK_LOCAL(localCache, add, Add, rec); | 120 CHECK_LOCAL(localCache, add, Add, rec); |
121 src.pixelRef()->notifyAddedToCache(); | 121 src.pixelRef()->notifyAddedToCache(); |
122 } | 122 } |
123 | 123 |
124 bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result
, | 124 bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result
, |
125 SkResourceCache* localCache) { | 125 SkResourceCache* localCache) { |
126 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); | 126 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); |
127 | 127 |
128 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); | 128 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); |
129 } | 129 } |
130 | 130 |
131 bool SkBitmapCache::Add(SkPixelRef* pr, const SkIRect& subset, const SkBitmap& r
esult, | 131 bool SkBitmapCache::Add(SkPixelRef* pr, const SkIRect& subset, const SkBitmap& r
esult, |
132 SkResourceCache* localCache) { | 132 SkResourceCache* localCache) { |
133 SkASSERT(result.isImmutable()); | 133 SkASSERT(result.isImmutable()); |
134 | 134 |
135 if (subset.isEmpty() | 135 if (subset.isEmpty() |
136 || subset.top() < 0 | 136 || subset.top() < 0 |
137 || subset.left() < 0 | 137 || subset.left() < 0 |
138 || result.width() != subset.width() | 138 || result.width() != subset.width() |
139 || result.height() != subset.height()) { | 139 || result.height() != subset.height()) { |
140 return false; | 140 return false; |
141 } else { | 141 } else { |
142 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (pr->getGenerationID(), 1, 1, sub
set, result)); | 142 BitmapRec* rec = new BitmapRec(pr->getGenerationID(), 1, 1, subset, resu
lt); |
143 | 143 |
144 CHECK_LOCAL(localCache, add, Add, rec); | 144 CHECK_LOCAL(localCache, add, Add, rec); |
145 pr->notifyAddedToCache(); | 145 pr->notifyAddedToCache(); |
146 return true; | 146 return true; |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 bool SkBitmapCache::Find(uint32_t genID, SkBitmap* result, SkResourceCache* loca
lCache) { | 150 bool SkBitmapCache::Find(uint32_t genID, SkBitmap* result, SkResourceCache* loca
lCache) { |
151 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeEmpty()); | 151 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeEmpty()); |
152 | 152 |
153 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); | 153 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); |
154 } | 154 } |
155 | 155 |
156 void SkBitmapCache::Add(uint32_t genID, const SkBitmap& result, SkResourceCache*
localCache) { | 156 void SkBitmapCache::Add(uint32_t genID, const SkBitmap& result, SkResourceCache*
localCache) { |
157 SkASSERT(result.isImmutable()); | 157 SkASSERT(result.isImmutable()); |
158 | 158 |
159 BitmapRec* rec = SkNEW_ARGS(BitmapRec, (genID, 1, 1, SkIRect::MakeEmpty(), r
esult)); | 159 BitmapRec* rec = new BitmapRec(genID, 1, 1, SkIRect::MakeEmpty(), result); |
160 | 160 |
161 CHECK_LOCAL(localCache, add, Add, rec); | 161 CHECK_LOCAL(localCache, add, Add, rec); |
162 } | 162 } |
163 | 163 |
164 ////////////////////////////////////////////////////////////////////////////////
////////// | 164 ////////////////////////////////////////////////////////////////////////////////
////////// |
165 ////////////////////////////////////////////////////////////////////////////////
////////// | 165 ////////////////////////////////////////////////////////////////////////////////
////////// |
166 | 166 |
167 namespace { | 167 namespace { |
168 static unsigned gMipMapKeyNamespaceLabel; | 168 static unsigned gMipMapKeyNamespaceLabel; |
169 | 169 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 228 } |
229 | 229 |
230 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
{ | 230 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
{ |
231 return localCache ? localCache->GetDiscardableFactory() | 231 return localCache ? localCache->GetDiscardableFactory() |
232 : SkResourceCache::GetDiscardableFactory(); | 232 : SkResourceCache::GetDiscardableFactory(); |
233 } | 233 } |
234 | 234 |
235 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { | 235 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { |
236 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); | 236 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); |
237 if (mipmap) { | 237 if (mipmap) { |
238 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); | 238 MipMapRec* rec = new MipMapRec(src, mipmap); |
239 CHECK_LOCAL(localCache, add, Add, rec); | 239 CHECK_LOCAL(localCache, add, Add, rec); |
240 src.pixelRef()->notifyAddedToCache(); | 240 src.pixelRef()->notifyAddedToCache(); |
241 } | 241 } |
242 return mipmap; | 242 return mipmap; |
243 } | 243 } |
OLD | NEW |