From 8d9153fca25897bf40ca0ebac8b03616612cc7b4 Mon Sep 17 00:00:00 2001 From: humper Date: Fri, 8 Aug 2014 12:06:13 -0700 Subject: [PATCH] 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 --- src/core/SkBitmapProcState.cpp | 22 ++++++++++++++++++++-- src/core/SkBitmapProcState_matrixProcs.cpp | 3 +-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index d48679e8c9..6a6cc75b6e 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -167,6 +167,22 @@ bool SkBitmapProcState::possiblyScaleImage() { SkScalar invScaleX = fInvMatrix.getScaleX(); 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, invScaleX, invScaleY, &fScaledBitmap); @@ -218,8 +234,10 @@ bool SkBitmapProcState::possiblyScaleImage() { fInvMatrix.setTranslate(fInvMatrix.getTranslateX() / fInvMatrix.getScaleX(), fInvMatrix.getTranslateY() / fInvMatrix.getScaleY()); - // no need for any further filtering; we just did it! - fFilterLevel = SkPaint::kNone_FilterLevel; + // 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; unlocker.release(); return true; } diff --git a/src/core/SkBitmapProcState_matrixProcs.cpp b/src/core/SkBitmapProcState_matrixProcs.cpp index 02204b676b..851389c700 100644 --- a/src/core/SkBitmapProcState_matrixProcs.cpp +++ b/src/core/SkBitmapProcState_matrixProcs.cpp @@ -477,8 +477,7 @@ static void mirrorx_nofilter_trans(const SkBitmapProcState& s, SkBitmapProcState::MatrixProc SkBitmapProcState::chooseMatrixProc(bool trivial_matrix) { // test_int_tileprocs(); // check for our special case when there is no scale/affine/perspective - if (trivial_matrix) { - SkASSERT(SkPaint::kNone_FilterLevel == fFilterLevel); + if (trivial_matrix && SkPaint::kNone_FilterLevel == fFilterLevel) { fIntTileProcY = choose_int_tile_proc(fTileModeY); switch (fTileModeX) { case SkShader::kClamp_TileMode: