From 9bc3954fc1b6c3fb609cbb10d42f659b9d762eb0 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Wed, 12 Aug 2015 12:57:54 -0700 Subject: Refactor helper function for SkBitmapShader to GrFragmentProcessor BUG=skia: Review URL: https://codereview.chromium.org/1285283002 --- include/gpu/SkGr.h | 8 +++++++- src/core/SkBitmapProcShader.cpp | 43 ++++++----------------------------------- src/gpu/SkGpuDevice.cpp | 37 ++++------------------------------- src/gpu/SkGr.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 71 deletions(-) diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 4de61afffb..e46479eb0f 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -14,8 +14,9 @@ #include // Gr headers -#include "GrTypes.h" #include "GrContext.h" +#include "GrTextureAccess.h" +#include "GrTypes.h" // skia headers #include "SkBitmap.h" @@ -96,6 +97,11 @@ SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque); // Using the dreaded SkGrPixelRef ... void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap* dst); +GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, + const SkMatrix& viewM, + const SkMatrix& localM, + bool* doBicubic); + //////////////////////////////////////////////////////////////////////////////// // Classes diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index 5a33af55ba..9086072f98 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -349,8 +349,8 @@ void SkBitmapProcShader::toString(SkString* str) const { #if SK_SUPPORT_GPU #include "GrTextureAccess.h" -#include "effects/GrSimpleTextureEffect.h" #include "SkGr.h" +#include "effects/GrSimpleTextureEffect.h" bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, const SkMatrix& viewM, @@ -382,41 +382,10 @@ bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& // we check the matrix scale factors to determine how to interpret the filter quality setting. // This completely ignores the complexity of the drawVertices case where explicit local coords // are provided by the caller. - bool useBicubic = false; - GrTextureParams::FilterMode textureFilterMode; - switch(paint.getFilterQuality()) { - case kNone_SkFilterQuality: - textureFilterMode = GrTextureParams::kNone_FilterMode; - break; - case kLow_SkFilterQuality: - textureFilterMode = GrTextureParams::kBilerp_FilterMode; - break; - case kMedium_SkFilterQuality: { - SkMatrix matrix; - matrix.setConcat(viewM, this->getLocalMatrix()); - if (matrix.getMinScale() < SK_Scalar1) { - textureFilterMode = GrTextureParams::kMipMap_FilterMode; - } else { - // Don't trigger MIP level generation unnecessarily. - textureFilterMode = GrTextureParams::kBilerp_FilterMode; - } - break; - } - case kHigh_SkFilterQuality: { - SkMatrix matrix; - matrix.setConcat(viewM, this->getLocalMatrix()); - useBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode); - break; - } - default: - SkErrorInternals::SetError( kInvalidPaint_SkError, - "Sorry, I don't understand the filtering " - "mode you asked for. Falling back to " - "MIPMaps."); - textureFilterMode = GrTextureParams::kMipMap_FilterMode; - break; - - } + bool doBicubic; + GrTextureParams::FilterMode textureFilterMode = + GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, this->getLocalMatrix(), + &doBicubic); GrTextureParams params(tm, textureFilterMode); SkAutoTUnref texture(GrRefCachedBitmapTexture(context, fRawBitmap, ¶ms)); @@ -430,7 +399,7 @@ bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& SkColor2GrColor(paint.getColor()) : SkColor2GrColorJustAlpha(paint.getColor()); - if (useBicubic) { + if (doBicubic) { *fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm); } else { *fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index c5fccfc2e2..f8318c52d8 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1034,39 +1034,10 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw, viewM.preConcat(m); GrTextureParams params; - SkFilterQuality paintFilterQuality = paint.getFilterQuality(); - GrTextureParams::FilterMode textureFilterMode; - - bool doBicubic = false; - - switch(paintFilterQuality) { - case kNone_SkFilterQuality: - textureFilterMode = GrTextureParams::kNone_FilterMode; - break; - case kLow_SkFilterQuality: - textureFilterMode = GrTextureParams::kBilerp_FilterMode; - break; - case kMedium_SkFilterQuality: - if (viewM.getMinScale() < SK_Scalar1) { - textureFilterMode = GrTextureParams::kMipMap_FilterMode; - } else { - // Don't trigger MIP level generation unnecessarily. - textureFilterMode = GrTextureParams::kBilerp_FilterMode; - } - break; - case kHigh_SkFilterQuality: - // Minification can look bad with the bicubic effect. - doBicubic = - GrBicubicEffect::ShouldUseBicubic(viewM, &textureFilterMode); - break; - default: - SkErrorInternals::SetError( kInvalidPaint_SkError, - "Sorry, I don't understand the filtering " - "mode you asked for. Falling back to " - "MIPMaps."); - textureFilterMode = GrTextureParams::kMipMap_FilterMode; - break; - } + bool doBicubic; + GrTextureParams::FilterMode textureFilterMode = + GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, SkMatrix::I(), + &doBicubic); int tileFilterPad; if (doBicubic) { diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 9aa79618a2..53f640b601 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -21,6 +21,7 @@ #include "SkResourceCache.h" #include "SkTextureCompressor.h" #include "SkYUVPlanesCache.h" +#include "effects/GrBicubicEffect.h" #include "effects/GrDitherEffect.h" #include "effects/GrPorterDuffXferProcessor.h" #include "effects/GrYUVtoRGBEffect.h" @@ -835,3 +836,45 @@ void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap dst->setInfo(info); dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref(); } + +GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality paintFilterQuality, + const SkMatrix& viewM, + const SkMatrix& localM, + bool* doBicubic) { + *doBicubic = false; + GrTextureParams::FilterMode textureFilterMode; + switch (paintFilterQuality) { + case kNone_SkFilterQuality: + textureFilterMode = GrTextureParams::kNone_FilterMode; + break; + case kLow_SkFilterQuality: + textureFilterMode = GrTextureParams::kBilerp_FilterMode; + break; + case kMedium_SkFilterQuality: { + SkMatrix matrix; + matrix.setConcat(viewM, localM); + if (matrix.getMinScale() < SK_Scalar1) { + textureFilterMode = GrTextureParams::kMipMap_FilterMode; + } else { + // Don't trigger MIP level generation unnecessarily. + textureFilterMode = GrTextureParams::kBilerp_FilterMode; + } + break; + } + case kHigh_SkFilterQuality: { + SkMatrix matrix; + matrix.setConcat(viewM, localM); + *doBicubic = GrBicubicEffect::ShouldUseBicubic(matrix, &textureFilterMode); + break; + } + default: + SkErrorInternals::SetError( kInvalidPaint_SkError, + "Sorry, I don't understand the filtering " + "mode you asked for. Falling back to " + "MIPMaps."); + textureFilterMode = GrTextureParams::kMipMap_FilterMode; + break; + + } + return textureFilterMode; +} -- cgit v1.2.3