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>
This commit is contained in:
parent
f6f7b67ac2
commit
db78cba957
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -152,6 +152,7 @@ bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*);
|
||||
GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
|
||||
const SkMatrix& viewM,
|
||||
const SkMatrix& localM,
|
||||
bool sharpenMipmappedTextures,
|
||||
bool* doBicubic);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user