OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); | 253 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); |
254 | 254 |
255 /** | 255 /** |
256 * Medium quality means use a mipmap for down-scaling, and just bilper | 256 * Medium quality means use a mipmap for down-scaling, and just bilper |
257 * for upscaling. Since we're examining the inverse matrix, we look for | 257 * for upscaling. Since we're examining the inverse matrix, we look for |
258 * a scale > 1 to indicate down scaling by the CTM. | 258 * a scale > 1 to indicate down scaling by the CTM. |
259 */ | 259 */ |
260 if (scaleSqd > SK_Scalar1) { | 260 if (scaleSqd > SK_Scalar1) { |
261 fCurrMip.reset(SkMipMapCache::FindAndRef(fOrigBitmap)); | 261 fCurrMip.reset(SkMipMapCache::FindAndRef(fOrigBitmap)); |
262 if (NULL == fCurrMip.get()) { | 262 if (NULL == fCurrMip.get()) { |
263 fCurrMip.reset(SkMipMap::Build(fOrigBitmap)); | 263 fCurrMip.reset(SkMipMapCache::AddAndRef(fOrigBitmap)); |
264 if (NULL == fCurrMip.get()) { | 264 if (NULL == fCurrMip.get()) { |
265 return false; | 265 return false; |
266 } | 266 } |
267 SkMipMapCache::Add(fOrigBitmap, fCurrMip); | 267 } |
| 268 // diagnostic for a crasher... |
| 269 if (NULL == fCurrMip->data()) { |
| 270 sk_throw(); |
268 } | 271 } |
269 | 272 |
270 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); | 273 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); |
271 SkMipMap::Level level; | 274 SkMipMap::Level level; |
272 if (fCurrMip->extractLevel(levelScale, &level)) { | 275 if (fCurrMip->extractLevel(levelScale, &level)) { |
273 SkScalar invScaleFixup = level.fScale; | 276 SkScalar invScaleFixup = level.fScale; |
274 fInvMatrix.postScale(invScaleFixup, invScaleFixup); | 277 fInvMatrix.postScale(invScaleFixup, invScaleFixup); |
275 | 278 |
276 const SkImageInfo info = fOrigBitmap.info().makeWH(level.fWidth, lev
el.fHeight); | 279 const SkImageInfo info = fOrigBitmap.info().makeWH(level.fWidth, lev
el.fHeight); |
277 // todo: if we could wrap the fCurrMip in a pixelref, then we could
just install | 280 // todo: if we could wrap the fCurrMip in a pixelref, then we could
just install |
278 // that here, and not need to explicitly track it ourselves. | 281 // that here, and not need to explicitly track it ourselves. |
279 fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes); | 282 fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes); |
280 fBitmap = &fScaledBitmap; | 283 fBitmap = &fScaledBitmap; |
281 fFilterLevel = SkPaint::kLow_FilterLevel; | 284 fFilterLevel = SkPaint::kLow_FilterLevel; |
282 return true; | 285 return true; |
| 286 } else { |
| 287 // failed to extract, so release the mipmap |
| 288 fCurrMip.reset(NULL); |
283 } | 289 } |
284 } | 290 } |
285 | 291 |
286 return false; | 292 return false; |
287 } | 293 } |
288 | 294 |
289 static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) { | 295 static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) { |
290 SkPixelRef* pr = src.pixelRef(); | 296 SkPixelRef* pr = src.pixelRef(); |
291 if (pr && pr->decodeInto(pow2, dst)) { | 297 if (pr && pr->decodeInto(pow2, dst)) { |
292 return true; | 298 return true; |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 } else { | 1012 } else { |
1007 size >>= 2; | 1013 size >>= 2; |
1008 } | 1014 } |
1009 | 1015 |
1010 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1016 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
1011 size >>= 1; | 1017 size >>= 1; |
1012 } | 1018 } |
1013 | 1019 |
1014 return size; | 1020 return size; |
1015 } | 1021 } |
OLD | NEW |