GrSingleTextureEffect.h revision 6251d17dfadbbeba8a7e72affde5cbdbd0c0c95f
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 "GrFragmentProcessor.h" 12#include "SkMatrix.h" 13#include "GrCoordTransform.h" 14 15class GrTexture; 16 17/** 18 * A base class for effects that draw a single texture with a texture matrix. This effect has no 19 * backend implementations. One must be provided by the subclass. 20 */ 21class GrSingleTextureEffect : public GrFragmentProcessor { 22public: 23 virtual ~GrSingleTextureEffect(); 24 25protected: 26 /** unfiltered, clamp mode */ 27 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet); 28 /** clamp mode */ 29 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode, 30 GrCoordSet = kLocal_GrCoordSet); 31 GrSingleTextureEffect(GrTexture*, 32 const SkMatrix&, 33 const GrTextureParams&, 34 GrCoordSet = kLocal_GrCoordSet); 35 36 /** 37 * Helper for subclass onIsEqual() functions. 38 */ 39 bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect& other) const { 40 // We don't have to check the accesses' swizzles because they are inferred from the texture. 41 return fTextureAccess == other.fTextureAccess && 42 fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.getMatrix()) && 43 fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoords(); 44 } 45 46 /** 47 * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that 48 * the subclass output color will be a modulation of the input color with a value read from the 49 * texture. 50 */ 51 void updateInvariantOutputForModulation(InvariantOutput* inout) const { 52 if (GrPixelConfigIsOpaque(this->texture(0)->config())) { 53 inout->mulByUnknownOpaqueColor(); 54 } else { 55 inout->mulByUnknownColor(); 56 } 57 } 58 59private: 60 GrCoordTransform fCoordTransform; 61 GrTextureAccess fTextureAccess; 62 63 typedef GrFragmentProcessor INHERITED; 64}; 65 66#endif 67