• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrDrawEffect.h"
13 #include "gl/GrGLEffect.h"
14 #include "GrTBackendEffectFactory.h"
15 
16 class GrGLBicubicEffect;
17 
18 class GrBicubicEffect : public GrSingleTextureEffect {
19 public:
20     enum {
21         kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of
22                              // surrounding texels are needed by the kernel in x and y.
23     };
24     virtual ~GrBicubicEffect();
25 
Name()26     static const char* Name() { return "Bicubic"; }
coefficients()27     const float* coefficients() const { return fCoefficients; }
28 
29     typedef GrGLBicubicEffect GLEffect;
30 
31     virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
32     virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
33 
34     /**
35      * Create a simple Mitchell filter effect.
36      */
Create(GrTexture * tex)37     static GrEffectRef* Create(GrTexture* tex) {
38         return Create(tex, gMitchellCoefficients);
39     }
40 
41     /**
42      * Create a simple filter effect with custom bicubic coefficients.
43      */
Create(GrTexture * tex,const SkScalar coefficients[16])44     static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16]) {
45         const SkShader::TileMode tm[] = { SkShader::kClamp_TileMode, SkShader::kClamp_TileMode };
46         return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), tm);
47     }
48 
49     /**
50      * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
51      */
Create(GrTexture * tex,const SkMatrix & matrix,SkShader::TileMode tileModes[2])52     static GrEffectRef* Create(GrTexture* tex,
53                                const SkMatrix& matrix,
54                                SkShader::TileMode tileModes[2]) {
55         return Create(tex, gMitchellCoefficients, matrix, tileModes);
56     }
57 
58     /**
59      * The most general Create method. This allows specification of the bicubic coefficients, the
60      * texture matrix, and the x/y tilemodes.
61      */
Create(GrTexture * tex,const SkScalar coefficients[16],const SkMatrix & matrix,const SkShader::TileMode tileModes[2])62     static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16],
63                                const SkMatrix& matrix,
64                                const SkShader::TileMode tileModes[2]) {
65         AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, matrix, tileModes)));
66         return CreateEffectRef(effect);
67     }
68 
69 private:
70     GrBicubicEffect(GrTexture*, const SkScalar coefficients[16],
71                     const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
72     virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
73     float    fCoefficients[16];
74 
75     GR_DECLARE_EFFECT_TEST;
76 
77     static const SkScalar gMitchellCoefficients[16];
78 
79     typedef GrSingleTextureEffect INHERITED;
80 };
81 
82 #endif
83