OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
| 8 #include "SkBitmapCache.h" |
8 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
9 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
10 #include "SkFilterProc.h" | 11 #include "SkFilterProc.h" |
11 #include "SkPaint.h" | 12 #include "SkPaint.h" |
12 #include "SkShader.h" // for tilemodes | 13 #include "SkShader.h" // for tilemodes |
13 #include "SkUtilsArm.h" | 14 #include "SkUtilsArm.h" |
14 #include "SkBitmapScaler.h" | 15 #include "SkBitmapScaler.h" |
15 #include "SkMipMap.h" | 16 #include "SkMipMap.h" |
16 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
17 #include "SkScaledImageCache.h" | |
18 #include "SkImageEncoder.h" | 18 #include "SkImageEncoder.h" |
19 | 19 |
20 #if !SK_ARM_NEON_IS_NONE | 20 #if !SK_ARM_NEON_IS_NONE |
21 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp | 21 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp |
22 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; | 22 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; |
23 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; | 23 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; |
24 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); | 24 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i
nt, uint16_t*); |
25 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); | 25 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i
nt, int, uint16_t*, int); |
26 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); | 26 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&,
int, int, uint16_t*, int); |
27 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); | 27 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3
2_t*, int, SkPMColor*); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // are close to -1 as well, since the flip doesn't require | 176 // are close to -1 as well, since the flip doesn't require |
177 // any fancy re-sampling... | 177 // any fancy re-sampling... |
178 | 178 |
179 // Set our filter level to low -- the only post-filtering this | 179 // Set our filter level to low -- the only post-filtering this |
180 // image might require is some interpolation if the translation | 180 // image might require is some interpolation if the translation |
181 // is fractional. | 181 // is fractional. |
182 fFilterLevel = SkPaint::kLow_FilterLevel; | 182 fFilterLevel = SkPaint::kLow_FilterLevel; |
183 return false; | 183 return false; |
184 } | 184 } |
185 | 185 |
186 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, | 186 fScaledCacheID = SkBitmapCache::FindAndLock(fOrigBitmap, invScaleX, invS
caleY, |
187 invScaleX, invScaleY, | 187 &fScaledBitmap); |
188 &fScaledBitmap); | |
189 if (fScaledCacheID) { | 188 if (fScaledCacheID) { |
190 fScaledBitmap.lockPixels(); | 189 fScaledBitmap.lockPixels(); |
191 if (!fScaledBitmap.getPixels()) { | 190 if (!fScaledBitmap.getPixels()) { |
192 fScaledBitmap.unlockPixels(); | 191 fScaledBitmap.unlockPixels(); |
193 // found a purged entry (discardablememory?), release it | 192 // found a purged entry (discardablememory?), release it |
194 SkScaledImageCache::Unlock(fScaledCacheID); | 193 SkScaledImageCache::Unlock(fScaledCacheID); |
195 fScaledCacheID = NULL; | 194 fScaledCacheID = NULL; |
196 // fall through to rebuild | 195 // fall through to rebuild |
197 } | 196 } |
198 } | 197 } |
(...skipping 10 matching lines...) Expand all Loading... |
209 dest_width, | 208 dest_width, |
210 dest_height, | 209 dest_height, |
211 SkScaledImageCache::GetAllocator())) { | 210 SkScaledImageCache::GetAllocator())) { |
212 // we failed to create fScaledBitmap, so just return and let | 211 // we failed to create fScaledBitmap, so just return and let |
213 // the scanline proc handle it. | 212 // the scanline proc handle it. |
214 return false; | 213 return false; |
215 | 214 |
216 } | 215 } |
217 | 216 |
218 SkASSERT(NULL != fScaledBitmap.getPixels()); | 217 SkASSERT(NULL != fScaledBitmap.getPixels()); |
219 fScaledCacheID = SkScaledImageCache::AddAndLock(fOrigBitmap, | 218 fScaledCacheID = SkBitmapCache::AddAndLock(fOrigBitmap, invScaleX, i
nvScaleY, |
220 invScaleX, | 219 fScaledBitmap); |
221 invScaleY, | |
222 fScaledBitmap); | |
223 if (!fScaledCacheID) { | 220 if (!fScaledCacheID) { |
224 fScaledBitmap.reset(); | 221 fScaledBitmap.reset(); |
225 return false; | 222 return false; |
226 } | 223 } |
227 SkASSERT(NULL != fScaledBitmap.getPixels()); | 224 SkASSERT(NULL != fScaledBitmap.getPixels()); |
228 } | 225 } |
229 | 226 |
230 SkASSERT(NULL != fScaledBitmap.getPixels()); | 227 SkASSERT(NULL != fScaledBitmap.getPixels()); |
231 fBitmap = &fScaledBitmap; | 228 fBitmap = &fScaledBitmap; |
232 | 229 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 276 |
280 /** | 277 /** |
281 * Medium quality means use a mipmap for down-scaling, and just bilper | 278 * Medium quality means use a mipmap for down-scaling, and just bilper |
282 * for upscaling. Since we're examining the inverse matrix, we look for | 279 * for upscaling. Since we're examining the inverse matrix, we look for |
283 * a scale > 1 to indicate down scaling by the CTM. | 280 * a scale > 1 to indicate down scaling by the CTM. |
284 */ | 281 */ |
285 if (scaleSqd > SK_Scalar1) { | 282 if (scaleSqd > SK_Scalar1) { |
286 const SkMipMap* mip = NULL; | 283 const SkMipMap* mip = NULL; |
287 | 284 |
288 SkASSERT(NULL == fScaledCacheID); | 285 SkASSERT(NULL == fScaledCacheID); |
289 fScaledCacheID = SkScaledImageCache::FindAndLockMip(fOrigBitmap, &mip); | 286 fScaledCacheID = SkMipMapCache::FindAndLock(fOrigBitmap, &mip); |
290 if (!fScaledCacheID) { | 287 if (!fScaledCacheID) { |
291 SkASSERT(NULL == mip); | 288 SkASSERT(NULL == mip); |
292 mip = SkMipMap::Build(fOrigBitmap); | 289 mip = SkMipMap::Build(fOrigBitmap); |
293 if (mip) { | 290 if (mip) { |
294 fScaledCacheID = SkScaledImageCache::AddAndLockMip(fOrigBitmap, | 291 fScaledCacheID = SkMipMapCache::AddAndLock(fOrigBitmap, mip); |
295 mip); | |
296 SkASSERT(mip->getRefCnt() > 1); | 292 SkASSERT(mip->getRefCnt() > 1); |
297 mip->unref(); // the cache took a ref | 293 mip->unref(); // the cache took a ref |
298 SkASSERT(fScaledCacheID); | 294 SkASSERT(fScaledCacheID); |
299 } | 295 } |
300 } else { | 296 } else { |
301 SkASSERT(mip); | 297 SkASSERT(mip); |
302 } | 298 } |
303 | 299 |
304 if (mip) { | 300 if (mip) { |
305 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); | 301 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 SkASSERT(NULL == fScaledCacheID); | 343 SkASSERT(NULL == fScaledCacheID); |
348 | 344 |
349 if (pr->isLocked() || !pr->implementsDecodeInto()) { | 345 if (pr->isLocked() || !pr->implementsDecodeInto()) { |
350 // fast-case, no need to look in our cache | 346 // fast-case, no need to look in our cache |
351 fScaledBitmap = fOrigBitmap; | 347 fScaledBitmap = fOrigBitmap; |
352 fScaledBitmap.lockPixels(); | 348 fScaledBitmap.lockPixels(); |
353 if (NULL == fScaledBitmap.getPixels()) { | 349 if (NULL == fScaledBitmap.getPixels()) { |
354 return false; | 350 return false; |
355 } | 351 } |
356 } else { | 352 } else { |
357 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, | 353 fScaledCacheID = SkBitmapCache::FindAndLock(fOrigBitmap, 1, 1, &fScaledB
itmap); |
358 SK_Scalar1, SK_Scalar1, | |
359 &fScaledBitmap); | |
360 if (fScaledCacheID) { | 354 if (fScaledCacheID) { |
361 fScaledBitmap.lockPixels(); | 355 fScaledBitmap.lockPixels(); |
362 if (!fScaledBitmap.getPixels()) { | 356 if (!fScaledBitmap.getPixels()) { |
363 fScaledBitmap.unlockPixels(); | 357 fScaledBitmap.unlockPixels(); |
364 // found a purged entry (discardablememory?), release it | 358 // found a purged entry (discardablememory?), release it |
365 SkScaledImageCache::Unlock(fScaledCacheID); | 359 SkScaledImageCache::Unlock(fScaledCacheID); |
366 fScaledCacheID = NULL; | 360 fScaledCacheID = NULL; |
367 // fall through to rebuild | 361 // fall through to rebuild |
368 } | 362 } |
369 } | 363 } |
370 | 364 |
371 if (NULL == fScaledCacheID) { | 365 if (NULL == fScaledCacheID) { |
372 if (!get_locked_pixels(fOrigBitmap, 0, &fScaledBitmap)) { | 366 if (!get_locked_pixels(fOrigBitmap, 0, &fScaledBitmap)) { |
373 return false; | 367 return false; |
374 } | 368 } |
375 | 369 |
376 // TODO: if fScaled comes back at a different width/height than fOri
g, | 370 // TODO: if fScaled comes back at a different width/height than fOri
g, |
377 // we need to update the matrix we are using to sample from this guy
. | 371 // we need to update the matrix we are using to sample from this guy
. |
378 | 372 |
379 fScaledCacheID = SkScaledImageCache::AddAndLock(fOrigBitmap, | 373 fScaledCacheID = SkBitmapCache::AddAndLock(fOrigBitmap, 1, 1, fScale
dBitmap); |
380 SK_Scalar1, SK_Scala
r1, | |
381 fScaledBitmap); | |
382 if (!fScaledCacheID) { | 374 if (!fScaledCacheID) { |
383 fScaledBitmap.reset(); | 375 fScaledBitmap.reset(); |
384 return false; | 376 return false; |
385 } | 377 } |
386 } | 378 } |
387 } | 379 } |
388 fBitmap = &fScaledBitmap; | 380 fBitmap = &fScaledBitmap; |
389 unlocker.release(); | 381 unlocker.release(); |
390 return true; | 382 return true; |
391 } | 383 } |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } else { | 1065 } else { |
1074 size >>= 2; | 1066 size >>= 2; |
1075 } | 1067 } |
1076 | 1068 |
1077 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1069 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
1078 size >>= 1; | 1070 size >>= 1; |
1079 } | 1071 } |
1080 | 1072 |
1081 return size; | 1073 return size; |
1082 } | 1074 } |
OLD | NEW |