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 15 matching lines...) Expand all Loading... |
26 : fViewMatrix(SkMatrix::InvalidMatrix()) | 26 : fViewMatrix(SkMatrix::InvalidMatrix()) |
27 , fColor(GrColor_ILLEGAL) | 27 , fColor(GrColor_ILLEGAL) |
28 #ifdef SK_GAMMA_APPLY_TO_A8 | 28 #ifdef SK_GAMMA_APPLY_TO_A8 |
29 , fDistanceAdjust(-1.0f) | 29 , fDistanceAdjust(-1.0f) |
30 #endif | 30 #endif |
31 {} | 31 {} |
32 | 32 |
33 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 33 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
34 const GrDistanceFieldA8TextGeoProc& dfTexEffect = | 34 const GrDistanceFieldA8TextGeoProc& dfTexEffect = |
35 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); | 35 args.fGP.cast<GrDistanceFieldA8TextGeoProc>(); |
36 GrGLGPBuilder* pb = args.fPB; | 36 GrGLSLGPBuilder* pb = args.fPB; |
37 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 37 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
38 SkAssertResult(fsBuilder->enableFeature( | 38 SkAssertResult(fsBuilder->enableFeature( |
39 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); | 39 GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); |
40 | 40 |
41 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 41 GrGLVertexBuilder* vsBuilder = pb->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 |
(...skipping 16 matching lines...) Expand all Loading... |
63 | 63 |
64 // Setup position | 64 // Setup position |
65 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), | 65 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), |
66 &fViewMatrixUniform); | 66 &fViewMatrixUniform); |
67 | 67 |
68 // emit transforms | 68 // emit transforms |
69 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, | 69 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, |
70 args.fTransformsIn, args.fTransformsOut); | 70 args.fTransformsIn, args.fTransformsOut); |
71 | 71 |
72 // add varyings | 72 // add varyings |
73 GrGLVertToFrag recipScale(kFloat_GrSLType); | 73 GrGLSLVertToFrag recipScale(kFloat_GrSLType); |
74 GrGLVertToFrag st(kVec2f_GrSLType); | 74 GrGLSLVertToFrag st(kVec2f_GrSLType); |
75 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); | 75 bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_Distan
ceFieldEffectFlag); |
76 pb->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 76 pb->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
77 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 77 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
78 | 78 |
79 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 79 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
80 SkASSERT(dfTexEffect.numTextures() == 1); | 80 SkASSERT(dfTexEffect.numTextures() == 1); |
81 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 81 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
82 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 82 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
83 SkScalar recipWidth = 1.0f / atlas->width(); | 83 SkScalar recipWidth = 1.0f / atlas->width(); |
84 SkScalar recipHeight = 1.0f / atlas->height(); | 84 SkScalar recipHeight = 1.0f / atlas->height(); |
85 | 85 |
86 GrGLVertToFrag uv(kVec2f_GrSLType); | 86 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
87 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 87 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
88 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 88 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
89 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, | 89 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
90 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 90 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
91 dfTexEffect.inTextureCoords()->fName); | 91 dfTexEffect.inTextureCoords()->fName); |
92 | 92 |
93 // Use highp to work around aliasing issues | 93 // Use highp to work around aliasing issues |
94 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), | 94 fsBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(pb->glslCaps(), |
95 kHigh_GrSLPrecisi
on)); | 95 kHigh_GrSLPrecisi
on)); |
96 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); | 96 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { | 277 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { |
278 public: | 278 public: |
279 GrGLDistanceFieldPathGeoProc() | 279 GrGLDistanceFieldPathGeoProc() |
280 : fViewMatrix(SkMatrix::InvalidMatrix()) | 280 : fViewMatrix(SkMatrix::InvalidMatrix()) |
281 , fColor(GrColor_ILLEGAL) | 281 , fColor(GrColor_ILLEGAL) |
282 , fTextureSize(SkISize::Make(-1, -1)) {} | 282 , fTextureSize(SkISize::Make(-1, -1)) {} |
283 | 283 |
284 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 284 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
285 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); | 285 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance
FieldPathGeoProc>(); |
286 | 286 |
287 GrGLGPBuilder* pb = args.fPB; | 287 GrGLSLGPBuilder* pb = args.fPB; |
288 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 288 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
289 SkAssertResult(fsBuilder->enableFeature( | 289 SkAssertResult(fsBuilder->enableFeature( |
290 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); | 290 GrGLFragmentShaderBuilder::kStandardDerivat
ives_GLSLFeature)); |
291 | 291 |
292 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 292 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
293 | 293 |
294 // emit attributes | 294 // emit attributes |
295 vsBuilder->emitAttributes(dfTexEffect); | 295 vsBuilder->emitAttributes(dfTexEffect); |
296 | 296 |
297 GrGLVertToFrag v(kVec2f_GrSLType); | 297 GrGLSLVertToFrag v(kVec2f_GrSLType); |
298 pb->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); | 298 pb->addVarying("TextureCoords", &v, kHigh_GrSLPrecision); |
299 | 299 |
300 // setup pass through color | 300 // setup pass through color |
301 if (!dfTexEffect.colorIgnored()) { | 301 if (!dfTexEffect.colorIgnored()) { |
302 if (dfTexEffect.hasVertexColor()) { | 302 if (dfTexEffect.hasVertexColor()) { |
303 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); | 303 pb->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputC
olor); |
304 } else { | 304 } else { |
305 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 305 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
306 } | 306 } |
307 } | 307 } |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { | 492 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { |
493 public: | 493 public: |
494 GrGLDistanceFieldLCDTextGeoProc() | 494 GrGLDistanceFieldLCDTextGeoProc() |
495 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { | 495 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { |
496 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); | 496 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.
0f, 1.0f, 1.0f); |
497 } | 497 } |
498 | 498 |
499 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 499 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
500 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = | 500 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = |
501 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); | 501 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); |
502 GrGLGPBuilder* pb = args.fPB; | 502 GrGLSLGPBuilder* pb = args.fPB; |
503 | 503 |
504 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 504 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
505 | 505 |
506 // emit attributes | 506 // emit attributes |
507 vsBuilder->emitAttributes(dfTexEffect); | 507 vsBuilder->emitAttributes(dfTexEffect); |
508 | 508 |
509 // setup pass through color | 509 // setup pass through color |
510 if (!dfTexEffect.colorIgnored()) { | 510 if (!dfTexEffect.colorIgnored()) { |
511 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 511 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
512 } | 512 } |
513 | 513 |
514 // Setup position | 514 // Setup position |
515 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), | 515 this->setupPosition(pb, gpArgs, dfTexEffect.inPosition()->fName, dfTexEf
fect.viewMatrix(), |
516 &fViewMatrixUniform); | 516 &fViewMatrixUniform); |
517 | 517 |
518 // emit transforms | 518 // emit transforms |
519 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, | 519 this->emitTransforms(pb, gpArgs->fPositionVar, dfTexEffect.inPosition()-
>fName, |
520 args.fTransformsIn, args.fTransformsOut); | 520 args.fTransformsIn, args.fTransformsOut); |
521 | 521 |
522 // set up varyings | 522 // set up varyings |
523 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); | 523 bool isUniformScale = SkToBool(dfTexEffect.getFlags() & kUniformScale_Di
stanceFieldEffectMask); |
524 GrGLVertToFrag recipScale(kFloat_GrSLType); | 524 GrGLSLVertToFrag recipScale(kFloat_GrSLType); |
525 GrGLVertToFrag st(kVec2f_GrSLType); | 525 GrGLSLVertToFrag st(kVec2f_GrSLType); |
526 pb->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); | 526 pb->addVarying("IntTextureCoords", &st, kHigh_GrSLPrecision); |
527 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); | 527 vsBuilder->codeAppendf("%s = %s;", st.vsOut(), dfTexEffect.inTextureCoor
ds()->fName); |
528 | 528 |
529 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 529 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
530 SkASSERT(dfTexEffect.numTextures() == 1); | 530 SkASSERT(dfTexEffect.numTextures() == 1); |
531 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); | 531 GrTexture* atlas = dfTexEffect.textureAccess(0).getTexture(); |
532 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 532 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
533 SkScalar recipWidth = 1.0f / atlas->width(); | 533 SkScalar recipWidth = 1.0f / atlas->width(); |
534 SkScalar recipHeight = 1.0f / atlas->height(); | 534 SkScalar recipHeight = 1.0f / atlas->height(); |
535 | 535 |
536 GrGLVertToFrag uv(kVec2f_GrSLType); | 536 GrGLSLVertToFrag uv(kVec2f_GrSLType); |
537 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); | 537 pb->addVarying("TextureCoords", &uv, kHigh_GrSLPrecision); |
538 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), | 538 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", uv.vsOut(), |
539 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, | 539 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |
540 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 540 GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |
541 dfTexEffect.inTextureCoords()->fName); | 541 dfTexEffect.inTextureCoords()->fName); |
542 | 542 |
543 // add frag shader code | 543 // add frag shader code |
544 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 544 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
545 | 545 |
546 SkAssertResult(fsBuilder->enableFeature( | 546 SkAssertResult(fsBuilder->enableFeature( |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; | 751 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; |
752 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; | 752 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; |
753 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; | 753 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; |
754 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), | 754 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), |
755 GrTest::TestMatrix(d->fRandom), | 755 GrTest::TestMatrix(d->fRandom), |
756 d->fTextures[texIdx], params, | 756 d->fTextures[texIdx], params, |
757 wa, | 757 wa, |
758 flags, | 758 flags, |
759 d->fRandom->nextBool()); | 759 d->fRandom->nextBool()); |
760 } | 760 } |
OLD | NEW |