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
This commit is contained in:
parent
a525cb151b
commit
33ed3ad9f6
@ -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);
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -27,8 +27,10 @@ DEF_TEST(MipMap, reporter) {
|
||||
make_bitmap(&bm, rand);
|
||||
SkAutoTUnref<SkMipMap> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user