Chromium Code Reviews| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 return false; | 245 return false; |
| 246 } | 246 } |
| 247 | 247 |
| 248 // else set the filter-level to Medium, since we're scaling down and | 248 // else set the filter-level to Medium, since we're scaling down and |
| 249 // want to reqeust mipmaps | 249 // want to reqeust mipmaps |
| 250 fFilterLevel = SkPaint::kMedium_FilterLevel; | 250 fFilterLevel = SkPaint::kMedium_FilterLevel; |
| 251 } | 251 } |
| 252 | 252 |
| 253 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); | 253 SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); |
| 254 | 254 |
| 255 /** | |
| 256 * Medium quality means use a mipmap for down-scaling, and just bilper | |
|
reed1
2014/11/11 14:44:12
seems like we should add a line here.
// HACK: di
reveman
2014/11/11 14:56:37
Done.
| |
| 257 * for upscaling. Since we're examining the inverse matrix, we look for | |
| 258 * a scale > 1 to indicate down scaling by the CTM. | |
| 259 */ | |
| 260 if (scaleSqd > SK_Scalar1) { | |
| 261 fCurrMip.reset(SkMipMapCache::FindAndRef(fOrigBitmap)); | |
| 262 if (NULL == fCurrMip.get()) { | |
| 263 fCurrMip.reset(SkMipMap::Build(fOrigBitmap)); | |
| 264 if (NULL == fCurrMip.get()) { | |
| 265 return false; | |
| 266 } | |
| 267 SkMipMapCache::Add(fOrigBitmap, fCurrMip); | |
| 268 } | |
| 269 | |
| 270 SkScalar levelScale = SkScalarInvert(SkScalarSqrt(scaleSqd)); | |
| 271 SkMipMap::Level level; | |
| 272 if (fCurrMip->extractLevel(levelScale, &level)) { | |
| 273 SkScalar invScaleFixup = level.fScale; | |
| 274 fInvMatrix.postScale(invScaleFixup, invScaleFixup); | |
| 275 | |
| 276 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 | |
| 278 // that here, and not need to explicitly track it ourselves. | |
| 279 fScaledBitmap.installPixels(info, level.fPixels, level.fRowBytes); | |
| 280 fBitmap = &fScaledBitmap; | |
| 281 fFilterLevel = SkPaint::kLow_FilterLevel; | |
| 282 return true; | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 return false; | 255 return false; |
| 287 } | 256 } |
| 288 | 257 |
| 289 static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) { | 258 static bool get_locked_pixels(const SkBitmap& src, int pow2, SkBitmap* dst) { |
| 290 SkPixelRef* pr = src.pixelRef(); | 259 SkPixelRef* pr = src.pixelRef(); |
| 291 if (pr && pr->decodeInto(pow2, dst)) { | 260 if (pr && pr->decodeInto(pow2, dst)) { |
| 292 return true; | 261 return true; |
| 293 } | 262 } |
| 294 | 263 |
| 295 /* | 264 /* |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 } else { | 975 } else { |
| 1007 size >>= 2; | 976 size >>= 2; |
| 1008 } | 977 } |
| 1009 | 978 |
| 1010 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 979 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
| 1011 size >>= 1; | 980 size >>= 1; |
| 1012 } | 981 } |
| 1013 | 982 |
| 1014 return size; | 983 return size; |
| 1015 } | 984 } |
| OLD | NEW |