Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef GrBicubicTextureEffect_DEFINED |
michael@0 | 9 | #define GrBicubicTextureEffect_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "GrSingleTextureEffect.h" |
michael@0 | 12 | #include "GrTextureDomain.h" |
michael@0 | 13 | #include "GrDrawEffect.h" |
michael@0 | 14 | #include "gl/GrGLEffect.h" |
michael@0 | 15 | #include "GrTBackendEffectFactory.h" |
michael@0 | 16 | |
michael@0 | 17 | class GrGLBicubicEffect; |
michael@0 | 18 | |
michael@0 | 19 | class GrBicubicEffect : public GrSingleTextureEffect { |
michael@0 | 20 | public: |
michael@0 | 21 | enum { |
michael@0 | 22 | kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of |
michael@0 | 23 | // surrounding texels are needed by the kernel in x and y. |
michael@0 | 24 | }; |
michael@0 | 25 | virtual ~GrBicubicEffect(); |
michael@0 | 26 | |
michael@0 | 27 | static const char* Name() { return "Bicubic"; } |
michael@0 | 28 | const float* coefficients() const { return fCoefficients; } |
michael@0 | 29 | |
michael@0 | 30 | typedef GrGLBicubicEffect GLEffect; |
michael@0 | 31 | |
michael@0 | 32 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
michael@0 | 33 | virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
michael@0 | 34 | |
michael@0 | 35 | const GrTextureDomain& domain() const { return fDomain; } |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Create a simple filter effect with custom bicubic coefficients and optional domain. |
michael@0 | 39 | */ |
michael@0 | 40 | static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], |
michael@0 | 41 | const SkRect* domain = NULL) { |
michael@0 | 42 | if (NULL == domain) { |
michael@0 | 43 | static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_TileMode, |
michael@0 | 44 | SkShader::kClamp_TileMode }; |
michael@0 | 45 | return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), kTileModes); |
michael@0 | 46 | } else { |
michael@0 | 47 | AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, |
michael@0 | 48 | MakeDivByTextureWHMatrix(tex), |
michael@0 | 49 | *domain))); |
michael@0 | 50 | return CreateEffectRef(effect); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | /** |
michael@0 | 55 | * Create a Mitchell filter effect with specified texture matrix and x/y tile modes. |
michael@0 | 56 | */ |
michael@0 | 57 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, |
michael@0 | 58 | SkShader::TileMode tileModes[2]) { |
michael@0 | 59 | return Create(tex, gMitchellCoefficients, matrix, tileModes); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | /** |
michael@0 | 63 | * Create a filter effect with custom bicubic coefficients, the texture matrix, and the x/y |
michael@0 | 64 | * tilemodes. |
michael@0 | 65 | */ |
michael@0 | 66 | static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16], |
michael@0 | 67 | const SkMatrix& matrix, const SkShader::TileMode tileModes[2]) { |
michael@0 | 68 | AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, matrix, tileModes))); |
michael@0 | 69 | return CreateEffectRef(effect); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Create a Mitchell filter effect with a texture matrix and a domain. |
michael@0 | 74 | */ |
michael@0 | 75 | static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const SkRect& domain) { |
michael@0 | 76 | AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, gMitchellCoefficients, matrix, |
michael@0 | 77 | domain))); |
michael@0 | 78 | return CreateEffectRef(effect); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | private: |
michael@0 | 82 | GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], |
michael@0 | 83 | const SkMatrix &matrix, const SkShader::TileMode tileModes[2]); |
michael@0 | 84 | GrBicubicEffect(GrTexture*, const SkScalar coefficients[16], |
michael@0 | 85 | const SkMatrix &matrix, const SkRect& domain); |
michael@0 | 86 | virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
michael@0 | 87 | |
michael@0 | 88 | float fCoefficients[16]; |
michael@0 | 89 | GrTextureDomain fDomain; |
michael@0 | 90 | |
michael@0 | 91 | GR_DECLARE_EFFECT_TEST; |
michael@0 | 92 | |
michael@0 | 93 | static const SkScalar gMitchellCoefficients[16]; |
michael@0 | 94 | |
michael@0 | 95 | typedef GrSingleTextureEffect INHERITED; |
michael@0 | 96 | }; |
michael@0 | 97 | |
michael@0 | 98 | #endif |