Skip to content

Commit

Permalink
Return kNearest from GrSkFilterQualityToGrFilterMode for 1x1 images
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
csmartdalton86 authored and Skia Commit-Bot committed Aug 13, 2019
1 parent fd91d20 commit 309c6c0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/gpu/SkGpuDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr
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;
Expand Down Expand Up @@ -1171,8 +1171,8 @@ void SkGpuDevice::drawBitmapRect(const SkBitmap& bitmap,
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;

Expand Down
2 changes: 1 addition & 1 deletion src/gpu/SkGpuDevice_drawTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static void draw_texture_producer(GrContext* context, GrRenderTargetContext* rtc
}
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;

Expand Down
28 changes: 12 additions & 16 deletions src/gpu/SkGr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,20 +542,21 @@ bool SkPaintToGrPaintWithTexture(GrRecordingContext* context,

////////////////////////////////////////////////////////////////////////////////////////////////

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);
Expand All @@ -569,24 +570,19 @@ GrSamplerState::Filter GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilt
// 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;
}
3 changes: 2 additions & 1 deletion src/gpu/SkGr.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info);

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,
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/SkImageShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
// 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 };
Expand Down

0 comments on commit 309c6c0

Please sign in to comment.