| 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 "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "GrTexture.h" |
| 11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
| 12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
| 13 #include "gl/GrGLTexture.h" | 13 #include "gl/GrGLTexture.h" |
| 14 #include "gl/GrGLGeometryProcessor.h" | 14 #include "gl/GrGLGeometryProcessor.h" |
| 15 #include "GrTBackendProcessorFactory.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
| 16 #include "GrTexture.h" | |
| 17 | 16 |
| 18 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { | 17 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { |
| 19 public: | 18 public: |
| 20 GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, | 19 GrGLCustomCoordsTextureEffect(const GrGeometryProcessor&, |
| 21 const GrGeometryProcessor&, | 20 const GrBatchTracker&) {} |
| 22 const GrBatchTracker&) | |
| 23 : INHERITED (factory) {} | |
| 24 | 21 |
| 25 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 22 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 26 const GrCustomCoordsTextureEffect& cte = | 23 const GrCustomCoordsTextureEffect& cte = |
| 27 args.fGP.cast<GrCustomCoordsTextureEffect>(); | 24 args.fGP.cast<GrCustomCoordsTextureEffect>(); |
| 28 | 25 |
| 29 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 26 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 30 | 27 |
| 31 GrGLVertToFrag v(kVec2f_GrSLType); | 28 GrGLVertToFrag v(kVec2f_GrSLType); |
| 32 args.fPB->addVarying("TextureCoords", &v); | 29 args.fPB->addVarying("TextureCoords", &v); |
| 33 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); | 30 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 private: | 64 private: |
| 68 typedef GrGLGeometryProcessor INHERITED; | 65 typedef GrGLGeometryProcessor INHERITED; |
| 69 }; | 66 }; |
| 70 | 67 |
| 71 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 72 | 69 |
| 73 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, | 70 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, |
| 74 const GrTextureParams&
params, | 71 const GrTextureParams&
params, |
| 75 bool hasColor) | 72 bool hasColor) |
| 76 : fTextureAccess(texture, params), fInColor(NULL) { | 73 : fTextureAccess(texture, params), fInColor(NULL) { |
| 74 this->initClassID<GrCustomCoordsTextureEffect>(); |
| 77 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); | 75 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 78 if (hasColor) { | 76 if (hasColor) { |
| 79 fInColor = &this->addVertexAttrib(GrAttribute("inColor", kVec4ub_GrVerte
xAttribType)); | 77 fInColor = &this->addVertexAttrib(GrAttribute("inColor", kVec4ub_GrVerte
xAttribType)); |
| 80 this->setHasVertexColor(); | 78 this->setHasVertexColor(); |
| 81 } | 79 } |
| 82 fInTextureCoords = &this->addVertexAttrib(GrAttribute("inTextureCoords", | 80 fInTextureCoords = &this->addVertexAttrib(GrAttribute("inTextureCoords", |
| 83 kVec2f_GrVertexAttribT
ype)); | 81 kVec2f_GrVertexAttribT
ype)); |
| 84 this->addTextureAccess(&fTextureAccess); | 82 this->addTextureAccess(&fTextureAccess); |
| 85 } | 83 } |
| 86 | 84 |
| 87 bool GrCustomCoordsTextureEffect::onIsEqual(const GrGeometryProcessor& other) co
nst { | 85 bool GrCustomCoordsTextureEffect::onIsEqual(const GrGeometryProcessor& other) co
nst { |
| 88 const GrCustomCoordsTextureEffect& gp = other.cast<GrCustomCoordsTextureEffe
ct>(); | 86 const GrCustomCoordsTextureEffect& gp = other.cast<GrCustomCoordsTextureEffe
ct>(); |
| 89 return SkToBool(this->inColor()) == SkToBool(gp.inColor()); | 87 return SkToBool(this->inColor()) == SkToBool(gp.inColor()); |
| 90 } | 88 } |
| 91 | 89 |
| 92 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in
out) const { | 90 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in
out) const { |
| 93 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { | 91 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
| 94 inout->mulByUnknownAlpha(); | 92 inout->mulByUnknownAlpha(); |
| 95 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { | 93 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 96 inout->mulByUnknownOpaqueColor(); | 94 inout->mulByUnknownOpaqueColor(); |
| 97 } else { | 95 } else { |
| 98 inout->mulByUnknownColor(); | 96 inout->mulByUnknownColor(); |
| 99 } | 97 } |
| 100 } | 98 } |
| 101 | 99 |
| 102 const GrBackendGeometryProcessorFactory& GrCustomCoordsTextureEffect::getFactory
() const { | 100 void GrCustomCoordsTextureEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 103 return GrTBackendGeometryProcessorFactory<GrCustomCoordsTextureEffect>::getI
nstance(); | 101 const GrGLCaps& caps, |
| 102 GrProcessorKeyBuilder* b) co
nst { |
| 103 GrGLCustomCoordsTextureEffect::GenKey(*this, bt, caps, b); |
| 104 } | 104 } |
| 105 | 105 |
| 106 GrGLGeometryProcessor* |
| 107 GrCustomCoordsTextureEffect::createGLInstance(const GrBatchTracker& bt) const { |
| 108 return SkNEW_ARGS(GrGLCustomCoordsTextureEffect, (*this, bt)); |
| 109 } |
| 106 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
| 107 | 111 |
| 108 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCustomCoordsTextureEffect); | 112 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCustomCoordsTextureEffect); |
| 109 | 113 |
| 110 GrGeometryProcessor* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, | 114 GrGeometryProcessor* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, |
| 111 GrContext*, | 115 GrContext*, |
| 112 const GrDrawTargetC
aps&, | 116 const GrDrawTargetC
aps&, |
| 113 GrTexture* textures
[]) { | 117 GrTexture* textures
[]) { |
| 114 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 118 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 115 GrProcessorUnitTest::kAlphaTextureIdx; | 119 GrProcessorUnitTest::kAlphaTextureIdx; |
| 116 static const SkShader::TileMode kTileModes[] = { | 120 static const SkShader::TileMode kTileModes[] = { |
| 117 SkShader::kClamp_TileMode, | 121 SkShader::kClamp_TileMode, |
| 118 SkShader::kRepeat_TileMode, | 122 SkShader::kRepeat_TileMode, |
| 119 SkShader::kMirror_TileMode, | 123 SkShader::kMirror_TileMode, |
| 120 }; | 124 }; |
| 121 SkShader::TileMode tileModes[] = { | 125 SkShader::TileMode tileModes[] = { |
| 122 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 126 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 123 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 127 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 124 }; | 128 }; |
| 125 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 129 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 126 GrTextureParams::kNon
e_FilterMode); | 130 GrTextureParams::kNon
e_FilterMode); |
| 127 | 131 |
| 128 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params, random-
>nextBool()); | 132 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params, random-
>nextBool()); |
| 129 } | 133 } |
| OLD | NEW |