gfx/skia/trunk/src/gpu/effects/GrBicubicEffect.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/effects/GrBicubicEffect.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,98 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef GrBicubicTextureEffect_DEFINED
    1.12 +#define GrBicubicTextureEffect_DEFINED
    1.13 +
    1.14 +#include "GrSingleTextureEffect.h"
    1.15 +#include "GrTextureDomain.h"
    1.16 +#include "GrDrawEffect.h"
    1.17 +#include "gl/GrGLEffect.h"
    1.18 +#include "GrTBackendEffectFactory.h"
    1.19 +
    1.20 +class GrGLBicubicEffect;
    1.21 +
    1.22 +class GrBicubicEffect : public GrSingleTextureEffect {
    1.23 +public:
    1.24 +    enum {
    1.25 +        kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of
    1.26 +                             // surrounding texels are needed by the kernel in x and y.
    1.27 +    };
    1.28 +    virtual ~GrBicubicEffect();
    1.29 +
    1.30 +    static const char* Name() { return "Bicubic"; }
    1.31 +    const float* coefficients() const { return fCoefficients; }
    1.32 +
    1.33 +    typedef GrGLBicubicEffect GLEffect;
    1.34 +
    1.35 +    virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
    1.36 +    virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
    1.37 +
    1.38 +    const GrTextureDomain& domain() const { return fDomain; }
    1.39 +
    1.40 +    /**
    1.41 +     * Create a simple filter effect with custom bicubic coefficients and optional domain.
    1.42 +     */
    1.43 +    static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16],
    1.44 +                               const SkRect* domain = NULL) {
    1.45 +        if (NULL == domain) {
    1.46 +            static const SkShader::TileMode kTileModes[] = { SkShader::kClamp_TileMode,
    1.47 +                                                             SkShader::kClamp_TileMode };
    1.48 +            return Create(tex, coefficients, MakeDivByTextureWHMatrix(tex), kTileModes);
    1.49 +        } else {
    1.50 +            AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients,
    1.51 +                                                                MakeDivByTextureWHMatrix(tex),
    1.52 +                                                                *domain)));
    1.53 +            return CreateEffectRef(effect);
    1.54 +        }
    1.55 +    }
    1.56 +
    1.57 +    /**
    1.58 +     * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
    1.59 +     */
    1.60 +    static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix,
    1.61 +                               SkShader::TileMode tileModes[2]) {
    1.62 +        return Create(tex, gMitchellCoefficients, matrix, tileModes);
    1.63 +    }
    1.64 +
    1.65 +    /**
    1.66 +     * Create a filter effect with custom bicubic coefficients, the texture matrix, and the x/y
    1.67 +     * tilemodes.
    1.68 +     */
    1.69 +    static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16],
    1.70 +                               const SkMatrix& matrix, const SkShader::TileMode tileModes[2]) {
    1.71 +        AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, matrix, tileModes)));
    1.72 +        return CreateEffectRef(effect);
    1.73 +    }
    1.74 +
    1.75 +    /**
    1.76 +     * Create a Mitchell filter effect with a texture matrix and a domain.
    1.77 +     */
    1.78 +    static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const SkRect& domain) {
    1.79 +        AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, gMitchellCoefficients, matrix,
    1.80 +                                                            domain)));
    1.81 +        return CreateEffectRef(effect);
    1.82 +    }
    1.83 +
    1.84 +private:
    1.85 +    GrBicubicEffect(GrTexture*, const SkScalar coefficients[16],
    1.86 +                    const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
    1.87 +    GrBicubicEffect(GrTexture*, const SkScalar coefficients[16],
    1.88 +                    const SkMatrix &matrix, const SkRect& domain);
    1.89 +    virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
    1.90 +
    1.91 +    float           fCoefficients[16];
    1.92 +    GrTextureDomain fDomain;
    1.93 +
    1.94 +    GR_DECLARE_EFFECT_TEST;
    1.95 +
    1.96 +    static const SkScalar gMitchellCoefficients[16];
    1.97 +
    1.98 +    typedef GrSingleTextureEffect INHERITED;
    1.99 +};
   1.100 +
   1.101 +#endif

mercurial