| 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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrCustomCoordsTextureEffect.h" | 9 #include "GrCustomCoordsTextureEffect.h" |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
| 13 #include "gl/GrGLVertexEffect.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
| 14 #include "GrTBackendEffectFactory.h" | 14 #include "GrTBackendEffectFactory.h" |
| 15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 | 16 |
| 17 class GrGLCustomCoordsTextureEffect : public GrGLVertexEffect { | 17 const GrShaderVar kAttrTextureCoords("aTextureCoords", |
| 18 kVec2f_GrSLType, |
| 19 GrShaderVar::kAttribute_TypeModifier); |
| 20 |
| 21 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { |
| 18 public: | 22 public: |
| 19 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rDrawEffect& drawEffect) | 23 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rDrawEffect& drawEffect) |
| 20 : INHERITED (factory) {} | 24 : INHERITED (factory) {} |
| 21 | 25 |
| 22 virtual void emitCode(GrGLFullProgramBuilder* builder, | 26 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 23 const GrDrawEffect& drawEffect, | 27 const GrDrawEffect& drawEffect, |
| 24 const GrEffectKey& key, | 28 const GrEffectKey& key, |
| 25 const char* outputColor, | 29 const char* outputColor, |
| 26 const char* inputColor, | 30 const char* inputColor, |
| 27 const TransformedCoordsArray&, | 31 const TransformedCoordsArray&, |
| 28 const TextureSamplerArray& samplers) SK_OVERRIDE { | 32 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 29 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVe
rtexAttribs()); | 33 SkASSERT(1 == |
| 34 drawEffect.castEffect<GrCustomCoordsTextureEffect>().getVertexAt
tribs().count()); |
| 30 | 35 |
| 31 SkString fsCoordName; | 36 SkString fsCoordName; |
| 32 const char* vsVaryingName; | 37 const char* vsVaryingName; |
| 33 const char* fsVaryingNamePtr; | 38 const char* fsVaryingNamePtr; |
| 34 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &f
sVaryingNamePtr); | 39 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &f
sVaryingNamePtr); |
| 35 fsCoordName = fsVaryingNamePtr; | 40 fsCoordName = fsVaryingNamePtr; |
| 36 | 41 |
| 37 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 42 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 38 const SkString* attr0Name = | 43 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, kAttrTextureCoords
.c_str()); |
| 39 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices(
)[0]); | |
| 40 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, attr0Name->c_str()
); | |
| 41 | 44 |
| 42 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 45 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); |
| 43 fsBuilder->codeAppendf("\t%s = ", outputColor); | 46 fsBuilder->codeAppendf("\t%s = ", outputColor); |
| 44 fsBuilder->appendTextureLookupAndModulate(inputColor, | 47 fsBuilder->appendTextureLookupAndModulate(inputColor, |
| 45 samplers[0], | 48 samplers[0], |
| 46 fsCoordName.c_str(), | 49 fsCoordName.c_str(), |
| 47 kVec2f_GrSLType); | 50 kVec2f_GrSLType); |
| 48 fsBuilder->codeAppend(";\n"); | 51 fsBuilder->codeAppend(";\n"); |
| 49 } | 52 } |
| 50 | 53 |
| 51 virtual void setData(const GrGLProgramDataManager& pdman, | 54 virtual void setData(const GrGLProgramDataManager& pdman, |
| 52 const GrDrawEffect& drawEffect) SK_OVERRIDE {} | 55 const GrDrawEffect& drawEffect) SK_OVERRIDE {} |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 typedef GrGLVertexEffect INHERITED; | 58 typedef GrGLGeometryProcessor INHERITED; |
| 56 }; | 59 }; |
| 57 | 60 |
| 58 /////////////////////////////////////////////////////////////////////////////// | 61 /////////////////////////////////////////////////////////////////////////////// |
| 59 | 62 |
| 60 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, | 63 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, |
| 61 const GrTextureParams&
params) | 64 const GrTextureParams&
params) |
| 62 : fTextureAccess(texture, params) { | 65 : fTextureAccess(texture, params) { |
| 63 this->addTextureAccess(&fTextureAccess); | 66 this->addTextureAccess(&fTextureAccess); |
| 64 this->addVertexAttrib(kVec2f_GrSLType); | 67 this->addVertexAttrib(kAttrTextureCoords); |
| 65 } | 68 } |
| 66 | 69 |
| 67 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const { | 70 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const { |
| 68 const GrCustomCoordsTextureEffect& cte = CastEffect<GrCustomCoordsTextureEff
ect>(other); | 71 const GrCustomCoordsTextureEffect& cte = CastEffect<GrCustomCoordsTextureEff
ect>(other); |
| 69 return fTextureAccess == cte.fTextureAccess; | 72 return fTextureAccess == cte.fTextureAccess; |
| 70 } | 73 } |
| 71 | 74 |
| 72 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color, | 75 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color, |
| 73 uint32_t* validFlag
s) const { | 76 uint32_t* validFlag
s) const { |
| 74 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && | 77 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
| (...skipping 25 matching lines...) Expand all Loading... |
| 100 }; | 103 }; |
| 101 SkShader::TileMode tileModes[] = { | 104 SkShader::TileMode tileModes[] = { |
| 102 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 105 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 103 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 106 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 104 }; | 107 }; |
| 105 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 108 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 106 GrTextureParams::kNon
e_FilterMode); | 109 GrTextureParams::kNon
e_FilterMode); |
| 107 | 110 |
| 108 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 111 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); |
| 109 } | 112 } |
| OLD | NEW |