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 "GrCoordTransform.h" 13#include "GrInvariantOutput.h" 14#include "SkMatrix.h" 15 16class GrTexture; 17 18/** 19 * A base class for effects that draw a single texture with a texture matrix. This effect has no 20 * backend implementations. One must be provided by the subclass. 21 */ 22class GrSingleTextureEffect : public GrFragmentProcessor { 23public: 24 virtual ~GrSingleTextureEffect(); 25 26protected: 27 /** unfiltered, clamp mode */ 28 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet); 29 /** clamp mode */ 30 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode, 31 GrCoordSet = kLocal_GrCoordSet); 32 GrSingleTextureEffect(GrTexture*, 33 const SkMatrix&, 34 const GrTextureParams&, 35 GrCoordSet = kLocal_GrCoordSet); 36 37 /** 38 * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that 39 * the subclass output color will be a modulation of the input color with a value read from the 40 * texture. 41 */ 42 void updateInvariantOutputForModulation(GrInvariantOutput* inout) const { 43 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { 44 inout->mulByUnknownSingleComponent(); 45 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { 46 inout->mulByUnknownOpaqueFourComponents(); 47 } else { 48 inout->mulByUnknownFourComponents(); 49 } 50 } 51 52private: 53 GrCoordTransform fCoordTransform; 54 GrTextureAccess fTextureAccess; 55 56 typedef GrFragmentProcessor INHERITED; 57}; 58 59#endif 60