diff options
author | Brian Osman <brianosman@google.com> | 2018-02-15 10:09:48 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-02-16 13:39:35 +0000 |
commit | db78cba957889285604aeacb75e47af4600880c4 (patch) | |
tree | bd44a73a8de38497aed8319bc5b880c12d3b2a7a /src | |
parent | f6f7b67ac230b14a725fbdabe951c70ea5b4428f (diff) |
Avoid creating MIPs until necessary when MIP bias is active
With sharpened mips, the scale at which we begin to sample level 1 is
(obviously) less than 1. This change avoids creation of mips for images
that are only slightly downscaled (and for which we wouldn't have sampled
those MIPs anyway).
Change-Id: If8ffc79c2ce2ff1f3aae7f5732d8a50aca0e26be
Reviewed-on: https://skia-review.googlesource.com/107801
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 14 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice_drawTexture.cpp | 3 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 12 | ||||
-rw-r--r-- | src/gpu/SkGr.h | 1 | ||||
-rw-r--r-- | src/shaders/SkImageShader.cpp | 4 |
5 files changed, 26 insertions, 8 deletions
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 7521278fac..9a01394691 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -761,8 +761,9 @@ bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr GrSamplerState samplerState; bool doBicubic; - GrSamplerState::Filter textureFilterMode = - GrSkFilterQualityToGrFilterMode(quality, viewMatrix, srcToDstRect, &doBicubic); + GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( + quality, viewMatrix, srcToDstRect, fContext->contextPriv().sharpenMipmappedTextures(), + &doBicubic); int tileFilterPad; if (doBicubic) { @@ -812,7 +813,8 @@ void SkGpuDevice::drawBitmap(const SkBitmap& bitmap, GrSamplerState samplerState; bool doBicubic; GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( - paint.getFilterQuality(), viewMatrix, SkMatrix::I(), &doBicubic); + paint.getFilterQuality(), viewMatrix, SkMatrix::I(), + fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic); int tileFilterPad; @@ -1170,7 +1172,8 @@ void SkGpuDevice::drawBitmapRect(const SkBitmap& bitmap, GrSamplerState sampleState; bool doBicubic; GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( - paint.getFilterQuality(), this->ctm(), srcToDstMatrix, &doBicubic); + paint.getFilterQuality(), this->ctm(), srcToDstMatrix, + fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic); int tileFilterPad; @@ -1362,7 +1365,8 @@ void SkGpuDevice::drawProducerNine(GrTextureProducer* producer, GrFSAAType::kUnifiedMSAA == fRenderTargetContext->fsaaType(); bool doBicubic; GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( - paint.getFilterQuality(), this->ctm(), SkMatrix::I(), &doBicubic); + paint.getFilterQuality(), this->ctm(), SkMatrix::I(), + fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic); if (useFallback || doBicubic || GrSamplerState::Filter::kNearest != textureFilterMode) { SkLatticeIter iter(producer->width(), producer->height(), center, dst); diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp index b6b1e619c0..c91d7a4569 100644 --- a/src/gpu/SkGpuDevice_drawTexture.cpp +++ b/src/gpu/SkGpuDevice_drawTexture.cpp @@ -258,7 +258,8 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, bool doBicubic; GrSamplerState::Filter fm = GrSkFilterQualityToGrFilterMode( - paint.getFilterQuality(), viewMatrix, srcToDstMatrix, &doBicubic); + paint.getFilterQuality(), viewMatrix, srcToDstMatrix, + fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic); const GrSamplerState::Filter* filterMode = doBicubic ? nullptr : &fm; GrTextureProducer::FilterConstraint constraintMode; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 12e7670029..c4bbf487f8 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -562,6 +562,7 @@ bool SkPaintToGrPaintWithTexture(GrContext* context, GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, const SkMatrix& viewM, const SkMatrix& localM, + bool sharpenMipmappedTextures, bool* doBicubic) { *doBicubic = false; GrSamplerState::Filter textureFilterMode; @@ -575,7 +576,16 @@ GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilt case kMedium_SkFilterQuality: { SkMatrix matrix; matrix.setConcat(viewM, localM); - if (matrix.getMinScale() < SK_Scalar1) { + // With sharp mips, we bias lookups by -0.5. That means our final LOD is >= 0 until the + // computed LOD is >= 0.5. At what scale factor does a texture get an LOD of 0.5? + // + // Want: 0 = log2(1/s) - 0.5 + // 0.5 = log2(1/s) + // 2^0.5 = 1/s + // 1/2^0.5 = s + // 2^0.5/2 = s + SkScalar mipScale = sharpenMipmappedTextures ? SK_ScalarRoot2Over2 : SK_Scalar1; + if (matrix.getMinScale() < mipScale) { textureFilterMode = GrSamplerState::Filter::kMipMap; } else { // Don't trigger MIP level generation unnecessarily. diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h index 5657821cbe..fc0aa63d4a 100644 --- a/src/gpu/SkGr.h +++ b/src/gpu/SkGr.h @@ -152,6 +152,7 @@ bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*); GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, const SkMatrix& viewM, const SkMatrix& localM, + bool sharpenMipmappedTextures, bool* doBicubic); ////////////////////////////////////////////////////////////////////////////// diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp index debd13b2ef..9f39fe2792 100644 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -201,6 +201,7 @@ void SkImageShader::toString(SkString* str) const { #include "GrColorSpaceInfo.h" #include "GrContext.h" +#include "GrContextPriv.h" #include "SkGr.h" #include "effects/GrBicubicEffect.h" #include "effects/GrSimpleTextureEffect.h" @@ -243,7 +244,8 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor( // are provided by the caller. bool doBicubic; GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode( - args.fFilterQuality, *args.fViewMatrix, lm, &doBicubic); + args.fFilterQuality, *args.fViewMatrix, lm, + args.fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic); GrSamplerState samplerState(wrapModes, textureFilterMode); sk_sp<SkColorSpace> texColorSpace; SkScalar scaleAdjust[2] = { 1.0f, 1.0f }; |