short circuit high quality scales that are actually the identity

transform

BUG=skia:
R=reed@google.com

Author: humper@google.com

Review URL: https://codereview.chromium.org/456843002
This commit is contained in:
humper 2014-08-08 12:06:13 -07:00 committed by Commit bot
parent 8875a04136
commit 8d9153fca2
2 changed files with 21 additions and 4 deletions

View File

@ -167,6 +167,22 @@ bool SkBitmapProcState::possiblyScaleImage() {
SkScalar invScaleX = fInvMatrix.getScaleX(); SkScalar invScaleX = fInvMatrix.getScaleX();
SkScalar invScaleY = fInvMatrix.getScaleY(); SkScalar invScaleY = fInvMatrix.getScaleY();
if (SkScalarNearlyEqual(invScaleX,1.0f) &&
SkScalarNearlyEqual(invScaleY,1.0f)) {
// short-circuit identity scaling; the output is supposed to
// be the same as the input, so we might as well go fast.
// Note(humper): We could also probably do this if the scales
// are close to -1 as well, since the flip doesn't require
// any fancy re-sampling...
// Set our filter level to low -- the only post-filtering this
// image might require is some interpolation if the translation
// is fractional.
fFilterLevel = SkPaint::kLow_FilterLevel;
return false;
}
fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap, fScaledCacheID = SkScaledImageCache::FindAndLock(fOrigBitmap,
invScaleX, invScaleY, invScaleX, invScaleY,
&fScaledBitmap); &fScaledBitmap);
@ -218,8 +234,10 @@ bool SkBitmapProcState::possiblyScaleImage() {
fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScaleX(), fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScaleX(),
fInvMatrix.getTranslateY() / fInvMatrix.getScaleY()); fInvMatrix.getTranslateY() / fInvMatrix.getScaleY());
// no need for any further filtering; we just did it! // Set our filter level to low -- the only post-filtering this
fFilterLevel = SkPaint::kNone_FilterLevel; // image might require is some interpolation if the translation
// is fractional.
fFilterLevel = SkPaint::kLow_FilterLevel;
unlocker.release(); unlocker.release();
return true; return true;
} }

View File

@ -477,8 +477,7 @@ static void mirrorx_nofilter_trans(const SkBitmapProcState& s,
SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool trivial_matrix) { SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool trivial_matrix) {
// test_int_tileprocs(); // test_int_tileprocs();
// check for our special case when there is no scale/affine/perspective // check for our special case when there is no scale/affine/perspective
if (trivial_matrix) { if (trivial_matrix && SkPaint::kNone_FilterLevel == fFilterLevel) {
SkASSERT(SkPaint::kNone_FilterLevel == fFilterLevel);
fIntTileProcY = choose_int_tile_proc(fTileModeY); fIntTileProcY = choose_int_tile_proc(fTileModeY);
switch (fTileModeX) { switch (fTileModeX) {
case SkShader::kClamp_TileMode: case SkShader::kClamp_TileMode: