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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 SkAssertResult(fsBuilder->enableFeature( | 38 SkAssertResult(fsBuilder->enableFeature( |
39 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 39 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
40 | 40 |
41 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 41 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
42 | 42 |
43 // emit attributes | 43 // emit attributes |
44 vsBuilder->emitAttributes(dfTexEffect); | 44 vsBuilder->emitAttributes(dfTexEffect); |
45 | 45 |
46 #ifdef SK_GAMMA_APPLY_TO_A8 | 46 #ifdef SK_GAMMA_APPLY_TO_A8 |
47 // adjust based on gamma | 47 // adjust based on gamma |
48 const char* distanceAdjustUniName = NULL; | 48 const char* distanceAdjustUniName = nullptr; |
49 // width, height, 1/(3*width) | 49 // width, height, 1/(3*width) |
50 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 50 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
51 kFloat_GrSLType, kDefault_GrSLPrecision, | 51 kFloat_GrSLType, kDefault_GrSLPrecision, |
52 "DistanceAdjust", &distanceAdjustUniName); | 52 "DistanceAdjust", &distanceAdjustUniName); |
53 #endif | 53 #endif |
54 | 54 |
55 // Setup pass through color | 55 // Setup pass through color |
56 if (!dfTexEffect.colorIgnored()) { | 56 if (!dfTexEffect.colorIgnored()) { |
57 if (dfTexEffect.hasVertexColor()) { | 57 if (dfTexEffect.hasVertexColor()) { |
58 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); | 58 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 #endif | 215 #endif |
216 uint32_t flags, | 216 uint32_t flags, |
217 bool usesLocalCoords) | 217 bool usesLocalCoords) |
218 : fColor(color) | 218 : fColor(color) |
219 , fViewMatrix(viewMatrix) | 219 , fViewMatrix(viewMatrix) |
220 , fTextureAccess(texture, params) | 220 , fTextureAccess(texture, params) |
221 #ifdef SK_GAMMA_APPLY_TO_A8 | 221 #ifdef SK_GAMMA_APPLY_TO_A8 |
222 , fDistanceAdjust(distanceAdjust) | 222 , fDistanceAdjust(distanceAdjust) |
223 #endif | 223 #endif |
224 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 224 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
225 , fInColor(NULL) | 225 , fInColor(nullptr) |
226 , fUsesLocalCoords(usesLocalCoords) { | 226 , fUsesLocalCoords(usesLocalCoords) { |
227 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 227 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
228 this->initClassID<GrDistanceFieldA8TextGeoProc>(); | 228 this->initClassID<GrDistanceFieldA8TextGeoProc>(); |
229 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 229 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
230 kHigh_GrSLPrecision)); | 230 kHigh_GrSLPrecision)); |
231 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 231 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
232 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 232 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
233 } | 233 } |
234 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 234 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
235 kVec2s_GrVertexAttribT
ype)); | 235 kVec2s_GrVertexAttribT
ype)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); | 315 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoord
s()->fName); |
316 | 316 |
317 // Setup position | 317 // Setup position |
318 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), | 318 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), |
319 &fViewMatrixUniform); | 319 &fViewMatrixUniform); |
320 | 320 |
321 // emit transforms | 321 // emit transforms |
322 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, | 322 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosit
ion()->fName, |
323 args.fTransformsIn, args.fTransformsOut); | 323 args.fTransformsIn, args.fTransformsOut); |
324 | 324 |
325 const char* textureSizeUniName = NULL; | 325 const char* textureSizeUniName = nullptr; |
326 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 326 fTextureSizeUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
327 kVec2f_GrSLType, kDefault_GrSLPrec
ision, | 327 kVec2f_GrSLType, kDefault_GrSLPrec
ision, |
328 "TextureSize", &textureSizeUniName
); | 328 "TextureSize", &textureSizeUniName
); |
329 | 329 |
330 // Use highp to work around aliasing issues | 330 // Use highp to work around aliasing issues |
331 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, | 331 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision
, |
332 pb->ctxInfo().stand
ard())); | 332 pb->ctxInfo().stand
ard())); |
333 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); | 333 fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); |
334 | 334 |
335 fsBuilder->codeAppend("float texColor = "); | 335 fsBuilder->codeAppend("float texColor = "); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 GrColor color, | 439 GrColor color, |
440 const SkMatrix& viewMatrix, | 440 const SkMatrix& viewMatrix, |
441 GrTexture* texture, | 441 GrTexture* texture, |
442 const GrTextureParams& params, | 442 const GrTextureParams& params, |
443 uint32_t flags, | 443 uint32_t flags, |
444 bool usesLocalCoords) | 444 bool usesLocalCoords) |
445 : fColor(color) | 445 : fColor(color) |
446 , fViewMatrix(viewMatrix) | 446 , fViewMatrix(viewMatrix) |
447 , fTextureAccess(texture, params) | 447 , fTextureAccess(texture, params) |
448 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) | 448 , fFlags(flags & kNonLCD_DistanceFieldEffectMask) |
449 , fInColor(NULL) | 449 , fInColor(nullptr) |
450 , fUsesLocalCoords(usesLocalCoords) { | 450 , fUsesLocalCoords(usesLocalCoords) { |
451 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); | 451 SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask)); |
452 this->initClassID<GrDistanceFieldPathGeoProc>(); | 452 this->initClassID<GrDistanceFieldPathGeoProc>(); |
453 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, | 453 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex
AttribType, |
454 kHigh_GrSLPrecision)); | 454 kHigh_GrSLPrecision)); |
455 if (flags & kColorAttr_DistanceFieldEffectFlag) { | 455 if (flags & kColorAttr_DistanceFieldEffectFlag) { |
456 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 456 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
457 } | 457 } |
458 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 458 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
459 kVec2f_GrVertexAttribTyp
e)); | 459 kVec2f_GrVertexAttribTyp
e)); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 fsBuilder->codeAppend("\tuv_adjusted = uv + offset;\n"); | 599 fsBuilder->codeAppend("\tuv_adjusted = uv + offset;\n"); |
600 fsBuilder->codeAppend("\ttexColor = "); | 600 fsBuilder->codeAppend("\ttexColor = "); |
601 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv_adjusted", kVec2f_
GrSLType); | 601 fsBuilder->appendTextureLookup(args.fSamplers[0], "uv_adjusted", kVec2f_
GrSLType); |
602 fsBuilder->codeAppend(";\n"); | 602 fsBuilder->codeAppend(";\n"); |
603 fsBuilder->codeAppend("\tdistance.z = texColor.r;\n"); | 603 fsBuilder->codeAppend("\tdistance.z = texColor.r;\n"); |
604 | 604 |
605 fsBuilder->codeAppend("\tdistance = " | 605 fsBuilder->codeAppend("\tdistance = " |
606 "vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceF
ieldThreshold"));"); | 606 "vec3(" SK_DistanceFieldMultiplier ")*(distance - vec3(" SK_DistanceF
ieldThreshold"));"); |
607 | 607 |
608 // adjust width based on gamma | 608 // adjust width based on gamma |
609 const char* distanceAdjustUniName = NULL; | 609 const char* distanceAdjustUniName = nullptr; |
610 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 610 fDistanceAdjustUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
611 kVec3f_GrSLType, kDefault_GrSLPrecision, | 611 kVec3f_GrSLType, kDefault_GrSLPrecision, |
612 "DistanceAdjust", &distanceAdjustUniName); | 612 "DistanceAdjust", &distanceAdjustUniName); |
613 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); | 613 fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName); |
614 | 614 |
615 // To be strictly correct, we should compute the anti-aliasing factor se
parately | 615 // To be strictly correct, we should compute the anti-aliasing factor se
parately |
616 // for each color component. However, this is only important when using
perspective | 616 // for each color component. However, this is only important when using
perspective |
617 // transformations, and even then using a single factor seems like a rea
sonable | 617 // transformations, and even then using a single factor seems like a rea
sonable |
618 // trade-off between quality and speed. | 618 // trade-off between quality and speed. |
619 fsBuilder->codeAppend("float afwidth;"); | 619 fsBuilder->codeAppend("float afwidth;"); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 766 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
767 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 767 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
768 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 768 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
769 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 769 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
770 GrTest::TestMatrix(d->fRandom), | 770 GrTest::TestMatrix(d->fRandom), |
771 d->fTextures[texIdx], params, | 771 d->fTextures[texIdx], params, |
772 wa, | 772 wa, |
773 flags, | 773 flags, |
774 d->fRandom->nextBool()); | 774 d->fRandom->nextBool()); |
775 } | 775 } |
OLD | NEW |