Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2012 Google Inc. | |
|
bsalomon
2013/09/23 14:13:48
2013
| |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "GrCustomCoordsTextureEffect.h" | |
| 9 #include "gl/GrGLEffect.h" | |
| 10 #include "gl/GrGLEffectMatrix.h" | |
| 11 #include "gl/GrGLSL.h" | |
| 12 #include "gl/GrGLTexture.h" | |
| 13 #include "GrTBackendEffectFactory.h" | |
| 14 #include "GrTexture.h" | |
| 15 | |
| 16 class GrGLCustomCoordsTextureEffect : public GrGLEffect { | |
| 17 public: | |
| 18 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G rDrawEffect& drawEffect) | |
| 19 : INHERITED (factory) {} | |
| 20 | |
| 21 virtual void emitCode(GrGLShaderBuilder* builder, | |
| 22 const GrDrawEffect& drawEffect, | |
| 23 EffectKey key, | |
| 24 const char* outputColor, | |
| 25 const char* inputColor, | |
| 26 const TextureSamplerArray& samplers) SK_OVERRIDE { | |
| 27 const GrCustomCoordsTextureEffect& cte = drawEffect.castEffect<GrCustomC oordsTextureEffect>(); | |
| 28 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuil der(); | |
| 29 SkASSERT(NULL != vertexBuilder); | |
| 30 SkASSERT(1 == cte.numVertexAttribs()); | |
| 31 | |
| 32 SkString fsCoordName; | |
| 33 const char* vsVaryingName; | |
| 34 const char* fsVaryingNamePtr; | |
| 35 vertexBuilder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingNa me, &fsVaryingNamePtr); | |
| 36 fsCoordName = fsVaryingNamePtr; | |
| 37 | |
| 38 const char* attrName = | |
| 39 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndi ces()[0])->c_str(); | |
| 40 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName); | |
| 41 | |
| 42 builder->fsCodeAppendf("\t%s = ", outputColor); | |
| 43 builder->fsAppendTextureLookupAndModulate(inputColor, | |
| 44 samplers[0], | |
| 45 fsCoordName.c_str(), | |
| 46 kVec2f_GrSLType); | |
| 47 builder->fsCodeAppend(";\n"); | |
| 48 } | |
| 49 | |
| 50 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&) { | |
| 51 return 1 << GrGLEffectMatrix::kKeyBits; | |
| 52 } | |
| 53 | |
| 54 virtual void setData(const GrGLUniformManager& uman, | |
| 55 const GrDrawEffect& drawEffect) SK_OVERRIDE {} | |
| 56 | |
| 57 private: | |
| 58 typedef GrGLEffect INHERITED; | |
| 59 }; | |
| 60 | |
| 61 /////////////////////////////////////////////////////////////////////////////// | |
| 62 | |
| 63 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, | |
| 64 const GrTextureParams& params) | |
| 65 : fTextureAccess(texture, params) { | |
| 66 this->addTextureAccess(&fTextureAccess); | |
| 67 this->addVertexAttrib(kVec2f_GrSLType); | |
| 68 } | |
| 69 | |
| 70 bool GrCustomCoordsTextureEffect::onIsEqual(const GrEffect& other) const { | |
| 71 const GrCustomCoordsTextureEffect& cte = CastEffect<GrCustomCoordsTextureEff ect>(other); | |
| 72 return fTextureAccess == cte.fTextureAccess; | |
| 73 } | |
| 74 | |
| 75 void GrCustomCoordsTextureEffect::getConstantColorComponents(GrColor* color, | |
| 76 uint32_t* validFlag s) const { | |
| 77 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color ) && | |
| 78 GrPixelConfigIsOpaque(this->texture(0)->config())) { | |
| 79 *validFlags = kA_GrColorComponentFlag; | |
| 80 } else { | |
| 81 *validFlags = 0; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 const GrBackendEffectFactory& GrCustomCoordsTextureEffect::getFactory() const { | |
| 86 return GrTBackendEffectFactory<GrCustomCoordsTextureEffect>::getInstance(); | |
| 87 } | |
| 88 | |
| 89 /////////////////////////////////////////////////////////////////////////////// | |
| 90 | |
| 91 GR_DEFINE_EFFECT_TEST(GrCustomCoordsTextureEffect); | |
| 92 | |
| 93 GrEffectRef* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, | |
| 94 GrContext*, | |
|
bsalomon
2013/09/23 14:13:48
can you align the wrapped params with "SkRandom ra
| |
| 95 const GrDrawTargetCaps&, | |
| 96 GrTexture* textures[]) { | |
| 97 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | |
| 98 GrEffectUnitTest::kAlphaTextureIdx; | |
| 99 static const SkShader::TileMode kTileModes[] = { | |
| 100 SkShader::kClamp_TileMode, | |
| 101 SkShader::kRepeat_TileMode, | |
| 102 SkShader::kMirror_TileMode, | |
| 103 }; | |
| 104 SkShader::TileMode tileModes[] = { | |
| 105 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | |
| 106 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | |
| 107 }; | |
| 108 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil erp_FilterMode : | |
| 109 GrTextureParams::kNon e_FilterMode); | |
| 110 | |
| 111 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | |
| 112 } | |
| OLD | NEW |