aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/effects')
-rw-r--r--src/gpu/effects/GrBicubicEffect.cpp33
-rw-r--r--src/gpu/effects/GrBicubicEffect.h10
2 files changed, 43 insertions, 0 deletions
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 89124ff667..9c6d1a3f8c 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -177,3 +177,36 @@ GrEffectRef* GrBicubicEffect::TestCreate(SkRandom* random,
}
return GrBicubicEffect::Create(textures[texIdx], coefficients);
}
+
+//////////////////////////////////////////////////////////////////////////////
+
+bool GrBicubicEffect::ShouldUseBicubic(const SkMatrix& matrix,
+ GrTextureParams::FilterMode* filterMode) {
+ if (matrix.isIdentity()) {
+ *filterMode = GrTextureParams::kNone_FilterMode;
+ return false;
+ }
+
+ SkScalar scales[2];
+ if (!matrix.getMinMaxScales(scales) || scales[0] < SK_Scalar1) {
+ // Bicubic doesn't handle arbitrary minimization well, as src texels can be skipped
+ // entirely,
+ *filterMode = GrTextureParams::kMipMap_FilterMode;
+ return false;
+ }
+ // At this point if scales[1] == SK_Scalar1 then the matrix doesn't do any scaling.
+ if (scales[1] == SK_Scalar1) {
+ if (matrix.rectStaysRect() && SkScalarIsInt(matrix.getTranslateX()) &&
+ SkScalarIsInt(matrix.getTranslateY())) {
+ *filterMode = GrTextureParams::kNone_FilterMode;
+ } else {
+ // Use bilerp to handle rotation or fractional translation.
+ *filterMode = GrTextureParams::kBilerp_FilterMode;
+ }
+ return false;
+ }
+ // When we use the bicubic filtering effect each sample is read from the texture using
+ // nearest neighbor sampling.
+ *filterMode = GrTextureParams::kNone_FilterMode;
+ return true;
+}
diff --git a/src/gpu/effects/GrBicubicEffect.h b/src/gpu/effects/GrBicubicEffect.h
index cc8b120863..1998e68780 100644
--- a/src/gpu/effects/GrBicubicEffect.h
+++ b/src/gpu/effects/GrBicubicEffect.h
@@ -78,6 +78,16 @@ public:
return CreateEffectRef(effect);
}
+ /**
+ * Determines whether the bicubic effect should be used based on the transformation from the
+ * local coords to the device. Returns true if the bicubic effect should be used. filterMode
+ * is set to appropriate filtering mode to use regardless of the return result (e.g. when this
+ * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or
+ * kNearest).
+ */
+ static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice,
+ GrTextureParams::FilterMode* filterMode);
+
private:
GrBicubicEffect(GrTexture*, const SkScalar coefficients[16],
const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);