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 #include "GrSimpleTextureEffect.h" 9 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLSL.h" 11 #include "gl/GrGLTexture.h" 12 #include "GrTBackendEffectFactory.h" 13 #include "GrTexture.h" 14 15 class GrGLSimpleTextureEffect : public GrGLEffect { 16 public: 17 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 18 : INHERITED (factory) { 19 } 20 21 virtual void emitCode(GrGLShaderBuilder* builder, 22 const GrDrawEffect& drawEffect, 23 EffectKey key, 24 const char* outputColor, 25 const char* inputColor, 26 const TransformedCoordsArray& coords, 27 const TextureSamplerArray& samplers) SK_OVERRIDE { 28 builder->fsCodeAppendf("\t%s = ", outputColor); 29 builder->fsAppendTextureLookupAndModulate(inputColor, 30 samplers[0], 31 coords[0].c_str(), 32 coords[0].type()); 33 builder->fsCodeAppend(";\n"); 34 } 35 36 private: 37 typedef GrGLEffect INHERITED; 38 }; 39 40 /////////////////////////////////////////////////////////////////////////////// 41 42 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 43 this->updateConstantColorComponentsForModulation(color, validFlags); 44 } 45 46 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { 47 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance(); 48 } 49 50 /////////////////////////////////////////////////////////////////////////////// 51 52 GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect); 53 54 GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random, 55 GrContext*, 56 const GrDrawTargetCaps&, 57 GrTexture* textures[]) { 58 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 59 GrEffectUnitTest::kAlphaTextureIdx; 60 static const SkShader::TileMode kTileModes[] = { 61 SkShader::kClamp_TileMode, 62 SkShader::kRepeat_TileMode, 63 SkShader::kMirror_TileMode, 64 }; 65 SkShader::TileMode tileModes[] = { 66 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 67 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 68 }; 69 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode : 70 GrTextureParams::kNone_FilterMode); 71 72 static const GrCoordSet kCoordSets[] = { 73 kLocal_GrCoordSet, 74 kPosition_GrCoordSet 75 }; 76 GrCoordSet coordSet = kCoordSets[random->nextULessThan(GR_ARRAY_COUNT(kCoordSets))]; 77 78 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 79 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet); 80 } 81