Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkBitmapProcState.h" | 8 #include "SkBitmapProcState.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkFilterProc.h" | 10 #include "SkFilterProc.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 // remove the scaling component from the matrix. | 160 // remove the scaling component from the matrix. |
| 161 | 161 |
| 162 if (SkPaint::kHigh_FilterLevel == fFilterLevel && | 162 if (SkPaint::kHigh_FilterLevel == fFilterLevel && |
| 163 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && | 163 fInvMatrix.getType() <= (SkMatrix::kScale_Mask | SkMatrix::kTranslate_Ma sk) && |
| 164 kN32_SkColorType == fOrigBitmap.colorType() && | 164 kN32_SkColorType == fOrigBitmap.colorType() && |
| 165 cache_size_okay(fOrigBitmap, fInvMatrix)) { | 165 cache_size_okay(fOrigBitmap, fInvMatrix)) { |
| 166 | 166 |
| 167 SkScalar invScaleX = fInvMatrix.getScaleX(); | 167 SkScalar invScaleX = fInvMatrix.getScaleX(); |
| 168 SkScalar invScaleY = fInvMatrix.getScaleY(); | 168 SkScalar invScaleY = fInvMatrix.getScaleY(); |
| 169 | 169 |
| 170 if (SkScalarNearlyEqual(invScaleX,1.0f) && | |
| 171 SkScalarNearlyEqual(invScaleY,1.0f)) { | |
| 172 // short-circuit identity scaling; the output is supposed to | |
| 173 // be the same as the input, so we might as well go fast. | |
| 174 | |
| 175 // TODO -- consider short circuiting here if the scale is | |
|
reed1
2014/08/08 18:28:21
remove the TODO
humper
2014/08/08 18:39:05
Done.
| |
| 176 // CLOSE to one. | |
| 177 | |
| 178 // Set our filter level to low -- the only post-filtering this | |
| 179 // image might require is some interpolation if the translation | |
| 180 // is fractional. | |
| 181 fFilterLevel = SkPaint::kLow_FilterLevel; | |
| 182 return false; | |
| 183 } | |
| 184 | |
| 170 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, | 185 fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, |
| 171 invScaleX, invScaleY, | 186 invScaleX, invScaleY, |
| 172 &fScaledBitmap); | 187 &fScaledBitmap); |
| 173 if (fScaledCacheID) { | 188 if (fScaledCacheID) { |
| 174 fScaledBitmap.lockPixels(); | 189 fScaledBitmap.lockPixels(); |
| 175 if (!fScaledBitmap.getPixels()) { | 190 if (!fScaledBitmap.getPixels()) { |
| 176 fScaledBitmap.unlockPixels(); | 191 fScaledBitmap.unlockPixels(); |
| 177 // found a purged entry (discardablememory?), release it | 192 // found a purged entry (discardablememory?), release it |
| 178 SkScaledImageCache::Unlock(fScaledCacheID); | 193 SkScaledImageCache::Unlock(fScaledCacheID); |
| 179 fScaledCacheID = NULL; | 194 fScaledCacheID = NULL; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 SkASSERT(NULL != fScaledBitmap.getPixels()); | 226 SkASSERT(NULL != fScaledBitmap.getPixels()); |
| 212 } | 227 } |
| 213 | 228 |
| 214 SkASSERT(NULL != fScaledBitmap.getPixels()); | 229 SkASSERT(NULL != fScaledBitmap.getPixels()); |
| 215 fBitmap = &fScaledBitmap; | 230 fBitmap = &fScaledBitmap; |
| 216 | 231 |
| 217 // set the inv matrix type to translate-only; | 232 // set the inv matrix type to translate-only; |
| 218 fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScale X(), | 233 fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScale X(), |
| 219 fInvMatrix.getTranslateY() / fInvMatrix.getScale Y()); | 234 fInvMatrix.getTranslateY() / fInvMatrix.getScale Y()); |
| 220 | 235 |
| 221 // no need for any further filtering; we just did it! | 236 // Set our filter level to low -- the only post-filtering this |
| 222 fFilterLevel = SkPaint::kNone_FilterLevel; | 237 // image might require is some interpolation if the translation |
| 238 // is fractional. | |
| 239 fFilterLevel = SkPaint::kLow_FilterLevel; | |
| 223 unlocker.release(); | 240 unlocker.release(); |
| 224 return true; | 241 return true; |
| 225 } | 242 } |
| 226 | 243 |
| 227 /* | 244 /* |
| 228 * If High, then our special-case for scale-only did not take, and so we | 245 * If High, then our special-case for scale-only did not take, and so we |
| 229 * have to make a choice: | 246 * have to make a choice: |
| 230 * 1. fall back on mipmaps + bilerp | 247 * 1. fall back on mipmaps + bilerp |
| 231 * 2. fall back on scanline bicubic filter | 248 * 2. fall back on scanline bicubic filter |
| 232 * For now, we compute the "scale" value from the matrix, and have a | 249 * For now, we compute the "scale" value from the matrix, and have a |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 fShaderProc32 = NULL; | 468 fShaderProc32 = NULL; |
| 452 fShaderProc16 = NULL; | 469 fShaderProc16 = NULL; |
| 453 fSampleProc32 = NULL; | 470 fSampleProc32 = NULL; |
| 454 fSampleProc16 = NULL; | 471 fSampleProc16 = NULL; |
| 455 | 472 |
| 456 // recompute the triviality of the matrix here because we may have | 473 // recompute the triviality of the matrix here because we may have |
| 457 // changed it! | 474 // changed it! |
| 458 | 475 |
| 459 trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; | 476 trivialMatrix = (fInvMatrix.getType() & ~SkMatrix::kTranslate_Mask) == 0; |
| 460 | 477 |
| 478 // | |
|
reed1
2014/08/08 18:28:21
remove //
| |
| 479 | |
| 480 if (trivialMatrix && fFilterLevel > SkPaint::kMedium_FilterLevel) { | |
|
reed1
2014/08/08 18:28:21
I *think* we can remove this check now, yes?
humper
2014/08/08 18:39:04
Done.
| |
| 481 fFilterLevel = SkPaint::kMedium_FilterLevel; | |
| 482 } | |
| 483 | |
| 461 if (SkPaint::kHigh_FilterLevel == fFilterLevel) { | 484 if (SkPaint::kHigh_FilterLevel == fFilterLevel) { |
| 462 // If this is still set, that means we wanted HQ sampling | 485 // If this is still set, that means we wanted HQ sampling |
| 463 // but couldn't do it as a preprocess. Let's try to install | 486 // but couldn't do it as a preprocess. Let's try to install |
| 464 // the scanline version of the HQ sampler. If that process fails, | 487 // the scanline version of the HQ sampler. If that process fails, |
| 465 // downgrade to bilerp. | 488 // downgrade to bilerp. |
| 466 | 489 |
| 467 // NOTE: Might need to be careful here in the future when we want | 490 // NOTE: Might need to be careful here in the future when we want |
| 468 // to have the platform proc have a shot at this; it's possible that | 491 // to have the platform proc have a shot at this; it's possible that |
| 469 // the chooseBitmapFilterProc will fail to install a shader but a | 492 // the chooseBitmapFilterProc will fail to install a shader but a |
| 470 // platform-specific one might succeed, so it might be premature here | 493 // platform-specific one might succeed, so it might be premature here |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1055 } else { | 1078 } else { |
| 1056 size >>= 2; | 1079 size >>= 2; |
| 1057 } | 1080 } |
| 1058 | 1081 |
| 1059 if (fFilterLevel != SkPaint::kNone_FilterLevel) { | 1082 if (fFilterLevel != SkPaint::kNone_FilterLevel) { |
| 1060 size >>= 1; | 1083 size >>= 1; |
| 1061 } | 1084 } |
| 1062 | 1085 |
| 1063 return size; | 1086 return size; |
| 1064 } | 1087 } |
| OLD | NEW |