OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrCustomCoordsTextureEffect.h" | 8 #include "GrCustomCoordsTextureEffect.h" |
9 #include "gl/builders/GrGLFullProgramBuilder.h" | 9 #include "gl/builders/GrGLFullProgramBuilder.h" |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLProcessor.h" |
11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
14 #include "GrTBackendEffectFactory.h" | 14 #include "GrTBackendProcessorFactory.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 | 16 |
17 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { | 17 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { |
18 public: | 18 public: |
19 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rEffect& effect) | 19 GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor& effect) |
20 : INHERITED (factory) {} | 20 : INHERITED (factory) {} |
21 | 21 |
22 virtual void emitCode(GrGLFullProgramBuilder* builder, | 22 virtual void emitCode(GrGLFullProgramBuilder* builder, |
23 const GrEffect& effect, | 23 const GrGeometryProcessor& geometryProcessor, |
24 const GrEffectKey& key, | 24 const GrProcessorKey& key, |
25 const char* outputColor, | 25 const char* outputColor, |
26 const char* inputColor, | 26 const char* inputColor, |
27 const TransformedCoordsArray&, | 27 const TransformedCoordsArray&, |
28 const TextureSamplerArray& samplers) SK_OVERRIDE { | 28 const TextureSamplerArray& samplers) SK_OVERRIDE { |
29 const GrCustomCoordsTextureEffect& customCoordsTextureEffect = | 29 const GrCustomCoordsTextureEffect& customCoordsTextureEffect = |
30 effect.cast<GrCustomCoordsTextureEffect>(); | 30 geometryProcessor.cast<GrCustomCoordsTextureEffect>(); |
31 SkASSERT(1 == customCoordsTextureEffect.getVertexAttribs().count()); | 31 SkASSERT(1 == customCoordsTextureEffect.getVertexAttribs().count()); |
32 | 32 |
33 SkString fsCoordName; | 33 SkString fsCoordName; |
34 const char* vsVaryingName; | 34 const char* vsVaryingName; |
35 const char* fsVaryingNamePtr; | 35 const char* fsVaryingNamePtr; |
36 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &f
sVaryingNamePtr); | 36 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &f
sVaryingNamePtr); |
37 fsCoordName = fsVaryingNamePtr; | 37 fsCoordName = fsVaryingNamePtr; |
38 | 38 |
39 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 39 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
40 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); | 40 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); |
41 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, inTextureCoords.c_
str()); | 41 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, inTextureCoords.c_
str()); |
42 | 42 |
43 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 43 GrGLBaseFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
44 fsBuilder->codeAppendf("\t%s = ", outputColor); | 44 fsBuilder->codeAppendf("\t%s = ", outputColor); |
45 fsBuilder->appendTextureLookupAndModulate(inputColor, | 45 fsBuilder->appendTextureLookupAndModulate(inputColor, |
46 samplers[0], | 46 samplers[0], |
47 fsCoordName.c_str(), | 47 fsCoordName.c_str(), |
48 kVec2f_GrSLType); | 48 kVec2f_GrSLType); |
49 fsBuilder->codeAppend(";\n"); | 49 fsBuilder->codeAppend(";\n"); |
50 } | 50 } |
51 | 51 |
52 virtual void setData(const GrGLProgramDataManager& pdman, | 52 virtual void setData(const GrGLProgramDataManager&, |
53 const GrEffect& effect) SK_OVERRIDE {} | 53 const GrProcessor&) SK_OVERRIDE {} |
54 | 54 |
55 private: | 55 private: |
56 typedef GrGLGeometryProcessor INHERITED; | 56 typedef GrGLGeometryProcessor INHERITED; |
57 }; | 57 }; |
58 | 58 |
59 /////////////////////////////////////////////////////////////////////////////// | 59 /////////////////////////////////////////////////////////////////////////////// |
60 | 60 |
61 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, | 61 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, |
62 const GrTextureParams&
params) | 62 const GrTextureParams&
params) |
63 : fTextureAccess(texture, params) | 63 : fTextureAccess(texture, params) |
64 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", | 64 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", |
65 kVec2f_GrSLType, | 65 kVec2f_GrSLType, |
66 GrShaderVar::kAttribute
_TypeModifier))) { | 66 GrShaderVar::kAttribute
_TypeModifier))) { |
67 this->addTextureAccess(&fTextureAccess); | 67 this->addTextureAccess(&fTextureAccess); |
68 } | 68 } |
69 | 69 |
70 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const { | 70 bool GrCustomCoordsTextureEffect::onIsEqual(const GrProcessor& other) const { |
71 const GrCustomCoordsTextureEffect& cte = other.cast<GrCustomCoordsTextureEff
ect>(); | 71 const GrCustomCoordsTextureEffect& cte = other.cast<GrCustomCoordsTextureEff
ect>(); |
72 return fTextureAccess == cte.fTextureAccess; | 72 return fTextureAccess == cte.fTextureAccess; |
73 } | 73 } |
74 | 74 |
75 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color, | 75 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color, |
76 uint32_t* validFlag
s) const { | 76 uint32_t* validFlag
s) const { |
77 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && | 77 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
78 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 78 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
79 *validFlags = kA_GrColorComponentFlag; | 79 *validFlags = kA_GrColorComponentFlag; |
80 } else { | 80 } else { |
81 *validFlags = 0; | 81 *validFlags = 0; |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 const GrBackendEffectFactory& GrCustomCoordsTextureEffect::getFactory() const { | 85 const GrBackendGeometryProcessorFactory& GrCustomCoordsTextureEffect::getFactory
() const { |
86 return GrTBackendEffectFactory<GrCustomCoordsTextureEffect>::getInstance(); | 86 return GrTBackendGeometryProcessorFactory<GrCustomCoordsTextureEffect>::getI
nstance(); |
87 } | 87 } |
88 | 88 |
89 /////////////////////////////////////////////////////////////////////////////// | 89 /////////////////////////////////////////////////////////////////////////////// |
90 | 90 |
91 GR_DEFINE_EFFECT_TEST(GrCustomCoordsTextureEffect); | 91 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCustomCoordsTextureEffect); |
92 | 92 |
93 GrEffect* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, | 93 GrGeometryProcessor* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, |
94 GrContext*, | 94 GrContext*, |
95 const GrDrawTargetCaps&, | 95 const GrDrawTargetC
aps&, |
96 GrTexture* textures[]) { | 96 GrTexture* textures
[]) { |
97 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 97 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
98 GrEffectUnitTest::kAlphaTextureIdx; | 98 GrProcessorUnitTest::kAlphaTextureIdx; |
99 static const SkShader::TileMode kTileModes[] = { | 99 static const SkShader::TileMode kTileModes[] = { |
100 SkShader::kClamp_TileMode, | 100 SkShader::kClamp_TileMode, |
101 SkShader::kRepeat_TileMode, | 101 SkShader::kRepeat_TileMode, |
102 SkShader::kMirror_TileMode, | 102 SkShader::kMirror_TileMode, |
103 }; | 103 }; |
104 SkShader::TileMode tileModes[] = { | 104 SkShader::TileMode tileModes[] = { |
105 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 105 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
106 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 106 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
107 }; | 107 }; |
108 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 108 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
109 GrTextureParams::kNon
e_FilterMode); | 109 GrTextureParams::kNon
e_FilterMode); |
110 | 110 |
111 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 111 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); |
112 } | 112 } |
OLD | NEW |