diff options
author | reed <reed@google.com> | 2015-01-16 07:18:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-16 07:18:10 -0800 |
commit | 15fd47f8a07615a7f5d78581aee4c80ff9f17fd9 (patch) | |
tree | 705f38c1a3f53b5a6d0e6e02defdac7df9246978 | |
parent | 45fa447460f70ec21d22cf4e1531490acfd3c578 (diff) |
use log2(scale) to compute mip level
BUG=skia:
Review URL: https://codereview.chromium.org/849333002
-rw-r--r-- | expectations/gm/ignored-tests.txt | 11 | ||||
-rw-r--r-- | include/core/SkFloatingPoint.h | 10 | ||||
-rw-r--r-- | include/core/SkScalar.h | 2 | ||||
-rw-r--r-- | src/core/SkMipMap.cpp | 17 |
4 files changed, 37 insertions, 3 deletions
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index 7bc03a30a5..6367eb5009 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -37,6 +37,17 @@ colortype_xfermodes mixed_xfermodes +# reed - rebase after mipmap level improvement +downsamplebitmap_image_medium_mandrill_512 +downsamplebitmap_image_medium_mandrill_132x132_12x12 +downsamplebitmap_image_medium_mandrill_512.png +downsamplebitmap_image_medium_mandrill_132x132_12x12.astc +downsamplebitmap_checkerboard_medium_512_256 +downsamplebitmap_text_medium_72.00pt +filterindiabox +coloremoji +fontmgr_iter + # robertphillips - skia:2995 blurrects diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h index 1003b80b4f..9fb343261b 100644 --- a/include/core/SkFloatingPoint.h +++ b/include/core/SkFloatingPoint.h @@ -91,6 +91,16 @@ static inline float sk_float_copysign(float x, float y) { #define sk_float_log(x) logf(x) #endif +// can't find log2f on android, but maybe that just a tool bug? +#ifdef SK_BUILD_FOR_ANDROID + static inline float sk_float_log2(float x) { + const double inv_ln_2 = 1.44269504088896; + return (float)(log(x) * inv_ln_2); + } +#else + #define sk_float_log2(x) log2f(x) +#endif + #ifdef SK_BUILD_FOR_WIN #define sk_float_isfinite(x) _finite(x) #define sk_float_isnan(x) _isnan(x) diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h index 94c3ce15c0..e8c7a7fb65 100644 --- a/include/core/SkScalar.h +++ b/include/core/SkScalar.h @@ -58,6 +58,7 @@ typedef float SkScalar; #define SkScalarATan2(y, x) (float)sk_float_atan2(y,x) #define SkScalarExp(x) (float)sk_float_exp(x) #define SkScalarLog(x) (float)sk_float_log(x) +#define SkScalarLog2(x) (float)sk_float_log2(x) #else // SK_SCALAR_IS_DOUBLE @@ -100,6 +101,7 @@ typedef double SkScalar; #define SkScalarATan2(y, x) atan2(y,x) #define SkScalarExp(x) exp(x) #define SkScalarLog(x) log(x) +#define SkScalarLog2(x) log2(x) #endif diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp index 83164b1526..2dad6d9c57 100644 --- a/src/core/SkMipMap.cpp +++ b/src/core/SkMipMap.cpp @@ -225,8 +225,7 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) { /////////////////////////////////////////////////////////////////////////////// -//static int gCounter; - +#ifdef SK_SUPPORT_LEGACY_MIPLEVELCHOICE static SkFixed compute_level(SkScalar scale) { SkScalar inv = SkScalarAbs(SkScalarInvert(scale)); if (inv > 32767) { // Watch out for SkFixed overflow. @@ -241,17 +240,29 @@ static SkFixed compute_level(SkScalar scale) { SkASSERT(clz >= 1 && clz <= 15); return SkIntToFixed(15 - clz) + ((unsigned)(s << (clz + 1)) >> 16); } +#endif bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const { if (NULL == fLevels) { return false; } - if (scale >= SK_Scalar1) { + if (scale >= SK_Scalar1 || scale <= 0 || !SkScalarIsFinite(scale)) { return false; } +#ifdef SK_SUPPORT_LEGACY_MIPLEVELCHOICE int level = compute_level(scale) >> 16; +#else + SkScalar L = -SkScalarLog2(scale); + if (!SkScalarIsFinite(L)) { + return false; + } + SkASSERT(L >= 0); + int level = SkScalarRoundToInt(L); +// SkDebugf("mipmap scale=%g L=%g level=%d\n", scale, L, level); +#endif + SkASSERT(level >= 0); if (level <= 0) { return false; |