2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
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"
15 class GrGLSimpleTextureEffect : public GrGLEffect {
17 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
18 : INHERITED (factory) {
21 virtual void emitCode(GrGLShaderBuilder* builder,
22 const GrDrawEffect& drawEffect,
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,
33 builder->fsCodeAppend(";\n");
37 typedef GrGLEffect INHERITED;
40 ///////////////////////////////////////////////////////////////////////////////
42 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
43 this->updateConstantColorComponentsForModulation(color, validFlags);
46 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
47 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance();
50 ///////////////////////////////////////////////////////////////////////////////
52 GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect);
54 GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random,
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,
65 SkShader::TileMode tileModes[] = {
66 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
67 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
69 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
70 GrTextureParams::kNone_FilterMode);
72 static const GrCoordSet kCoordSets[] = {
76 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
78 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
79 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);