GrSimpleTextureEffect.h revision 68b58c95384dd6c2fd389a5b4bbf8fc468819454
168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com/*
268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * Copyright 2013 Google Inc.
368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com *
468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * Use of this source code is governed by a BSD-style license that can be
568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * found in the LICENSE file.
668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com */
768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#ifndef GrSimpleTextureEffect_DEFINED
968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#define GrSimpleTextureEffect_DEFINED
1068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
1168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#include "GrSingleTextureEffect.h"
1268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
1368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comclass GrGLSimpleTextureEffect;
1468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
1568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com/**
1668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * The output color of this effect is a modulation of the input color and a sample from a texture.
1768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * The coord to sample the texture is determine by a matrix. It allows explicit specification of
1868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com * the filtering and wrap modes (GrTextureParams).
1968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com */
2068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comclass GrSimpleTextureEffect : public GrSingleTextureEffect {
2168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.compublic:
2268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    /* unfiltered, clamp mode */
2368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) {
2468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix)));
2568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        return CreateEffectRef(effect);
2668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    }
2768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
2868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    /* clamp mode */
2968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) {
3068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, bilerp)));
3168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        return CreateEffectRef(effect);
3268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    }
3368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
3468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) {
3568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p)));
3668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        return CreateEffectRef(effect);
3768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    }
3868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
3968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    virtual ~GrSimpleTextureEffect() {}
4068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
4168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    static const char* Name() { return "Texture"; }
4268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
4368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
4468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
4568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    typedef GrGLSimpleTextureEffect GLEffect;
4668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
4768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
4868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
4968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.comprivate:
5068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix)
5168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        : GrSingleTextureEffect(texture, matrix) {}
5268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, bool bilerp)
5368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        : GrSingleTextureEffect(texture, matrix, bilerp) {}
5468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, const GrTextureParams& params)
5568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        : GrSingleTextureEffect(texture, matrix, params) {}
5668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
5768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
5868b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        const GrSimpleTextureEffect& ste = static_cast<const GrSimpleTextureEffect&>(other);
5968b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com        return this->hasSameTextureParamsAndMatrix(ste);
6068b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    }
6168b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
6268b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    GR_DECLARE_EFFECT_TEST;
6368b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
6468b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com    typedef GrSingleTextureEffect INHERITED;
6568b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com};
6668b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com
6768b58c95384dd6c2fd389a5b4bbf8fc468819454bsalomon@google.com#endif
68