Return kNearest from GrSkFilterQualityToGrFilterMode for 1x1 images
Bug: skia:
Change-Id: I358e5c74d918b880bea05a6129dbffcae0e8046d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/234181
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 3123c42..f3201ba 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -769,7 +769,7 @@
GrSamplerState samplerState;
bool doBicubic;
GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode(
- quality, viewMatrix, srcToDstRect,
+ image->width(), image->height(), quality, viewMatrix, srcToDstRect,
fContext->priv().options().fSharpenMipmappedTextures, &doBicubic);
int tileFilterPad;
@@ -1171,8 +1171,8 @@
GrSamplerState sampleState;
bool doBicubic;
GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode(
- paint.getFilterQuality(), this->ctm(), srcToDstMatrix,
- fContext->priv().options().fSharpenMipmappedTextures, &doBicubic);
+ bitmap.width(), bitmap.height(), paint.getFilterQuality(), this->ctm(),
+ srcToDstMatrix, fContext->priv().options().fSharpenMipmappedTextures, &doBicubic);
int tileFilterPad;
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 0261635..25804eb 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -266,7 +266,7 @@
}
bool doBicubic;
GrSamplerState::Filter fm = GrSkFilterQualityToGrFilterMode(
- paint.getFilterQuality(), ctm, srcToDst,
+ producer->width(), producer->height(), paint.getFilterQuality(), ctm, srcToDst,
context->priv().options().fSharpenMipmappedTextures, &doBicubic);
const GrSamplerState::Filter* filterMode = doBicubic ? nullptr : &fm;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 6db4e37..d979f19 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -542,20 +542,21 @@
////////////////////////////////////////////////////////////////////////////////////////////////
-GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
+GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(int imageWidth, int imageHeight,
+ SkFilterQuality paintFilterQuality,
const SkMatrix& viewM,
const SkMatrix& localM,
bool sharpenMipmappedTextures,
bool* doBicubic) {
*doBicubic = false;
- GrSamplerState::Filter textureFilterMode;
+ if (imageWidth <= 1 && imageHeight <= 1) {
+ return GrSamplerState::Filter::kNearest;
+ }
switch (paintFilterQuality) {
case kNone_SkFilterQuality:
- textureFilterMode = GrSamplerState::Filter::kNearest;
- break;
+ return GrSamplerState::Filter::kNearest;
case kLow_SkFilterQuality:
- textureFilterMode = GrSamplerState::Filter::kBilerp;
- break;
+ return GrSamplerState::Filter::kBilerp;
case kMedium_SkFilterQuality: {
SkMatrix matrix;
matrix.setConcat(viewM, localM);
@@ -569,24 +570,19 @@
// 2^0.5/2 = s
SkScalar mipScale = sharpenMipmappedTextures ? SK_ScalarRoot2Over2 : SK_Scalar1;
if (matrix.getMinScale() < mipScale) {
- textureFilterMode = GrSamplerState::Filter::kMipMap;
+ return GrSamplerState::Filter::kMipMap;
} else {
// Don't trigger MIP level generation unnecessarily.
- textureFilterMode = GrSamplerState::Filter::kBilerp;
+ return GrSamplerState::Filter::kBilerp;
}
- break;
}
case kHigh_SkFilterQuality: {
SkMatrix matrix;
matrix.setConcat(viewM, localM);
+ GrSamplerState::Filter textureFilterMode;
*doBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode);
- break;
+ return textureFilterMode;
}
- default:
- // Should be unreachable. If not, fall back to mipmaps.
- textureFilterMode = GrSamplerState::Filter::kMipMap;
- break;
-
}
- return textureFilterMode;
+ SkUNREACHABLE;
}
diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h
index 8084787..e04291c 100644
--- a/src/gpu/SkGr.h
+++ b/src/gpu/SkGr.h
@@ -140,7 +140,8 @@
bool GrPixelConfigToColorType(GrPixelConfig, SkColorType*);
-GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality,
+GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(int imageWidth, int imageHeight,
+ SkFilterQuality paintFilterQuality,
const SkMatrix& viewM,
const SkMatrix& localM,
bool sharpenMipmappedTextures,
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index 52fe97e..8474fbf 100644
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -218,7 +218,7 @@
// are provided by the caller.
bool doBicubic;
GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode(
- args.fFilterQuality, *args.fViewMatrix, *lm,
+ fImage->width(), fImage->height(), args.fFilterQuality, *args.fViewMatrix, *lm,
args.fContext->priv().options().fSharpenMipmappedTextures, &doBicubic);
GrSamplerState samplerState(wrapModes, textureFilterMode);
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };