| 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 "GrBitmapTextGeoProc.h" | 8 #include "GrBitmapTextGeoProc.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "GrTexture.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 "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
| 16 | 16 |
| 17 struct BitmapTextBatchTracker { |
| 18 GrGPInput fInputColorType; |
| 19 GrColor fColor; |
| 20 }; |
| 21 |
| 17 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { | 22 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { |
| 18 public: | 23 public: |
| 19 GrGLBitmapTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&) {} | 24 GrGLBitmapTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&) |
| 25 : fColor(GrColor_ILLEGAL) {} |
| 20 | 26 |
| 21 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 27 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 22 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); | 28 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); |
| 29 const BitmapTextBatchTracker& local = args.fBT.cast<BitmapTextBatchTrack
er>(); |
| 23 | 30 |
| 24 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 31 GrGLGPBuilder* pb = args.fPB; |
| 32 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
| 25 | 33 |
| 26 GrGLVertToFrag v(kVec2f_GrSLType); | 34 GrGLVertToFrag v(kVec2f_GrSLType); |
| 27 args.fPB->addVarying("TextureCoords", &v); | 35 pb->addVarying("TextureCoords", &v); |
| 28 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); | 36 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); |
| 29 | 37 |
| 30 if (cte.inColor()) { | 38 // Setup pass through color |
| 31 args.fPB->addPassThroughAttribute(cte.inColor(), args.fOutputColor); | 39 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, cte.inColor(), |
| 32 } | 40 &fColorUniform); |
| 33 | 41 |
| 34 // setup output coords | 42 // setup output coords |
| 35 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), cte.inPo
sition()->fName); | 43 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), cte.inPo
sition()->fName); |
| 36 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), cte.inPosit
ion()->fName); | 44 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), cte.inPosit
ion()->fName); |
| 37 | 45 |
| 38 // setup position varying | 46 // setup position varying |
| 39 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition()
, | 47 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition()
, |
| 40 vsBuilder->uViewM(), cte.inPosition()->fName); | 48 vsBuilder->uViewM(), cte.inPosition()->fName); |
| 41 | 49 |
| 42 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 50 GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 43 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); | 51 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |
| 44 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT
ype); | 52 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT
ype); |
| 45 fsBuilder->codeAppend(";"); | 53 fsBuilder->codeAppend(";"); |
| 46 } | 54 } |
| 47 | 55 |
| 48 virtual void setData(const GrGLProgramDataManager&, | 56 virtual void setData(const GrGLProgramDataManager& pdman, |
| 49 const GrGeometryProcessor&, | 57 const GrPrimitiveProcessor& gp, |
| 50 const GrBatchTracker&) SK_OVERRIDE {} | 58 const GrBatchTracker& bt) SK_OVERRIDE { |
| 59 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); |
| 60 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 61 GrGLfloat c[4]; |
| 62 GrColorToRGBAFloat(local.fColor, c); |
| 63 pdman.set4fv(fColorUniform, 1, c); |
| 64 fColor = local.fColor; |
| 65 } |
| 66 } |
| 51 | 67 |
| 52 static inline void GenKey(const GrGeometryProcessor& proc, | 68 static inline void GenKey(const GrGeometryProcessor& proc, |
| 53 const GrBatchTracker&, | 69 const GrBatchTracker& bt, |
| 54 const GrGLCaps&, | 70 const GrGLCaps&, |
| 55 GrProcessorKeyBuilder* b) { | 71 GrProcessorKeyBuilder* b) { |
| 72 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); |
| 73 // We have to put the optional vertex attribute as part of the key. See
the comment |
| 74 // on addVertexAttrib. |
| 75 // TODO When we have deferred geometry we can fix this |
| 56 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); | 76 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); |
| 57 | |
| 58 b->add32(SkToBool(gp.inColor())); | 77 b->add32(SkToBool(gp.inColor())); |
| 78 b->add32(local.fInputColorType); |
| 59 } | 79 } |
| 60 | 80 |
| 81 private: |
| 82 GrColor fColor; |
| 83 UniformHandle fColorUniform; |
| 61 | 84 |
| 62 private: | |
| 63 typedef GrGLGeometryProcessor INHERITED; | 85 typedef GrGLGeometryProcessor INHERITED; |
| 64 }; | 86 }; |
| 65 | 87 |
| 66 /////////////////////////////////////////////////////////////////////////////// | 88 /////////////////////////////////////////////////////////////////////////////// |
| 67 | 89 |
| 68 GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture, | 90 GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture, |
| 69 const GrTextureParams& params, bool use
ColorAttrib, | 91 const GrTextureParams& params, bool use
ColorAttrib, |
| 70 bool opaqueVertexColors) | 92 bool opaqueVertexColors) |
| 71 : INHERITED(color, opaqueVertexColors), fTextureAccess(texture, params), fIn
Color(NULL) { | 93 : INHERITED(color, opaqueVertexColors), fTextureAccess(texture, params), fIn
Color(NULL) { |
| 72 this->initClassID<GrBitmapTextGeoProc>(); | 94 this->initClassID<GrBitmapTextGeoProc>(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 100 void GrBitmapTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 122 void GrBitmapTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
| 101 const GrGLCaps& caps, | 123 const GrGLCaps& caps, |
| 102 GrProcessorKeyBuilder* b) const { | 124 GrProcessorKeyBuilder* b) const { |
| 103 GrGLBitmapTextGeoProc::GenKey(*this, bt, caps, b); | 125 GrGLBitmapTextGeoProc::GenKey(*this, bt, caps, b); |
| 104 } | 126 } |
| 105 | 127 |
| 106 GrGLGeometryProcessor* | 128 GrGLGeometryProcessor* |
| 107 GrBitmapTextGeoProc::createGLInstance(const GrBatchTracker& bt) const { | 129 GrBitmapTextGeoProc::createGLInstance(const GrBatchTracker& bt) const { |
| 108 return SkNEW_ARGS(GrGLBitmapTextGeoProc, (*this, bt)); | 130 return SkNEW_ARGS(GrGLBitmapTextGeoProc, (*this, bt)); |
| 109 } | 131 } |
| 132 |
| 133 void GrBitmapTextGeoProc::initBatchTracker(GrBatchTracker* bt, const InitBT& ini
t) const { |
| 134 BitmapTextBatchTracker* local = bt->cast<BitmapTextBatchTracker>(); |
| 135 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in
it, |
| 136 SkToBool(fInColor)); |
| 137 } |
| 138 |
| 139 bool GrBitmapTextGeoProc::onCanMakeEqual(const GrBatchTracker& m, const GrBatchT
racker& t) const { |
| 140 const BitmapTextBatchTracker& mine = m.cast<BitmapTextBatchTracker>(); |
| 141 const BitmapTextBatchTracker& theirs = t.cast<BitmapTextBatchTracker>(); |
| 142 return CanCombineOutput(mine.fInputColorType, mine.fColor, |
| 143 theirs.fInputColorType, theirs.fColor); |
| 144 } |
| 145 |
| 110 /////////////////////////////////////////////////////////////////////////////// | 146 /////////////////////////////////////////////////////////////////////////////// |
| 111 | 147 |
| 112 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrBitmapTextGeoProc); | 148 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrBitmapTextGeoProc); |
| 113 | 149 |
| 114 GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(SkRandom* random, | 150 GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(SkRandom* random, |
| 115 GrContext*, | 151 GrContext*, |
| 116 const GrDrawTargetCaps&, | 152 const GrDrawTargetCaps&, |
| 117 GrTexture* textures[]) { | 153 GrTexture* textures[]) { |
| 118 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : | 154 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 119 GrProcessorUnitTest::kAlphaTextureIdx; | 155 GrProcessorUnitTest::kAlphaTextureIdx; |
| 120 static const SkShader::TileMode kTileModes[] = { | 156 static const SkShader::TileMode kTileModes[] = { |
| 121 SkShader::kClamp_TileMode, | 157 SkShader::kClamp_TileMode, |
| 122 SkShader::kRepeat_TileMode, | 158 SkShader::kRepeat_TileMode, |
| 123 SkShader::kMirror_TileMode, | 159 SkShader::kMirror_TileMode, |
| 124 }; | 160 }; |
| 125 SkShader::TileMode tileModes[] = { | 161 SkShader::TileMode tileModes[] = { |
| 126 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 162 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 127 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 163 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 128 }; | 164 }; |
| 129 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 165 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 130 GrTextureParams::kNon
e_FilterMode); | 166 GrTextureParams::kNon
e_FilterMode); |
| 131 | 167 |
| 132 return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx],
params, | 168 return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx],
params, |
| 133 random->nextBool(), random->nextBool()); | 169 random->nextBool(), random->nextBool()); |
| 134 } | 170 } |
| OLD | NEW |