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 "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"
16 class GrGLSimpleTextureEffect : public GrGLFragmentProcessor {
18 GrGLSimpleTextureEffect(const GrBackendProcessorFactory& factory, const GrProcessor&)
19 : INHERITED (factory) {
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,
35 fsBuilder->codeAppend(";\n");
39 typedef GrGLFragmentProcessor INHERITED;
42 ///////////////////////////////////////////////////////////////////////////////
44 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
45 this->updateConstantColorComponentsForModulation(color, validFlags);
48 const GrBackendFragmentProcessorFactory& GrSimpleTextureEffect::getFactory() const {
49 return GrTBackendFragmentProcessorFactory<GrSimpleTextureEffect>::getInstance();
52 ///////////////////////////////////////////////////////////////////////////////
54 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
56 GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(SkRandom* random,
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,
67 SkShader::TileMode tileModes[] = {
68 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
69 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
71 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
72 GrTextureParams::kNone_FilterMode);
74 static const GrCoordSet kCoordSets[] = {
78 GrCoordSet coordSet = kCoordSets[random->nextULessThan(SK_ARRAY_COUNT(kCoordSets))];
80 const SkMatrix& matrix = GrProcessorUnitTest::TestMatrix(random);
81 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);