| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrAAConvexPathRenderer.h" | 9 #include "GrAAConvexPathRenderer.h" |
| 10 | 10 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 bool usesLocalCoords() const { return fUsesLocalCoords; } | 542 bool usesLocalCoords() const { return fUsesLocalCoords; } |
| 543 | 543 |
| 544 class GLSLProcessor : public GrGLSLGeometryProcessor { | 544 class GLSLProcessor : public GrGLSLGeometryProcessor { |
| 545 public: | 545 public: |
| 546 GLSLProcessor() | 546 GLSLProcessor() |
| 547 : fColor(GrColor_ILLEGAL) {} | 547 : fColor(GrColor_ILLEGAL) {} |
| 548 | 548 |
| 549 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 549 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 550 const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); | 550 const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); |
| 551 GrGLSLGPBuilder* pb = args.fPB; | 551 GrGLSLGPBuilder* pb = args.fPB; |
| 552 GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 552 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 553 | 553 |
| 554 // emit attributes | 554 // emit attributes |
| 555 vsBuilder->emitAttributes(qe); | 555 vertBuilder->emitAttributes(qe); |
| 556 | 556 |
| 557 GrGLSLVertToFrag v(kVec4f_GrSLType); | 557 GrGLSLVertToFrag v(kVec4f_GrSLType); |
| 558 args.fPB->addVarying("QuadEdge", &v); | 558 args.fPB->addVarying("QuadEdge", &v); |
| 559 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.inQuadEdge()->fName
); | 559 vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.inQuadEdge()->fNa
me); |
| 560 | 560 |
| 561 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 561 // Setup pass through color | 562 // Setup pass through color |
| 562 if (!qe.colorIgnored()) { | 563 if (!qe.colorIgnored()) { |
| 563 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 564 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo
lorUniform); |
| 564 } | 565 } |
| 565 | 566 |
| 566 // Setup position | 567 // Setup position |
| 567 this->setupPosition(pb, gpArgs, qe.inPosition()->fName); | 568 this->setupPosition(pb, vertBuilder, gpArgs, qe.inPosition()->fName)
; |
| 568 | 569 |
| 569 // emit transforms | 570 // emit transforms |
| 570 this->emitTransforms(args.fPB, gpArgs->fPositionVar, qe.inPosition()
->fName, | 571 this->emitTransforms(args.fPB, |
| 571 qe.localMatrix(), args.fTransformsIn, args.fTra
nsformsOut); | 572 vertBuilder, |
| 573 gpArgs->fPositionVar, |
| 574 qe.inPosition()->fName, |
| 575 qe.localMatrix(), |
| 576 args.fTransformsIn, |
| 577 args.fTransformsOut); |
| 572 | 578 |
| 573 GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde
r(); | 579 SkAssertResult(fragBuilder->enableFeature( |
| 574 | |
| 575 SkAssertResult(fsBuilder->enableFeature( | |
| 576 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | 580 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); |
| 577 fsBuilder->codeAppendf("float edgeAlpha;"); | 581 fragBuilder->codeAppendf("float edgeAlpha;"); |
| 578 | 582 |
| 579 // keep the derivative instructions outside the conditional | 583 // keep the derivative instructions outside the conditional |
| 580 fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); | 584 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
| 581 fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); | 585 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
| 582 fsBuilder->codeAppendf("if (%s.z > 0.0 && %s.w > 0.0) {", v.fsIn(),
v.fsIn()); | 586 fragBuilder->codeAppendf("if (%s.z > 0.0 && %s.w > 0.0) {", v.fsIn()
, v.fsIn()); |
| 583 // today we know z and w are in device space. We could use derivativ
es | 587 // today we know z and w are in device space. We could use derivativ
es |
| 584 fsBuilder->codeAppendf("edgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);
", v.fsIn(), | 588 fragBuilder->codeAppendf("edgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0
);", v.fsIn(), |
| 585 v.fsIn()); | 589 v.fsIn()); |
| 586 fsBuilder->codeAppendf ("} else {"); | 590 fragBuilder->codeAppendf ("} else {"); |
| 587 fsBuilder->codeAppendf("vec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y," | 591 fragBuilder->codeAppendf("vec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,
" |
| 588 " 2.0*%s.x*duvdy.x - duvdy.y);"
, | 592 " 2.0*%s.x*duvdy.x - duvdy.y)
;", |
| 589 v.fsIn(), v.fsIn()); | 593 v.fsIn(), v.fsIn()); |
| 590 fsBuilder->codeAppendf("edgeAlpha = (%s.x*%s.x - %s.y);", v.fsIn(),
v.fsIn(), | 594 fragBuilder->codeAppendf("edgeAlpha = (%s.x*%s.x - %s.y);", v.fsIn()
, v.fsIn(), |
| 591 v.fsIn()); | 595 v.fsIn()); |
| 592 fsBuilder->codeAppendf("edgeAlpha = " | 596 fragBuilder->codeAppendf("edgeAlpha = " |
| 593 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);}"); | 597 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1
.0);}"); |
| 594 | 598 |
| 595 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 599 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); |
| 596 } | 600 } |
| 597 | 601 |
| 598 static inline void GenKey(const GrGeometryProcessor& gp, | 602 static inline void GenKey(const GrGeometryProcessor& gp, |
| 599 const GrGLSLCaps&, | 603 const GrGLSLCaps&, |
| 600 GrProcessorKeyBuilder* b) { | 604 GrProcessorKeyBuilder* b) { |
| 601 const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>(); | 605 const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>(); |
| 602 uint32_t key = 0; | 606 uint32_t key = 0; |
| 603 key |= qee.usesLocalCoords() && qee.localMatrix().hasPerspective() ?
0x1 : 0x0; | 607 key |= qee.usesLocalCoords() && qee.localMatrix().hasPerspective() ?
0x1 : 0x0; |
| 604 key |= qee.colorIgnored() ? 0x2 : 0x0; | 608 key |= qee.colorIgnored() ? 0x2 : 0x0; |
| 605 b->add32(key); | 609 b->add32(key); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { | 1011 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { |
| 1008 AAConvexPathBatch::Geometry geometry; | 1012 AAConvexPathBatch::Geometry geometry; |
| 1009 geometry.fColor = GrRandomColor(random); | 1013 geometry.fColor = GrRandomColor(random); |
| 1010 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 1014 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
| 1011 geometry.fPath = GrTest::TestPathConvex(random); | 1015 geometry.fPath = GrTest::TestPathConvex(random); |
| 1012 | 1016 |
| 1013 return AAConvexPathBatch::Create(geometry); | 1017 return AAConvexPathBatch::Create(geometry); |
| 1014 } | 1018 } |
| 1015 | 1019 |
| 1016 #endif | 1020 #endif |
| OLD | NEW |