| 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 "GrDistanceFieldGeoProc.h" | 8 #include "GrDistanceFieldGeoProc.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
| 11 | 11 |
| 12 #include "SkDistanceFieldGen.h" | 12 #include "SkDistanceFieldGen.h" |
| 13 | 13 |
| 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 #include "glsl/GrGLSLGeometryProcessor.h" | 15 #include "glsl/GrGLSLGeometryProcessor.h" |
| 16 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 #include "glsl/GrGLSLUniformHandler.h" | 17 #include "glsl/GrGLSLUniformHandler.h" |
| 18 #include "glsl/GrGLSLUtil.h" | 18 #include "glsl/GrGLSLUtil.h" |
| 19 #include "glsl/GrGLSLVarying.h" | 19 #include "glsl/GrGLSLVarying.h" |
| 20 #include "glsl/GrGLSLVertexShaderBuilder.h" | 20 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 21 | 21 |
| 22 // Assuming a radius of a little less than the diagonal of the fragment | 22 // Assuming a radius of a little less than the diagonal of the fragment |
| 23 #define SK_DistanceFieldAAFactor "0.65" | 23 #define SK_DistanceFieldAAFactor "0.65" |
| 24 | 24 |
| 25 class GrGLDistanceFieldA8TextGeoProc : public GrGLSLGeometryProcessor { | 25 class GrGLDistanceFieldA8TextGeoProc : public GrGLSLGeometryProcessor { |
| 26 public: | 26 public: |
| 27 GrGLDistanceFieldA8TextGeoProc() | 27 GrGLDistanceFieldA8TextGeoProc() |
| 28 : fViewMatrix(SkMatrix::InvalidMatrix()) | 28 : fViewMatrix(SkMatrix::InvalidMatrix()) |
| 29 , fColor(GrColor_ILLEGAL) | |
| 30 #ifdef SK_GAMMA_APPLY_TO_A8 | 29 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 31 , fDistanceAdjust(-1.0f) | 30 , fDistanceAdjust(-1.0f) |
| 32 #endif | 31 #endif |
| 33 {} | 32 {} |
| 34 | 33 |
| 35 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 34 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 36 const GrDistanceFieldA8TextGeoProc& dfTexEffect = | 35 const GrDistanceFieldA8TextGeoProc& dfTexEffect = |
| 37 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); | 36 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); |
| 38 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 37 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 39 SkAssertResult(fragBuilder->enableFeature( | 38 SkAssertResult(fragBuilder->enableFeature( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 // adjust based on gamma | 49 // adjust based on gamma |
| 51 const char* distanceAdjustUniName = nullptr; | 50 const char* distanceAdjustUniName = nullptr; |
| 52 // width, height, 1/(3*width) | 51 // width, height, 1/(3*width) |
| 53 fDistanceAdjustUni = uniformHandler->addUniform(GrGLSLUniformHandler::kF
ragment_Visibility, | 52 fDistanceAdjustUni = uniformHandler->addUniform(GrGLSLUniformHandler::kF
ragment_Visibility, |
| 54 kFloat_GrSLType, kDefaul
t_GrSLPrecision, | 53 kFloat_GrSLType, kDefaul
t_GrSLPrecision, |
| 55 "DistanceAdjust", &dista
nceAdjustUniName); | 54 "DistanceAdjust", &dista
nceAdjustUniName); |
| 56 #endif | 55 #endif |
| 57 | 56 |
| 58 // Setup pass through color | 57 // Setup pass through color |
| 59 if (!dfTexEffect.colorIgnored()) { | 58 if (!dfTexEffect.colorIgnored()) { |
| 60 if (dfTexEffect.hasVertexColor()) { | 59 varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.
fOutputColor); |
| 61 varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), a
rgs.fOutputColor); | |
| 62 } else { | |
| 63 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutpu
tColor, | |
| 64 &fColorUniform); | |
| 65 } | |
| 66 } | 60 } |
| 67 | 61 |
| 68 // Setup position | 62 // Setup position |
| 69 this->setupPosition(vertBuilder, | 63 this->setupPosition(vertBuilder, |
| 70 uniformHandler, | 64 uniformHandler, |
| 71 gpArgs, | 65 gpArgs, |
| 72 dfTexEffect.inPosition()->fName, | 66 dfTexEffect.inPosition()->fName, |
| 73 dfTexEffect.viewMatrix(), | 67 dfTexEffect.viewMatrix(), |
| 74 &fViewMatrixUniform); | 68 &fViewMatrixUniform); |
| 75 | 69 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 161 } |
| 168 #endif | 162 #endif |
| 169 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); | 163 const GrDistanceFieldA8TextGeoProc& dfa8gp = proc.cast<GrDistanceFieldA8
TextGeoProc>(); |
| 170 | 164 |
| 171 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g
p.viewMatrix())) { | 165 if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8g
p.viewMatrix())) { |
| 172 fViewMatrix = dfa8gp.viewMatrix(); | 166 fViewMatrix = dfa8gp.viewMatrix(); |
| 173 float viewMatrix[3 * 3]; | 167 float viewMatrix[3 * 3]; |
| 174 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 168 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 175 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 169 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 176 } | 170 } |
| 177 | |
| 178 if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { | |
| 179 float c[4]; | |
| 180 GrColorToRGBAFloat(dfa8gp.color(), c); | |
| 181 pdman.set4fv(fColorUniform, 1, c); | |
| 182 fColor = dfa8gp.color(); | |
| 183 } | |
| 184 } | 171 } |
| 185 | 172 |
| 186 static inline void GenKey(const GrGeometryProcessor& gp, | 173 static inline void GenKey(const GrGeometryProcessor& gp, |
| 187 const GrGLSLCaps&, | 174 const GrGLSLCaps&, |
| 188 GrProcessorKeyBuilder* b) { | 175 GrProcessorKeyBuilder* b) { |
| 189 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); | 176 const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFiel
dA8TextGeoProc>(); |
| 190 uint32_t key = dfTexEffect.getFlags(); | 177 uint32_t key = dfTexEffect.getFlags(); |
| 191 key |= dfTexEffect.hasVertexColor() << 16; | 178 key |= dfTexEffect.colorIgnored() << 16; |
| 192 key |= dfTexEffect.colorIgnored() << 17; | |
| 193 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 179 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
| 194 b->add32(key); | 180 b->add32(key); |
| 195 | 181 |
| 196 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point | 182 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point |
| 197 SkASSERT(gp.numTextures() == 1); | 183 SkASSERT(gp.numTextures() == 1); |
| 198 GrTexture* atlas = gp.textureAccess(0).getTexture(); | 184 GrTexture* atlas = gp.textureAccess(0).getTexture(); |
| 199 SkASSERT(atlas); | 185 SkASSERT(atlas); |
| 200 b->add32(atlas->width()); | 186 b->add32(atlas->width()); |
| 201 b->add32(atlas->height()); | 187 b->add32(atlas->height()); |
| 202 } | 188 } |
| 203 | 189 |
| 204 private: | 190 private: |
| 205 SkMatrix fViewMatrix; | 191 SkMatrix fViewMatrix; |
| 206 GrColor fColor; | |
| 207 UniformHandle fColorUniform; | |
| 208 UniformHandle fViewMatrixUniform; | 192 UniformHandle fViewMatrixUniform; |
| 209 #ifdef SK_GAMMA_APPLY_TO_A8 | 193 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 210 float fDistanceAdjust; | 194 float fDistanceAdjust; |
| 211 UniformHandle fDistanceAdjustUni; | 195 UniformHandle fDistanceAdjustUni; |
| 212 #endif | 196 #endif |
| 213 | 197 |
| 214 typedef GrGLSLGeometryProcessor INHERITED; | 198 typedef GrGLSLGeometryProcessor INHERITED; |
| 215 }; | 199 }; |
| 216 | 200 |
| 217 /////////////////////////////////////////////////////////////////////////////// | 201 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 13 matching lines...) Expand all Loading... |
| 231 #ifdef SK_GAMMA_APPLY_TO_A8 | 215 #ifdef SK_GAMMA_APPLY_TO_A8 |
| 232 , fDistanceAdjust(distanceAdjust) | 216 , fDistanceAdjust(distanceAdjust) |
| 233 #endif | 217 #endif |
| 234 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 218 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
| 235 , fInColor(nullptr) | 219 , fInColor(nullptr) |
| 236 , fUsesLocalCoords(usesLocalCoords) { | 220 , fUsesLocalCoords(usesLocalCoords) { |
| 237 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 221 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 238 this->initClassID<GrDistanceFieldA8TextGeoProc>(); | 222 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
| 239 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 223 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
| 240 kHigh_GrSLPrecision)); | 224 kHigh_GrSLPrecision)); |
| 241 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 225 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); |
| 242 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | |
| 243 } | |
| 244 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 226 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 245 kVec2s_GrVertexAttribT
ype)); | 227 kVec2s_GrVertexAttribT
ype)); |
| 246 this->addTextureAccess(&fTextureAccess); | 228 this->addTextureAccess(&fTextureAccess); |
| 247 } | 229 } |
| 248 | 230 |
| 249 void GrDistanceFieldA8TextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, | 231 void GrDistanceFieldA8TextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, |
| 250 GrProcessorKeyBuilder* b)
const { | 232 GrProcessorKeyBuilder* b)
const { |
| 251 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); | 233 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); |
| 252 } | 234 } |
| 253 | 235 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 284 kSimilarity_DistanceFieldEff
ectFlag : 0, | 266 kSimilarity_DistanceFieldEff
ectFlag : 0, |
| 285 d->fRandom->nextBool()); | 267 d->fRandom->nextBool()); |
| 286 } | 268 } |
| 287 | 269 |
| 288 /////////////////////////////////////////////////////////////////////////////// | 270 /////////////////////////////////////////////////////////////////////////////// |
| 289 | 271 |
| 290 class GrGLDistanceFieldPathGeoProc : public GrGLSLGeometryProcessor { | 272 class GrGLDistanceFieldPathGeoProc : public GrGLSLGeometryProcessor { |
| 291 public: | 273 public: |
| 292 GrGLDistanceFieldPathGeoProc() | 274 GrGLDistanceFieldPathGeoProc() |
| 293 : fViewMatrix(SkMatrix::InvalidMatrix()) | 275 : fViewMatrix(SkMatrix::InvalidMatrix()) |
| 294 , fColor(GrColor_ILLEGAL) | |
| 295 , fTextureSize(SkISize::Make(-1, -1)) {} | 276 , fTextureSize(SkISize::Make(-1, -1)) {} |
| 296 | 277 |
| 297 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 278 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 298 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); | 279 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); |
| 299 | 280 |
| 300 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 281 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 301 SkAssertResult(fragBuilder->enableFeature( | 282 SkAssertResult(fragBuilder->enableFeature( |
| 302 GrGLSLFragmentShaderBuilder::kStandardDeriv
atives_GLSLFeature)); | 283 GrGLSLFragmentShaderBuilder::kStandardDeriv
atives_GLSLFeature)); |
| 303 | 284 |
| 304 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 285 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 305 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 286 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 306 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 287 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 307 | 288 |
| 308 // emit attributes | 289 // emit attributes |
| 309 varyingHandler->emitAttributes(dfTexEffect); | 290 varyingHandler->emitAttributes(dfTexEffect); |
| 310 | 291 |
| 311 GrGLSLVertToFrag v(kVec2f_GrSLType); | 292 GrGLSLVertToFrag v(kVec2f_GrSLType); |
| 312 varyingHandler->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); | 293 varyingHandler->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); |
| 313 | 294 |
| 314 // setup pass through color | 295 // setup pass through color |
| 315 if (!dfTexEffect.colorIgnored()) { | 296 if (!dfTexEffect.colorIgnored()) { |
| 316 if (dfTexEffect.hasVertexColor()) { | 297 varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.
fOutputColor); |
| 317 varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), a
rgs.fOutputColor); | |
| 318 } else { | |
| 319 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutpu
tColor, | |
| 320 &fColorUniform); | |
| 321 } | |
| 322 } | 298 } |
| 323 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoo
rds()->fName); | 299 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoo
rds()->fName); |
| 324 | 300 |
| 325 // Setup position | 301 // Setup position |
| 326 this->setupPosition(vertBuilder, | 302 this->setupPosition(vertBuilder, |
| 327 uniformHandler, | 303 uniformHandler, |
| 328 gpArgs, | 304 gpArgs, |
| 329 dfTexEffect.inPosition()->fName, | 305 dfTexEffect.inPosition()->fName, |
| 330 dfTexEffect.viewMatrix(), | 306 dfTexEffect.viewMatrix(), |
| 331 &fViewMatrixUniform); | 307 &fViewMatrixUniform); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 384 } |
| 409 | 385 |
| 410 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); | 386 const GrDistanceFieldPathGeoProc& dfpgp = proc.cast<GrDistanceFieldPathG
eoProc>(); |
| 411 | 387 |
| 412 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.
viewMatrix())) { | 388 if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.
viewMatrix())) { |
| 413 fViewMatrix = dfpgp.viewMatrix(); | 389 fViewMatrix = dfpgp.viewMatrix(); |
| 414 float viewMatrix[3 * 3]; | 390 float viewMatrix[3 * 3]; |
| 415 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 391 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 416 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 392 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 417 } | 393 } |
| 418 | |
| 419 if (dfpgp.color() != fColor && !dfpgp.hasVertexColor()) { | |
| 420 float c[4]; | |
| 421 GrColorToRGBAFloat(dfpgp.color(), c); | |
| 422 pdman.set4fv(fColorUniform, 1, c); | |
| 423 fColor = dfpgp.color(); | |
| 424 } | |
| 425 } | 394 } |
| 426 | 395 |
| 427 static inline void GenKey(const GrGeometryProcessor& gp, | 396 static inline void GenKey(const GrGeometryProcessor& gp, |
| 428 const GrGLSLCaps&, | 397 const GrGLSLCaps&, |
| 429 GrProcessorKeyBuilder* b) { | 398 GrProcessorKeyBuilder* b) { |
| 430 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); | 399 const GrDistanceFieldPathGeoProc& dfTexEffect = gp.cast<GrDistanceFieldP
athGeoProc>(); |
| 431 | 400 |
| 432 uint32_t key = dfTexEffect.getFlags(); | 401 uint32_t key = dfTexEffect.getFlags(); |
| 433 key |= dfTexEffect.colorIgnored() << 16; | 402 key |= dfTexEffect.colorIgnored() << 16; |
| 434 key |= dfTexEffect.hasVertexColor() << 17; | |
| 435 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 403 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
| 436 b->add32(key); | 404 b->add32(key); |
| 437 } | 405 } |
| 438 | 406 |
| 439 private: | 407 private: |
| 440 UniformHandle fColorUniform; | |
| 441 UniformHandle fTextureSizeUni; | 408 UniformHandle fTextureSizeUni; |
| 442 UniformHandle fViewMatrixUniform; | 409 UniformHandle fViewMatrixUniform; |
| 443 SkMatrix fViewMatrix; | 410 SkMatrix fViewMatrix; |
| 444 GrColor fColor; | |
| 445 SkISize fTextureSize; | 411 SkISize fTextureSize; |
| 446 | 412 |
| 447 typedef GrGLSLGeometryProcessor INHERITED; | 413 typedef GrGLSLGeometryProcessor INHERITED; |
| 448 }; | 414 }; |
| 449 | 415 |
| 450 /////////////////////////////////////////////////////////////////////////////// | 416 /////////////////////////////////////////////////////////////////////////////// |
| 451 | 417 |
| 452 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( | 418 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( |
| 453 GrColor color, | 419 GrColor color, |
| 454 const SkMatrix& viewMatrix, | 420 const SkMatrix& viewMatrix, |
| 455 GrTexture* texture, | 421 GrTexture* texture, |
| 456 const GrTextureParams& params, | 422 const GrTextureParams& params, |
| 457 uint32_t flags, | 423 uint32_t flags, |
| 458 bool usesLocalCoords) | 424 bool usesLocalCoords) |
| 459 : fColor(color) | 425 : fColor(color) |
| 460 , fViewMatrix(viewMatrix) | 426 , fViewMatrix(viewMatrix) |
| 461 , fTextureAccess(texture, params) | 427 , fTextureAccess(texture, params) |
| 462 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 428 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
| 463 , fInColor(nullptr) | 429 , fInColor(nullptr) |
| 464 , fUsesLocalCoords(usesLocalCoords) { | 430 , fUsesLocalCoords(usesLocalCoords) { |
| 465 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 431 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
| 466 this->initClassID<GrDistanceFieldPathGeoProc>(); | 432 this->initClassID<GrDistanceFieldPathGeoProc>(); |
| 467 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 433 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
| 468 kHigh_GrSLPrecision)); | 434 kHigh_GrSLPrecision)); |
| 469 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 435 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); |
| 470 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | |
| 471 } | |
| 472 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 436 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 473 kVec2f_GrVertexAttribTyp
e)); | 437 kVec2f_GrVertexAttribTyp
e)); |
| 474 this->addTextureAccess(&fTextureAccess); | 438 this->addTextureAccess(&fTextureAccess); |
| 475 } | 439 } |
| 476 | 440 |
| 477 void GrDistanceFieldPathGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, | 441 void GrDistanceFieldPathGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, |
| 478 GrProcessorKeyBuilder* b) c
onst { | 442 GrProcessorKeyBuilder* b) c
onst { |
| 479 GrGLDistanceFieldPathGeoProc::GenKey(*this, caps, b); | 443 GrGLDistanceFieldPathGeoProc::GenKey(*this, caps, b); |
| 480 } | 444 } |
| 481 | 445 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 509 d->fRandom->nextBool() ? | 473 d->fRandom->nextBool() ? |
| 510 kSimilarity_DistanceFieldE
ffectFlag : 0, | 474 kSimilarity_DistanceFieldE
ffectFlag : 0, |
| 511 d->fRandom->nextBool()); | 475 d->fRandom->nextBool()); |
| 512 } | 476 } |
| 513 | 477 |
| 514 /////////////////////////////////////////////////////////////////////////////// | 478 /////////////////////////////////////////////////////////////////////////////// |
| 515 | 479 |
| 516 class GrGLDistanceFieldLCDTextGeoProc : public GrGLSLGeometryProcessor { | 480 class GrGLDistanceFieldLCDTextGeoProc : public GrGLSLGeometryProcessor { |
| 517 public: | 481 public: |
| 518 GrGLDistanceFieldLCDTextGeoProc() | 482 GrGLDistanceFieldLCDTextGeoProc() |
| 519 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { | 483 : fViewMatrix(SkMatrix::InvalidMatrix()) { |
| 520 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); | 484 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); |
| 521 } | 485 } |
| 522 | 486 |
| 523 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 487 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
| 524 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = | 488 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
| 525 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); | 489 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
| 526 | 490 |
| 527 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 491 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 528 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 492 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 529 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 493 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 530 | 494 |
| 531 // emit attributes | 495 // emit attributes |
| 532 varyingHandler->emitAttributes(dfTexEffect); | 496 varyingHandler->emitAttributes(dfTexEffect); |
| 533 | 497 |
| 534 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 498 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 535 | 499 |
| 536 // setup pass through color | 500 // setup pass through color |
| 537 if (!dfTexEffect.colorIgnored()) { | 501 if (!dfTexEffect.colorIgnored()) { |
| 538 if (dfTexEffect.hasVertexColor()) { | 502 varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.
fOutputColor); |
| 539 varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), a
rgs.fOutputColor); | |
| 540 } else { | |
| 541 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutpu
tColor, | |
| 542 &fColorUniform); | |
| 543 } | |
| 544 } | 503 } |
| 545 | 504 |
| 546 // Setup position | 505 // Setup position |
| 547 this->setupPosition(vertBuilder, | 506 this->setupPosition(vertBuilder, |
| 548 uniformHandler, | 507 uniformHandler, |
| 549 gpArgs, | 508 gpArgs, |
| 550 dfTexEffect.inPosition()->fName, | 509 dfTexEffect.inPosition()->fName, |
| 551 dfTexEffect.viewMatrix(), | 510 dfTexEffect.viewMatrix(), |
| 552 &fViewMatrixUniform); | 511 &fViewMatrixUniform); |
| 553 | 512 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 wa.fB); | 652 wa.fB); |
| 694 fDistanceAdjust = wa; | 653 fDistanceAdjust = wa; |
| 695 } | 654 } |
| 696 | 655 |
| 697 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.
viewMatrix())) { | 656 if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.
viewMatrix())) { |
| 698 fViewMatrix = dflcd.viewMatrix(); | 657 fViewMatrix = dflcd.viewMatrix(); |
| 699 float viewMatrix[3 * 3]; | 658 float viewMatrix[3 * 3]; |
| 700 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); | 659 GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 701 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); | 660 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 702 } | 661 } |
| 703 | |
| 704 if (dflcd.color() != fColor && !dflcd.hasVertexColor()) { | |
| 705 float c[4]; | |
| 706 GrColorToRGBAFloat(dflcd.color(), c); | |
| 707 pdman.set4fv(fColorUniform, 1, c); | |
| 708 fColor = dflcd.color(); | |
| 709 } | |
| 710 } | 662 } |
| 711 | 663 |
| 712 static inline void GenKey(const GrGeometryProcessor& gp, | 664 static inline void GenKey(const GrGeometryProcessor& gp, |
| 713 const GrGLSLCaps&, | 665 const GrGLSLCaps&, |
| 714 GrProcessorKeyBuilder* b) { | 666 GrProcessorKeyBuilder* b) { |
| 715 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); | 667 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = gp.cast<GrDistanceFie
ldLCDTextGeoProc>(); |
| 716 | 668 |
| 717 uint32_t key = dfTexEffect.getFlags(); | 669 uint32_t key = dfTexEffect.getFlags(); |
| 718 key |= dfTexEffect.colorIgnored() << 16; | 670 key |= dfTexEffect.colorIgnored() << 16; |
| 719 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; | 671 key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25; |
| 720 b->add32(key); | 672 b->add32(key); |
| 721 | 673 |
| 722 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point | 674 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point |
| 723 SkASSERT(gp.numTextures() == 1); | 675 SkASSERT(gp.numTextures() == 1); |
| 724 GrTexture* atlas = gp.textureAccess(0).getTexture(); | 676 GrTexture* atlas = gp.textureAccess(0).getTexture(); |
| 725 SkASSERT(atlas); | 677 SkASSERT(atlas); |
| 726 b->add32(atlas->width()); | 678 b->add32(atlas->width()); |
| 727 b->add32(atlas->height()); | 679 b->add32(atlas->height()); |
| 728 } | 680 } |
| 729 | 681 |
| 730 private: | 682 private: |
| 731 SkMatrix fViewMatrix; | 683 SkMatrix fViewMatrix; |
| 732 GrColor fColor; | |
| 733 UniformHandle fViewMatrixUniform; | 684 UniformHandle fViewMatrixUniform; |
| 734 UniformHandle fColorUniform; | 685 UniformHandle fColorUniform; |
| 735 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; | 686 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; |
| 736 UniformHandle fDistanceAdjustUni; | 687 UniformHandle fDistanceAdjustUni; |
| 737 | 688 |
| 738 typedef GrGLSLGeometryProcessor INHERITED; | 689 typedef GrGLSLGeometryProcessor INHERITED; |
| 739 }; | 690 }; |
| 740 | 691 |
| 741 /////////////////////////////////////////////////////////////////////////////// | 692 /////////////////////////////////////////////////////////////////////////////// |
| 742 | 693 |
| 743 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( | 694 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( |
| 744 GrColor color, const SkMatrix&
viewMatrix, | 695 GrColor color, const SkMatrix&
viewMatrix, |
| 745 GrTexture* texture, const GrTe
xtureParams& params, | 696 GrTexture* texture, const GrTe
xtureParams& params, |
| 746 DistanceAdjust distanceAdjust, | 697 DistanceAdjust distanceAdjust, |
| 747 uint32_t flags, bool usesLocal
Coords) | 698 uint32_t flags, bool usesLocal
Coords) |
| 748 : fColor(color) | 699 : fColor(color) |
| 749 , fViewMatrix(viewMatrix) | 700 , fViewMatrix(viewMatrix) |
| 750 , fTextureAccess(texture, params) | 701 , fTextureAccess(texture, params) |
| 751 , fDistanceAdjust(distanceAdjust) | 702 , fDistanceAdjust(distanceAdjust) |
| 752 , fFlags(flags & kLCD_DistanceFieldEffectMask) | 703 , fFlags(flags & kLCD_DistanceFieldEffectMask) |
| 753 , fUsesLocalCoords(usesLocalCoords) { | 704 , fUsesLocalCoords(usesLocalCoords) { |
| 754 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); | 705 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan
ceFieldEffectFlag)); |
| 755 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); | 706 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); |
| 756 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 707 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
| 757 kHigh_GrSLPrecision)); | 708 kHigh_GrSLPrecision)); |
| 758 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 709 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttri
bType)); |
| 759 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | |
| 760 } | |
| 761 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 710 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
| 762 kVec2s_GrVertexAttribTyp
e)); | 711 kVec2s_GrVertexAttribTyp
e)); |
| 763 this->addTextureAccess(&fTextureAccess); | 712 this->addTextureAccess(&fTextureAccess); |
| 764 } | 713 } |
| 765 | 714 |
| 766 void GrDistanceFieldLCDTextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, | 715 void GrDistanceFieldLCDTextGeoProc::getGLSLProcessorKey(const GrGLSLCaps& caps, |
| 767 GrProcessorKeyBuilder* b
) const { | 716 GrProcessorKeyBuilder* b
) const { |
| 768 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); | 717 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); |
| 769 } | 718 } |
| 770 | 719 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 794 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 743 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
| 795 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 744 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
| 796 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 745 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
| 797 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 746 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
| 798 GrTest::TestMatrix(d->fRandom), | 747 GrTest::TestMatrix(d->fRandom), |
| 799 d->fTextures[texIdx], params, | 748 d->fTextures[texIdx], params, |
| 800 wa, | 749 wa, |
| 801 flags, | 750 flags, |
| 802 d->fRandom->nextBool()); | 751 d->fRandom->nextBool()); |
| 803 } | 752 } |
| OLD | NEW |