| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in
out) const { | 89 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in
out) const { |
| 93 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { | 90 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
| 94 inout->mulByUnknownAlpha(); | 91 inout->mulByUnknownAlpha(); |
| 95 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { | 92 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 96 inout->mulByUnknownOpaqueColor(); | 93 inout->mulByUnknownOpaqueColor(); |
| 97 } else { | 94 } else { |
| 98 inout->mulByUnknownColor(); | 95 inout->mulByUnknownColor(); |
| 99 } | 96 } |
| 100 } | 97 } |
| 101 | 98 |
| 102 const GrBackendGeometryProcessorFactory& GrCustomCoordsTextureEffect::getFactory
() const { | 99 void GrCustomCoordsTextureEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 103 return GrTBackendGeometryProcessorFactory<GrCustomCoordsTextureEffect>::getI
nstance(); | 100 const GrGLCaps& caps, |
| 101 GrProcessorKeyBuilder* b) co
nst { |
| 102 GrGLCustomCoordsTextureEffect::GenKey(*this, bt, caps, b); |
| 104 } | 103 } |
| 105 | 104 |
| 105 GrGLGeometryProcessor* |
| 106 GrCustomCoordsTextureEffect::createGLInstance(const GrBatchTracker& bt) const { |
| 107 return SkNEW_ARGS(GrGLCustomCoordsTextureEffect, (*this, bt)); |
| 108 } |
| 106 /////////////////////////////////////////////////////////////////////////////// | 109 /////////////////////////////////////////////////////////////////////////////// |
| 107 | 110 |
| 108 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCustomCoordsTextureEffect); | 111 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCustomCoordsTextureEffect); |
| 109 | 112 |
| 110 GrGeometryProcessor* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, | 113 GrGeometryProcessor* GrCustomCoordsTextureEffect::TestCreate(SkRandom* random, |
| 111 GrContext*, | 114 GrContext*, |
| 112 const GrDrawTargetC
aps&, | 115 const GrDrawTargetC
aps&, |
| 113 GrTexture* textures
[]) { | 116 GrTexture* textures
[]) { |
| 114 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 117 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 115 GrProcessorUnitTest::kAlphaTextureIdx; | 118 GrProcessorUnitTest::kAlphaTextureIdx; |
| 116 static const SkShader::TileMode kTileModes[] = { | 119 static const SkShader::TileMode kTileModes[] = { |
| 117 SkShader::kClamp_TileMode, | 120 SkShader::kClamp_TileMode, |
| 118 SkShader::kRepeat_TileMode, | 121 SkShader::kRepeat_TileMode, |
| 119 SkShader::kMirror_TileMode, | 122 SkShader::kMirror_TileMode, |
| 120 }; | 123 }; |
| 121 SkShader::TileMode tileModes[] = { | 124 SkShader::TileMode tileModes[] = { |
| 122 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 125 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 123 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 126 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 124 }; | 127 }; |
| 125 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 128 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 126 GrTextureParams::kNon
e_FilterMode); | 129 GrTextureParams::kNon
e_FilterMode); |
| 127 | 130 |
| 128 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params, random-
>nextBool()); | 131 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params, random-
>nextBool()); |
| 129 } | 132 } |
| OLD | NEW |