michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrBicubicTextureEffect_DEFINED michael@0: #define GrBicubicTextureEffect_DEFINED michael@0: michael@0: #include "GrSingleTextureEffect.h" michael@0: #include "GrTextureDomain.h" michael@0: #include "GrDrawEffect.h" michael@0: #include "gl/GrGLEffect.h" michael@0: #include "GrTBackendEffectFactory.h" michael@0: michael@0: class GrGLBicubicEffect; michael@0: michael@0: class GrBicubicEffect : public GrSingleTextureEffect { michael@0: public: michael@0: enum { michael@0: kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of michael@0: // surrounding texels are needed by the kernel in x and y. michael@0: }; michael@0: virtual ~GrBicubicEffect(); michael@0: michael@0: static const char* Name() { return "Bicubic"; } michael@0: const float* coefficients() const { return fCoefficients; } michael@0: michael@0: typedef GrGLBicubicEffect GLEffect; michael@0: michael@0: virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; michael@0: virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; michael@0: michael@0: const GrTextureDomain& domain() const { return fDomain; } michael@0: michael@0: /** michael@0: * Create a simple filter effect with custom bicubic coefficients and optional domain. michael@0: */ michael@0: static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], michael@0: const SkRect* domain = NULL) { michael@0: if (NULL == domain) { michael@0: static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_TileMode, michael@0: SkShader::kClamp_TileMode }; michael@0: return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), kTileModes); michael@0: } else { michael@0: AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, michael@0: MakeDivByTextureWHMatrix(tex), michael@0: *domain))); michael@0: return CreateEffectRef(effect); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. michael@0: */ michael@0: static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, michael@0: SkShader::TileMode tileModes[2]) { michael@0: return Create(tex, gMitchellCoefficients, matrix, tileModes); michael@0: } michael@0: michael@0: /** michael@0: * Create a filter effect with custom bicubic coefficients, the texture matrix, and the x/y michael@0: * tilemodes. michael@0: */ michael@0: static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], michael@0: const SkMatrix& matrix, const SkShader::TileMode tileModes[2]) { michael@0: AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, matrix, tileModes))); michael@0: return CreateEffectRef(effect); michael@0: } michael@0: michael@0: /** michael@0: * Create a Mitchell filter effect with a texture matrix and a domain. michael@0: */ michael@0: static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const SkRect& domain) { michael@0: AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, gMitchellCoefficients, matrix, michael@0: domain))); michael@0: return CreateEffectRef(effect); michael@0: } michael@0: michael@0: private: michael@0: GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], michael@0: const SkMatrix &matrix, const SkShader::TileMode tileModes[2]); michael@0: GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], michael@0: const SkMatrix &matrix, const SkRect& domain); michael@0: virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; michael@0: michael@0: float fCoefficients[16]; michael@0: GrTextureDomain fDomain; michael@0: michael@0: GR_DECLARE_EFFECT_TEST; michael@0: michael@0: static const SkScalar gMitchellCoefficients[16]; michael@0: michael@0: typedef GrSingleTextureEffect INHERITED; michael@0: }; michael@0: michael@0: #endif