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