Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: src/gpu/effects/GrSimpleTextureEffect.cpp

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrSimpleTextureEffect.h ('k') | src/gpu/effects/GrSingleTextureEffect.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrSimpleTextureEffect.h" 8 #include "GrSimpleTextureEffect.h"
9 #include "gl/GrGLEffect.h" 9 #include "gl/GrGLEffect.h"
10 #include "gl/GrGLEffectMatrix.h" 10 #include "gl/GrGLEffectMatrix.h"
11 #include "gl/GrGLSL.h" 11 #include "gl/GrGLSL.h"
12 #include "gl/GrGLTexture.h" 12 #include "gl/GrGLTexture.h"
13 #include "GrTBackendEffectFactory.h" 13 #include "GrTBackendEffectFactory.h"
14 #include "GrTexture.h" 14 #include "GrTexture.h"
15 15
16 class GrGLSimpleTextureEffect : public GrGLEffect { 16 class GrGLSimpleTextureEffect : public GrGLEffect {
17 public: 17 public:
18 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrEffec tRef&) 18 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawE ffect& drawEffect)
19 : INHERITED (factory) {} 19 : INHERITED (factory) {
20 GrEffect::CoordsType coordsType =
21 drawEffect.castEffect<GrSimpleTextureEffect>().coordsType();
22 if (GrEffect::kCustom_CoordsType != coordsType) {
23 SkNEW_IN_TLAZY(&fEffectMatrix, GrGLEffectMatrix, (coordsType));
24 }
25 }
20 26
21 virtual void emitCode(GrGLShaderBuilder* builder, 27 virtual void emitCode(GrGLShaderBuilder* builder,
22 const GrEffectStage&, 28 const GrDrawEffect& drawEffect,
23 EffectKey key, 29 EffectKey key,
24 const char* vertexCoords,
25 const char* outputColor, 30 const char* outputColor,
26 const char* inputColor, 31 const char* inputColor,
27 const TextureSamplerArray& samplers) SK_OVERRIDE { 32 const TextureSamplerArray& samplers) SK_OVERRIDE {
28 const char* coordName; 33 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>();
29 GrSLType coordType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coordName); 34 const char* fsCoordName;
35 GrSLType fsCoordSLType;
36 if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
37 GrAssert(ste.getMatrix().isIdentity());
38 GrAssert(1 == ste.numVertexAttribs());
39 fsCoordSLType = kVec2f_GrSLType;
40 const char* vsVaryingName;
41 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName , &fsCoordName);
42 const char* attrName =
43 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0])->c_str();
44 builder->vsCodeAppendf("\t%s = %s;", vsVaryingName, attrName);
45 } else {
46 fsCoordSLType = fEffectMatrix.get()->emitCode(builder, key, &fsCoord Name);
47 }
30 builder->fsCodeAppendf("\t%s = ", outputColor); 48 builder->fsCodeAppendf("\t%s = ", outputColor);
31 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_Sha derType, 49 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_Sha derType,
32 inputColor, 50 inputColor,
33 samplers[0], 51 samplers[0],
34 coordName, 52 fsCoordName,
35 coordType); 53 fsCoordSLType);
36 builder->fsCodeAppend(";\n"); 54 builder->fsCodeAppend(";\n");
37 } 55 }
38 56
39 static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) { 57 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) {
40 const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEff ect>(stage); 58 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>();
41 return GrGLEffectMatrix::GenKey(ste.getMatrix(), 59 if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
42 stage.getCoordChangeMatrix(), 60 return 1 << GrGLEffectMatrix::kKeyBits;
43 ste.texture(0)); 61 } else {
62 return GrGLEffectMatrix::GenKey(ste.getMatrix(),
63 drawEffect,
64 ste.coordsType(),
65 ste.texture(0));
66 }
44 } 67 }
45 68
46 virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& st age) SK_OVERRIDE { 69 virtual void setData(const GrGLUniformManager& uman,
47 const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEff ect>(stage); 70 const GrDrawEffect& drawEffect) SK_OVERRIDE {
48 fEffectMatrix.setData(uman, ste.getMatrix(), stage.getCoordChangeMatrix( ), ste.texture(0)); 71 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>();
72 if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
73 GrAssert(ste.getMatrix().isIdentity());
74 } else {
75 fEffectMatrix.get()->setData(uman, ste.getMatrix(), drawEffect, ste. texture(0));
76 }
49 } 77 }
50 78
51 private: 79 private:
52 GrGLEffectMatrix fEffectMatrix; 80 SkTLazy<GrGLEffectMatrix> fEffectMatrix;
53 typedef GrGLEffect INHERITED; 81 typedef GrGLEffect INHERITED;
54 }; 82 };
55 83
56 /////////////////////////////////////////////////////////////////////////////// 84 ///////////////////////////////////////////////////////////////////////////////
57 85
58 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 86 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
59 this->updateConstantColorComponentsForModulation(color, validFlags); 87 this->updateConstantColorComponentsForModulation(color, validFlags);
60 } 88 }
61 89
62 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { 90 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
63 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance(); 91 return GrTBackendEffectFactory<GrSimpleTextureEffect>::getInstance();
64 } 92 }
65 93
66 /////////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////////
67 95
68 GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect); 96 GR_DEFINE_EFFECT_TEST(GrSimpleTextureEffect);
69 97
70 GrEffectRef* GrSimpleTextureEffect::TestCreate(SkMWCRandom* random, 98 GrEffectRef* GrSimpleTextureEffect::TestCreate(SkMWCRandom* random,
71 GrContext*, 99 GrContext*,
72 GrTexture* textures[]) { 100 GrTexture* textures[]) {
73 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 101 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
74 GrEffectUnitTest::kAlphaTextureIdx; 102 GrEffectUnitTest::kAlphaTextureIdx;
75 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 103 static const SkShader::TileMode kTileModes[] = {
76 return GrSimpleTextureEffect::Create(textures[texIdx], matrix); 104 SkShader::kClamp_TileMode,
105 SkShader::kRepeat_TileMode,
106 SkShader::kMirror_TileMode,
107 };
108 SkShader::TileMode tileModes[] = {
109 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
110 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
111 };
112 GrTextureParams params(tileModes, random->nextBool());
113
114 static const CoordsType kCoordsTypes[] = {
115 kLocal_CoordsType,
116 kPosition_CoordsType,
117 kCustom_CoordsType
118 };
119 CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kC oordsTypes))];
120
121 if (kCustom_CoordsType == coordsType) {
122 return GrSimpleTextureEffect::CreateWithCustomCoords(textures[texIdx], p arams);
123 } else {
124 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
125 return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
126 }
77 } 127 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrSimpleTextureEffect.h ('k') | src/gpu/effects/GrSingleTextureEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698