GrSingleTextureEffect.h revision a1ebbe447d5eab098111eb83580e55f2f5f6faca
1/* 2 * Copyright 2012 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 GrSingleTextureEffect_DEFINED 9#define GrSingleTextureEffect_DEFINED 10 11#include "GrEffect.h" 12#include "SkMatrix.h" 13 14class GrGLSingleTextureEffect; 15class GrTexture; 16 17/** 18 * An effect that draws a single texture with a texture matrix; commonly used as a base class. The 19 * output color is the texture color is modulated against the input color. 20 */ 21class GrSingleTextureEffect : public GrEffect { 22public: 23 /* unfiltered, clamp mode */ 24 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) { 25 SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix))); 26 return CreateEffectRef(effect); 27 } 28 29 /* clamp mode */ 30 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) { 31 SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, bilerp))); 32 return CreateEffectRef(effect); 33 } 34 35 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) { 36 SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, p))); 37 return CreateEffectRef(effect); 38 } 39 40 virtual ~GrSingleTextureEffect(); 41 42 static const char* Name() { return "Single Texture"; } 43 44 /** Note that if this class is sub-classed, the subclass may have to override this function. 45 */ 46 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; 47 48 const SkMatrix& getMatrix() const { return fMatrix; } 49 50 typedef GrGLSingleTextureEffect GLEffect; 51 52 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; 53 54 virtual bool isEqual(const GrEffect& effect) const SK_OVERRIDE { 55 const GrSingleTextureEffect& ste = static_cast<const GrSingleTextureEffect&>(effect); 56 return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix()); 57 } 58 59protected: 60 GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */ 61 GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */ 62 GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&); 63 64private: 65 66 GR_DECLARE_EFFECT_TEST; 67 68 GrTextureAccess fTextureAccess; 69 SkMatrix fMatrix; 70 71 typedef GrEffect INHERITED; 72}; 73 74#endif 75