1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrBicubicTextureEffect_DEFINED 9 #define GrBicubicTextureEffect_DEFINED 10 11 #include "GrSingleTextureEffect.h" 12 #include "GrTextureDomain.h" 13 #include "glsl/GrGLSLFragmentProcessor.h" 14 15 class GrInvariantOutput; 16 17 class GrBicubicEffect : public GrSingleTextureEffect { 18 public: 19 enum { 20 kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of 21 // surrounding texels are needed by the kernel in x and y. 22 }; 23 ~GrBicubicEffect() override; 24 name()25 const char* name() const override { return "Bicubic"; } 26 domain()27 const GrTextureDomain& domain() const { return fDomain; } 28 29 /** 30 * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. 31 */ Make(GrResourceProvider * resourceProvider,sk_sp<GrTextureProxy> proxy,sk_sp<GrColorSpaceXform> colorSpaceXform,const SkMatrix & matrix,const SkShader::TileMode tileModes[2])32 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, 33 sk_sp<GrTextureProxy> proxy, 34 sk_sp<GrColorSpaceXform> colorSpaceXform, 35 const SkMatrix& matrix, 36 const SkShader::TileMode tileModes[2]) { 37 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy), 38 std::move(colorSpaceXform), 39 matrix, tileModes)); 40 } 41 42 /** 43 * Create a Mitchell filter effect with a texture matrix and a domain. 44 */ Make(GrResourceProvider * resourceProvider,sk_sp<GrTextureProxy> proxy,sk_sp<GrColorSpaceXform> colorSpaceXform,const SkMatrix & matrix,const SkRect & domain)45 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider, 46 sk_sp<GrTextureProxy> proxy, 47 sk_sp<GrColorSpaceXform> colorSpaceXform, 48 const SkMatrix& matrix, 49 const SkRect& domain) { 50 return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(resourceProvider, std::move(proxy), 51 std::move(colorSpaceXform), 52 matrix, domain)); 53 } 54 55 /** 56 * Determines whether the bicubic effect should be used based on the transformation from the 57 * local coords to the device. Returns true if the bicubic effect should be used. filterMode 58 * is set to appropriate filtering mode to use regardless of the return result (e.g. when this 59 * returns false it may indicate that the best fallback is to use kMipMap, kBilerp, or 60 * kNearest). 61 */ 62 static bool ShouldUseBicubic(const SkMatrix& localCoordsToDevice, 63 GrSamplerParams::FilterMode* filterMode); 64 65 private: 66 GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, 67 const SkMatrix &matrix, const SkShader::TileMode tileModes[2]); 68 GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, 69 const SkMatrix &matrix, const SkRect& domain); 70 71 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; 72 73 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; 74 75 bool onIsEqual(const GrFragmentProcessor&) const override; 76 77 GrTextureDomain fDomain; 78 79 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 80 81 typedef GrSingleTextureEffect INHERITED; 82 }; 83 84 #endif 85