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

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

Issue 24018007: Add a GrCustomCoordsTextureEffect class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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 GrDrawE ffect& drawEffect) 18 GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawE ffect& drawEffect)
19 : INHERITED (factory) { 19 : INHERITED (factory)
20 GrEffect::CoordsType coordsType = 20 , fEffectMatrix(drawEffect.castEffect<GrSimpleTextureEffect>().coordsTyp e()) {
21 drawEffect.castEffect<GrSimpleTextureEffect>().coordsType();
22 if (GrEffect::kCustom_CoordsType != coordsType) {
23 SkNEW_IN_TLAZY(&fEffectMatrix, GrGLEffectMatrix, (coordsType));
24 }
25 } 21 }
26 22
27 virtual void emitCode(GrGLShaderBuilder* builder, 23 virtual void emitCode(GrGLShaderBuilder* builder,
28 const GrDrawEffect& drawEffect, 24 const GrDrawEffect& drawEffect,
29 EffectKey key, 25 EffectKey key,
30 const char* outputColor, 26 const char* outputColor,
31 const char* inputColor, 27 const char* inputColor,
32 const TextureSamplerArray& samplers) SK_OVERRIDE { 28 const TextureSamplerArray& samplers) SK_OVERRIDE {
33 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>();
34 SkString fsCoordName; 29 SkString fsCoordName;
35 GrSLType fsCoordSLType; 30 GrSLType fsCoordSLType;
36 if (GrEffect::kCustom_CoordsType == ste.coordsType()) { 31 fsCoordSLType = fEffectMatrix.emitCode(builder, key, &fsCoordName);
37 SkASSERT(ste.getMatrix().isIdentity()); 32
38 SkASSERT(1 == ste.numVertexAttribs());
39 fsCoordSLType = kVec2f_GrSLType;
40 const char* vsVaryingName;
41 const char* fsVaryingNamePtr;
42 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex Builder();
43 SkASSERT(NULL != vertexBuilder);
44 vertexBuilder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryi ngName, &fsVaryingNamePtr);
45 fsCoordName = fsVaryingNamePtr;
46 const char* attrName =
47 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib Indices()[0])->c_str();
48 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName );
49 } else {
50 fsCoordSLType = fEffectMatrix.get()->emitCode(builder, key, &fsCoord Name);
51 }
52 builder->fsCodeAppendf("\t%s = ", outputColor); 33 builder->fsCodeAppendf("\t%s = ", outputColor);
53 builder->fsAppendTextureLookupAndModulate(inputColor, 34 builder->fsAppendTextureLookupAndModulate(inputColor,
54 samplers[0], 35 samplers[0],
55 fsCoordName.c_str(), 36 fsCoordName.c_str(),
56 fsCoordSLType); 37 fsCoordSLType);
57 builder->fsCodeAppend(";\n"); 38 builder->fsCodeAppend(";\n");
58 } 39 }
59 40
60 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) { 41 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) {
61 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>(); 42 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>();
62 if (GrEffect::kCustom_CoordsType == ste.coordsType()) { 43 return GrGLEffectMatrix::GenKey(ste.getMatrix(),
63 return 1 << GrGLEffectMatrix::kKeyBits; 44 drawEffect,
64 } else { 45 ste.coordsType(),
65 return GrGLEffectMatrix::GenKey(ste.getMatrix(), 46 ste.texture(0));
66 drawEffect,
67 ste.coordsType(),
68 ste.texture(0));
69 }
70 } 47 }
71 48
72 virtual void setData(const GrGLUniformManager& uman, 49 virtual void setData(const GrGLUniformManager& uman,
73 const GrDrawEffect& drawEffect) SK_OVERRIDE { 50 const GrDrawEffect& drawEffect) SK_OVERRIDE {
74 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>(); 51 const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTexture Effect>();
75 if (GrEffect::kCustom_CoordsType == ste.coordsType()) { 52 fEffectMatrix.setData(uman, ste.getMatrix(), drawEffect, ste.texture(0)) ;
76 SkASSERT(ste.getMatrix().isIdentity());
77 } else {
78 fEffectMatrix.get()->setData(uman, ste.getMatrix(), drawEffect, ste. texture(0));
79 }
80 } 53 }
81 54
82 private: 55 private:
83 SkTLazy<GrGLEffectMatrix> fEffectMatrix; 56 GrGLEffectMatrix fEffectMatrix;
84 typedef GrGLEffect INHERITED; 57 typedef GrGLEffect INHERITED;
85 }; 58 };
86 59
87 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
88 61
89 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 62 void GrSimpleTextureEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
90 this->updateConstantColorComponentsForModulation(color, validFlags); 63 this->updateConstantColorComponentsForModulation(color, validFlags);
91 } 64 }
92 65
93 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const { 66 const GrBackendEffectFactory& GrSimpleTextureEffect::getFactory() const {
(...skipping 17 matching lines...) Expand all
111 }; 84 };
112 SkShader::TileMode tileModes[] = { 85 SkShader::TileMode tileModes[] = {
113 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 86 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
114 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], 87 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
115 }; 88 };
116 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : 89 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode :
117 GrTextureParams::kNon e_FilterMode); 90 GrTextureParams::kNon e_FilterMode);
118 91
119 static const CoordsType kCoordsTypes[] = { 92 static const CoordsType kCoordsTypes[] = {
120 kLocal_CoordsType, 93 kLocal_CoordsType,
121 kPosition_CoordsType, 94 kPosition_CoordsType
122 kCustom_CoordsType
123 }; 95 };
124 CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kC oordsTypes))]; 96 CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kC oordsTypes))];
125 97
126 if (kCustom_CoordsType == coordsType) { 98 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
127 return GrSimpleTextureEffect::CreateWithCustomCoords(textures[texIdx], p arams); 99 return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordsType);
128 } else {
129 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
130 return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
131 }
132 } 100 }
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