| 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" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); | 40 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); |
| 41 | 41 |
| 42 // Setup pass through color | 42 // Setup pass through color |
| 43 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, cte.inColor(), | 43 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, cte.inColor(), |
| 44 &fColorUniform); | 44 &fColorUniform); |
| 45 | 45 |
| 46 // setup uniform viewMatrix | 46 // setup uniform viewMatrix |
| 47 this->addUniformViewMatrix(pb); | 47 this->addUniformViewMatrix(pb); |
| 48 | 48 |
| 49 // Setup position | 49 // Setup position |
| 50 SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName, | 50 SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName, cte.viewMatrix
(), this->uViewM()); |
| 51 cte.viewMatrix(), this->uViewM()); | |
| 52 | 51 |
| 53 // emit transforms | 52 // emit transforms |
| 54 this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->f
Name, | 53 this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->f
Name, |
| 55 cte.localMatrix(), args.fTransformsIn, args.fTransf
ormsOut); | 54 cte.localMatrix(), args.fTransformsIn, args.fTransf
ormsOut); |
| 56 | 55 |
| 57 GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 56 GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 58 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); | 57 if (cte.maskFormat() == kARGB_GrMaskFormat) { |
| 59 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT
ype); | 58 fsBuilder->codeAppendf("%s = ", args.fOutputColor); |
| 60 fsBuilder->codeAppend(";"); | 59 fsBuilder->appendTextureLookupAndModulate(args.fOutputColor, |
| 60 args.fSamplers[0], |
| 61 v.fsIn(), |
| 62 kVec2f_GrSLType); |
| 63 fsBuilder->codeAppend(";"); |
| 64 fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
| 65 } else { |
| 66 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |
| 67 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_G
rSLType); |
| 68 fsBuilder->codeAppend(";"); |
| 69 } |
| 61 } | 70 } |
| 62 | 71 |
| 63 virtual void setData(const GrGLProgramDataManager& pdman, | 72 virtual void setData(const GrGLProgramDataManager& pdman, |
| 64 const GrPrimitiveProcessor& gp, | 73 const GrPrimitiveProcessor& gp, |
| 65 const GrBatchTracker& bt) SK_OVERRIDE { | 74 const GrBatchTracker& bt) SK_OVERRIDE { |
| 66 this->setUniformViewMatrix(pdman, gp.viewMatrix()); | 75 this->setUniformViewMatrix(pdman, gp.viewMatrix()); |
| 67 | 76 |
| 68 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); | 77 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); |
| 69 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { | 78 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColo
r) { |
| 70 GrGLfloat c[4]; | 79 GrGLfloat c[4]; |
| 71 GrColorToRGBAFloat(local.fColor, c); | 80 GrColorToRGBAFloat(local.fColor, c); |
| 72 pdman.set4fv(fColorUniform, 1, c); | 81 pdman.set4fv(fColorUniform, 1, c); |
| 73 fColor = local.fColor; | 82 fColor = local.fColor; |
| 74 } | 83 } |
| 75 } | 84 } |
| 76 | 85 |
| 77 static inline void GenKey(const GrGeometryProcessor& proc, | 86 static inline void GenKey(const GrGeometryProcessor& proc, |
| 78 const GrBatchTracker& bt, | 87 const GrBatchTracker& bt, |
| 79 const GrGLCaps&, | 88 const GrGLCaps&, |
| 80 GrProcessorKeyBuilder* b) { | 89 GrProcessorKeyBuilder* b) { |
| 81 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); | 90 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); |
| 82 // We have to put the optional vertex attribute as part of the key. See
the comment | 91 // We have to put the optional vertex attribute as part of the key. See
the comment |
| 83 // on addVertexAttrib. | 92 // on addVertexAttrib. |
| 84 // TODO When we have deferred geometry we can fix this | 93 // TODO When we have deferred geometry we can fix this |
| 85 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); | 94 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); |
| 86 uint32_t key = 0; | 95 uint32_t key = 0; |
| 87 key |= SkToBool(gp.inColor()) ? 0x1 : 0x0; | 96 key |= SkToBool(gp.inColor()) ? 0x1 : 0x0; |
| 88 key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0
x2 : 0x0; | 97 key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0
x2 : 0x0; |
| 89 key |= ComputePosKey(gp.viewMatrix()) << 2; | 98 key |= gp.maskFormat() == kARGB_GrMaskFormat ? 0x4 : 0x0; |
| 99 key |= ComputePosKey(gp.viewMatrix()) << 3; |
| 90 b->add32(local.fInputColorType << 16 | key); | 100 b->add32(local.fInputColorType << 16 | key); |
| 91 } | 101 } |
| 92 | 102 |
| 93 private: | 103 private: |
| 94 GrColor fColor; | 104 GrColor fColor; |
| 95 UniformHandle fColorUniform; | 105 UniformHandle fColorUniform; |
| 96 | 106 |
| 97 typedef GrGLGeometryProcessor INHERITED; | 107 typedef GrGLGeometryProcessor INHERITED; |
| 98 }; | 108 }; |
| 99 | 109 |
| 100 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
| 101 | 111 |
| 102 GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture, | 112 GrBitmapTextGeoProc::GrBitmapTextGeoProc(GrColor color, GrTexture* texture, |
| 103 const GrTextureParams& params, bool use
ColorAttrib, | 113 const GrTextureParams& params, GrMaskFo
rmat format, |
| 104 bool opaqueVertexColors, const SkMatrix
& localMatrix) | 114 bool opaqueVertexColors, const SkMatrix
& localMatrix) |
| 105 : INHERITED(color, SkMatrix::I(), localMatrix, opaqueVertexColors) | 115 : INHERITED(color, SkMatrix::I(), localMatrix, opaqueVertexColors) |
| 106 , fTextureAccess(texture, params) | 116 , fTextureAccess(texture, params) |
| 107 , fInColor(NULL) { | 117 , fInColor(NULL) |
| 118 , fMaskFormat(format) { |
| 108 this->initClassID<GrBitmapTextGeoProc>(); | 119 this->initClassID<GrBitmapTextGeoProc>(); |
| 109 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); | 120 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType)); |
| 110 if (useColorAttrib) { | 121 |
| 122 bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat; |
| 123 if (hasVertexColor) { |
| 111 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 124 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
| 112 this->setHasVertexColor(); | 125 this->setHasVertexColor(); |
| 113 } | 126 } |
| 114 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 127 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 115 kVec2f_GrVertexAttribT
ype)); | 128 kVec2f_GrVertexAttribTyp
e)); |
| 116 this->addTextureAccess(&fTextureAccess); | 129 this->addTextureAccess(&fTextureAccess); |
| 117 } | 130 } |
| 118 | 131 |
| 119 bool GrBitmapTextGeoProc::onIsEqual(const GrGeometryProcessor& other) const { | 132 bool GrBitmapTextGeoProc::onIsEqual(const GrGeometryProcessor& other) const { |
| 120 const GrBitmapTextGeoProc& gp = other.cast<GrBitmapTextGeoProc>(); | 133 const GrBitmapTextGeoProc& gp = other.cast<GrBitmapTextGeoProc>(); |
| 121 return SkToBool(this->inColor()) == SkToBool(gp.inColor()); | 134 return SkToBool(this->inColor()) == SkToBool(gp.inColor()); |
| 122 } | 135 } |
| 123 | 136 |
| 124 void GrBitmapTextGeoProc::onGetInvariantOutputCoverage(GrInitInvariantOutput* ou
t) const { | 137 void GrBitmapTextGeoProc::onGetInvariantOutputColor(GrInitInvariantOutput* out)
const { |
| 125 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { | 138 if (kARGB_GrMaskFormat == fMaskFormat) { |
| 126 out->setUnknownSingleComponent(); | |
| 127 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { | |
| 128 out->setUnknownOpaqueFourComponents(); | |
| 129 out->setUsingLCDCoverage(); | |
| 130 } else { | |
| 131 out->setUnknownFourComponents(); | 139 out->setUnknownFourComponents(); |
| 132 out->setUsingLCDCoverage(); | |
| 133 } | 140 } |
| 134 } | 141 } |
| 135 | 142 |
| 143 void GrBitmapTextGeoProc::onGetInvariantOutputCoverage(GrInitInvariantOutput* ou
t) const { |
| 144 if (kARGB_GrMaskFormat != fMaskFormat) { |
| 145 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
| 146 out->setUnknownSingleComponent(); |
| 147 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 148 out->setUnknownOpaqueFourComponents(); |
| 149 out->setUsingLCDCoverage(); |
| 150 } else { |
| 151 out->setUnknownFourComponents(); |
| 152 out->setUsingLCDCoverage(); |
| 153 } |
| 154 } else { |
| 155 out->setKnownSingleComponent(0xff); |
| 156 } |
| 157 } |
| 158 |
| 136 void GrBitmapTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 159 void GrBitmapTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, |
| 137 const GrGLCaps& caps, | 160 const GrGLCaps& caps, |
| 138 GrProcessorKeyBuilder* b) const { | 161 GrProcessorKeyBuilder* b) const { |
| 139 GrGLBitmapTextGeoProc::GenKey(*this, bt, caps, b); | 162 GrGLBitmapTextGeoProc::GenKey(*this, bt, caps, b); |
| 140 } | 163 } |
| 141 | 164 |
| 142 GrGLPrimitiveProcessor* | 165 GrGLPrimitiveProcessor* |
| 143 GrBitmapTextGeoProc::createGLInstance(const GrBatchTracker& bt, | 166 GrBitmapTextGeoProc::createGLInstance(const GrBatchTracker& bt, |
| 144 const GrGLCaps& caps) const { | 167 const GrGLCaps& caps) const { |
| 145 return SkNEW_ARGS(GrGLBitmapTextGeoProc, (*this, bt)); | 168 return SkNEW_ARGS(GrGLBitmapTextGeoProc, (*this, bt)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 SkShader::kRepeat_TileMode, | 201 SkShader::kRepeat_TileMode, |
| 179 SkShader::kMirror_TileMode, | 202 SkShader::kMirror_TileMode, |
| 180 }; | 203 }; |
| 181 SkShader::TileMode tileModes[] = { | 204 SkShader::TileMode tileModes[] = { |
| 182 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 205 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 183 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 206 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 184 }; | 207 }; |
| 185 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 208 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 186 GrTextureParams::kNon
e_FilterMode); | 209 GrTextureParams::kNon
e_FilterMode); |
| 187 | 210 |
| 211 GrMaskFormat format; |
| 212 switch (random->nextULessThan(3)) { |
| 213 default: |
| 214 SkFAIL("Incomplete enum\n"); |
| 215 case 0: |
| 216 format = kA8_GrMaskFormat; |
| 217 break; |
| 218 case 1: |
| 219 format = kA565_GrMaskFormat; |
| 220 break; |
| 221 case 2: |
| 222 format = kARGB_GrMaskFormat; |
| 223 break; |
| 224 } |
| 225 |
| 188 return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx],
params, | 226 return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx],
params, |
| 189 random->nextBool(), random->nextBool(), | 227 format, random->nextBool(), |
| 190 GrProcessorUnitTest::TestMatrix(random)); | 228 GrProcessorUnitTest::TestMatrix(random)); |
| 191 } | 229 } |
| OLD | NEW |