From: fmalita Date: Tue, 9 Feb 2016 16:20:18 +0000 (-0800) Subject: Relocate anisotropic mipmap logic to SkMipMap::extractLevel() X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~129^2~2152 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=33ed3ad9f62b3c84d439b92ab45732d4fa6d05ad;p=platform%2Fupstream%2FlibSkiaSharp.git Relocate anisotropic mipmap logic to SkMipMap::extractLevel() Pass a full x/y scale and defer the anisotropic heuristic to SkMipMap. R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1686563002 Review URL: https://codereview.chromium.org/1686563002 --- diff --git a/gm/showmiplevels.cpp b/gm/showmiplevels.cpp index 7fc40ce..27d47e5 100644 --- a/gm/showmiplevels.cpp +++ b/gm/showmiplevels.cpp @@ -150,7 +150,7 @@ protected: int index = 0; SkMipMap::Level level; SkScalar scale = 0.5f; - while (mm->extractLevel(scale, &level)) { + while (mm->extractLevel(SkSize::Make(scale, scale), &level)) { SkBitmap bm = func(prevPM, level.fPixmap); DrawAndFrame(canvas, bm, x, y); @@ -258,7 +258,7 @@ protected: int index = 0; SkMipMap::Level level; SkScalar scale = 0.5f; - while (mm->extractLevel(scale, &level)) { + while (mm->extractLevel(SkSize::Make(scale, scale), &level)) { SkBitmap bm; bm.installPixels(level.fPixmap); DrawAndFrame(canvas, bm, x, y); diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp index b21c0f2..0555947 100644 --- a/src/core/SkBitmapController.cpp +++ b/src/core/SkBitmapController.cpp @@ -165,11 +165,7 @@ bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider return false; } - // Use the smallest (non-inverse) scale to match the GPU impl. - SkASSERT(invScaleSize.width() >= 0 && invScaleSize.height() >= 0); - const SkScalar invScale = SkTMax(invScaleSize.width(), invScaleSize.height()); - - if (invScale > SK_Scalar1) { + if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) { fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc())); if (nullptr == fCurrMip.get()) { SkBitmap orig; @@ -186,9 +182,10 @@ bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider sk_throw(); } - SkScalar levelScale = SkScalarInvert(invScale); + const SkSize scale = SkSize::Make(SkScalarInvert(invScaleSize.width()), + SkScalarInvert(invScaleSize.height())); SkMipMap::Level level; - if (fCurrMip->extractLevel(levelScale, &level)) { + if (fCurrMip->extractLevel(scale, &level)) { const SkSize& invScaleFixup = level.fScale; fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height()); diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp index 08602b7..7266dc6 100644 --- a/src/core/SkMipMap.cpp +++ b/src/core/SkMipMap.cpp @@ -320,11 +320,15 @@ SkMipMap* SkMipMap::Build(const SkPixmap& src, SkDiscardableFactoryProc fact) { /////////////////////////////////////////////////////////////////////////////// -bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const { +bool SkMipMap::extractLevel(const SkSize& scaleSize, Level* levelPtr) const { if (nullptr == fLevels) { return false; } + SkASSERT(scaleSize.width() >= 0 && scaleSize.height() >= 0); + // Use the smallest scale to match the GPU impl. + const SkScalar scale = SkTMin(scaleSize.width(), scaleSize.height()); + if (scale >= SK_Scalar1 || scale <= 0 || !SkScalarIsFinite(scale)) { return false; } diff --git a/src/core/SkMipMap.h b/src/core/SkMipMap.h index bc6d154..fe2018c 100644 --- a/src/core/SkMipMap.h +++ b/src/core/SkMipMap.h @@ -28,7 +28,7 @@ public: SkSize fScale; // < 1.0 }; - bool extractLevel(SkScalar scale, Level*) const; + bool extractLevel(const SkSize& scale, Level*) const; protected: void onDataChange(void* oldData, void* newData) override { diff --git a/tests/MipMapTest.cpp b/tests/MipMapTest.cpp index 11021e6..32fa34f 100644 --- a/tests/MipMapTest.cpp +++ b/tests/MipMapTest.cpp @@ -27,8 +27,10 @@ DEF_TEST(MipMap, reporter) { make_bitmap(&bm, rand); SkAutoTUnref mm(SkMipMap::Build(bm, nullptr)); - REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1, nullptr)); - REPORTER_ASSERT(reporter, !mm->extractLevel(SK_Scalar1 * 2, nullptr)); + REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_Scalar1), + nullptr)); + REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2, SK_Scalar1 * 2), + nullptr)); SkMipMap::Level prevLevel; sk_bzero(&prevLevel, sizeof(prevLevel)); @@ -38,7 +40,7 @@ DEF_TEST(MipMap, reporter) { scale = scale * 2 / 3; SkMipMap::Level level; - if (mm->extractLevel(scale, &level)) { + if (mm->extractLevel(SkSize::Make(scale, scale), &level)) { REPORTER_ASSERT(reporter, level.fPixmap.addr()); REPORTER_ASSERT(reporter, level.fPixmap.width() > 0); REPORTER_ASSERT(reporter, level.fPixmap.height() > 0);