michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "GrSimpleTextureEffect.h" michael@0: #include "gl/GrGLEffect.h" michael@0: #include "gl/GrGLSL.h" michael@0: #include "gl/GrGLTexture.h" michael@0: #include "GrTBackendEffectFactory.h" michael@0: #include "GrTexture.h" michael@0: michael@0: class GrGLSimpleTextureEffect : public GrGLEffect { michael@0: public: michael@0: GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) michael@0: : INHERITED (factory) { michael@0: } michael@0: michael@0: virtual void emitCode(GrGLShaderBuilder* builder, michael@0: const GrDrawEffect& drawEffect, michael@0: EffectKey key, michael@0: const char* outputColor, michael@0: const char* inputColor, michael@0: const TransformedCoordsArray& coords, michael@0: const TextureSamplerArray& samplers) SK_OVERRIDE { michael@0: builder->fsCodeAppendf("\t%s = ", outputColor); michael@0: builder->fsAppendTextureLookupAndModulate(inputColor, michael@0: samplers[0], michael@0: coords[0].c_str(), michael@0: coords[0].type()); michael@0: builder->fsCodeAppend(";\n"); michael@0: } michael@0: michael@0: private: michael@0: typedef GrGLEffect INHERITED; michael@0: }; michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { michael@0: this->updateConstantColorComponentsForModulation(color, validFlags); michael@0: } michael@0: michael@0: const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { michael@0: return GrTBackendEffectFactory::getInstance(); michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect); michael@0: michael@0: GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random, michael@0: GrContext*, michael@0: const GrDrawTargetCaps&, michael@0: GrTexture* textures[]) { michael@0: int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : michael@0: GrEffectUnitTest::kAlphaTextureIdx; michael@0: static const SkShader::TileMode kTileModes[] = { michael@0: SkShader::kClamp_TileMode, michael@0: SkShader::kRepeat_TileMode, michael@0: SkShader::kMirror_TileMode, michael@0: }; michael@0: SkShader::TileMode tileModes[] = { michael@0: kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], michael@0: kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], michael@0: }; michael@0: GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode : michael@0: GrTextureParams::kNone_FilterMode); michael@0: michael@0: static const GrCoordSet kCoordSets[] = { michael@0: kLocal_GrCoordSet, michael@0: kPosition_GrCoordSet michael@0: }; michael@0: GrCoordSet coordSet = kCoordSets[random->nextULessThan(GR_ARRAY_COUNT(kCoordSets))]; michael@0: michael@0: const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); michael@0: return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet); michael@0: }