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 "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
9 | 9 |
10 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 10 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 fragBuilder->declAppend(dklmdx); | 129 fragBuilder->declAppend(dklmdx); |
130 fragBuilder->declAppend(dklmdy); | 130 fragBuilder->declAppend(dklmdy); |
131 fragBuilder->declAppend(dfdx); | 131 fragBuilder->declAppend(dfdx); |
132 fragBuilder->declAppend(dfdy); | 132 fragBuilder->declAppend(dfdy); |
133 fragBuilder->declAppend(gF); | 133 fragBuilder->declAppend(gF); |
134 fragBuilder->declAppend(gFM); | 134 fragBuilder->declAppend(gFM); |
135 fragBuilder->declAppend(func); | 135 fragBuilder->declAppend(func); |
136 | 136 |
137 switch (fEdgeType) { | 137 switch (fEdgeType) { |
138 case kHairlineAA_GrProcessorEdgeType: { | 138 case kHairlineAA_GrProcessorEdgeType: { |
139 SkAssertResult(fragBuilder->enableFeature( | |
140 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | |
141 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); | 139 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); |
142 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); | 140 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); |
143 fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.
z * %s.y;", | 141 fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.
z * %s.y;", |
144 dfdx.c_str(), | 142 dfdx.c_str(), |
145 v.fsIn(), dklmdx.c_str(), | 143 v.fsIn(), dklmdx.c_str(), |
146 v.fsIn(), dklmdx.c_str(), | 144 v.fsIn(), dklmdx.c_str(), |
147 v.fsIn(), dklmdx.c_str()); | 145 v.fsIn(), dklmdx.c_str()); |
148 fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.
z * %s.y;", | 146 fragBuilder->codeAppendf("%s = 2.0 * %s.x * %s.x - %s.y * %s.z - %s.
z * %s.y;", |
149 dfdy.c_str(), | 147 dfdy.c_str(), |
150 v.fsIn(), dklmdy.c_str(), | 148 v.fsIn(), dklmdy.c_str(), |
151 v.fsIn(), dklmdy.c_str(), | 149 v.fsIn(), dklmdy.c_str(), |
152 v.fsIn(), dklmdy.c_str()); | 150 v.fsIn(), dklmdy.c_str()); |
153 fragBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_st
r(), dfdy.c_str()); | 151 fragBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_st
r(), dfdy.c_str()); |
154 fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", | 152 fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", |
155 gFM.c_str(), gF.c_str(), gF.c_str()); | 153 gFM.c_str(), gF.c_str(), gF.c_str()); |
156 fragBuilder->codeAppendf("%s = %s.x*%s.x - %s.y*%s.z;", | 154 fragBuilder->codeAppendf("%s = %s.x*%s.x - %s.y*%s.z;", |
157 func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(),
v.fsIn()); | 155 func.c_str(), v.fsIn(), v.fsIn(), v.fsIn(),
v.fsIn()); |
158 fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()
); | 156 fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()
); |
159 fragBuilder->codeAppendf("%s = %s / %s;", | 157 fragBuilder->codeAppendf("%s = %s / %s;", |
160 edgeAlpha.c_str(), func.c_str(), gFM.c_str(
)); | 158 edgeAlpha.c_str(), func.c_str(), gFM.c_str(
)); |
161 fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", | 159 fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", |
162 edgeAlpha.c_str(), edgeAlpha.c_str()); | 160 edgeAlpha.c_str(), edgeAlpha.c_str()); |
163 // Add line below for smooth cubic ramp | 161 // Add line below for smooth cubic ramp |
164 // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0
*edgeAlpha);"); | 162 // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0
*edgeAlpha);"); |
165 break; | 163 break; |
166 } | 164 } |
167 case kFillAA_GrProcessorEdgeType: { | 165 case kFillAA_GrProcessorEdgeType: { |
168 SkAssertResult(fragBuilder->enableFeature( | |
169 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | |
170 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); | 166 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); |
171 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); | 167 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); |
172 fragBuilder->codeAppendf("%s =" | 168 fragBuilder->codeAppendf("%s =" |
173 "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %
s.y;", | 169 "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %
s.y;", |
174 dfdx.c_str(), | 170 dfdx.c_str(), |
175 v.fsIn(), dklmdx.c_str(), | 171 v.fsIn(), dklmdx.c_str(), |
176 v.fsIn(), dklmdx.c_str(), | 172 v.fsIn(), dklmdx.c_str(), |
177 v.fsIn(), dklmdx.c_str()); | 173 v.fsIn(), dklmdx.c_str()); |
178 fragBuilder->codeAppendf("%s =" | 174 fragBuilder->codeAppendf("%s =" |
179 "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %
s.y;", | 175 "2.0 * %s.x * %s.x - %s.y * %s.z - %s.z * %
s.y;", |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 uniformHandler, | 363 uniformHandler, |
368 gpArgs->fPositionVar, | 364 gpArgs->fPositionVar, |
369 gp.inPosition()->fName, | 365 gp.inPosition()->fName, |
370 gp.localMatrix(), | 366 gp.localMatrix(), |
371 args.fFPCoordTransformHandler); | 367 args.fFPCoordTransformHandler); |
372 | 368 |
373 fragBuilder->codeAppendf("float edgeAlpha;"); | 369 fragBuilder->codeAppendf("float edgeAlpha;"); |
374 | 370 |
375 switch (fEdgeType) { | 371 switch (fEdgeType) { |
376 case kHairlineAA_GrProcessorEdgeType: { | 372 case kHairlineAA_GrProcessorEdgeType: { |
377 SkAssertResult(fragBuilder->enableFeature( | |
378 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | |
379 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); | 373 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
380 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); | 374 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
381 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," | 375 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," |
382 " 2.0 * %s.x * duvdy.x - duvd
y.y);", | 376 " 2.0 * %s.x * duvdy.x - duvd
y.y);", |
383 v.fsIn(), v.fsIn()); | 377 v.fsIn(), v.fsIn()); |
384 fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", | 378 fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", |
385 v.fsIn(), v.fsIn(), v.fsIn()); | 379 v.fsIn(), v.fsIn(), v.fsIn()); |
386 fragBuilder->codeAppend("edgeAlpha = sqrt(edgeAlpha * edgeAlpha / do
t(gF, gF));"); | 380 fragBuilder->codeAppend("edgeAlpha = sqrt(edgeAlpha * edgeAlpha / do
t(gF, gF));"); |
387 fragBuilder->codeAppend("edgeAlpha = max(1.0 - edgeAlpha, 0.0);"); | 381 fragBuilder->codeAppend("edgeAlpha = max(1.0 - edgeAlpha, 0.0);"); |
388 // Add line below for smooth cubic ramp | 382 // Add line below for smooth cubic ramp |
389 // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0
*edgeAlpha);"); | 383 // fragBuilder->codeAppend("edgeAlpha = edgeAlpha*edgeAlpha*(3.0-2.0
*edgeAlpha);"); |
390 break; | 384 break; |
391 } | 385 } |
392 case kFillAA_GrProcessorEdgeType: { | 386 case kFillAA_GrProcessorEdgeType: { |
393 SkAssertResult(fragBuilder->enableFeature( | |
394 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | |
395 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); | 387 fragBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn()); |
396 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); | 388 fragBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn()); |
397 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," | 389 fragBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvd
x.y," |
398 " 2.0 * %s.x * duvdy.x - duvd
y.y);", | 390 " 2.0 * %s.x * duvdy.x - duvd
y.y);", |
399 v.fsIn(), v.fsIn()); | 391 v.fsIn(), v.fsIn()); |
400 fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", | 392 fragBuilder->codeAppendf("edgeAlpha = (%s.x * %s.x - %s.y);", |
401 v.fsIn(), v.fsIn(), v.fsIn()); | 393 v.fsIn(), v.fsIn(), v.fsIn()); |
402 fragBuilder->codeAppend("edgeAlpha = edgeAlpha / sqrt(dot(gF, gF));"
); | 394 fragBuilder->codeAppend("edgeAlpha = edgeAlpha / sqrt(dot(gF, gF));"
); |
403 fragBuilder->codeAppend("edgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0
);"); | 395 fragBuilder->codeAppend("edgeAlpha = clamp(1.0 - edgeAlpha, 0.0, 1.0
);"); |
404 // Add line below for smooth cubic ramp | 396 // Add line below for smooth cubic ramp |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 fragBuilder->declAppend(dklmdx); | 577 fragBuilder->declAppend(dklmdx); |
586 fragBuilder->declAppend(dklmdy); | 578 fragBuilder->declAppend(dklmdy); |
587 fragBuilder->declAppend(dfdx); | 579 fragBuilder->declAppend(dfdx); |
588 fragBuilder->declAppend(dfdy); | 580 fragBuilder->declAppend(dfdy); |
589 fragBuilder->declAppend(gF); | 581 fragBuilder->declAppend(gF); |
590 fragBuilder->declAppend(gFM); | 582 fragBuilder->declAppend(gFM); |
591 fragBuilder->declAppend(func); | 583 fragBuilder->declAppend(func); |
592 | 584 |
593 switch (fEdgeType) { | 585 switch (fEdgeType) { |
594 case kHairlineAA_GrProcessorEdgeType: { | 586 case kHairlineAA_GrProcessorEdgeType: { |
595 SkAssertResult(fragBuilder->enableFeature( | |
596 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | |
597 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); | 587 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); |
598 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); | 588 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); |
599 fragBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.
z - %s.z * %s.y;", | 589 fragBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.
z - %s.z * %s.y;", |
600 dfdx.c_str(), v.fsIn(), v.fsIn(), dklmdx.c_
str(), v.fsIn(), | 590 dfdx.c_str(), v.fsIn(), v.fsIn(), dklmdx.c_
str(), v.fsIn(), |
601 dklmdx.c_str(), v.fsIn(), dklmdx.c_str()); | 591 dklmdx.c_str(), v.fsIn(), dklmdx.c_str()); |
602 fragBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.
z - %s.z * %s.y;", | 592 fragBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.
z - %s.z * %s.y;", |
603 dfdy.c_str(), v.fsIn(), v.fsIn(), dklmdy.c_
str(), v.fsIn(), | 593 dfdy.c_str(), v.fsIn(), v.fsIn(), dklmdy.c_
str(), v.fsIn(), |
604 dklmdy.c_str(), v.fsIn(), dklmdy.c_str()); | 594 dklmdy.c_str(), v.fsIn(), dklmdy.c_str()); |
605 fragBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_st
r(), dfdy.c_str()); | 595 fragBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_st
r(), dfdy.c_str()); |
606 fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", | 596 fragBuilder->codeAppendf("%s = sqrt(dot(%s, %s));", |
607 gFM.c_str(), gF.c_str(), gF.c_str()); | 597 gFM.c_str(), gF.c_str(), gF.c_str()); |
608 fragBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", | 598 fragBuilder->codeAppendf("%s = %s.x * %s.x * %s.x - %s.y * %s.z;", |
609 func.c_str(), v.fsIn(), v.fsIn(), | 599 func.c_str(), v.fsIn(), v.fsIn(), |
610 v.fsIn(), v.fsIn(), v.fsIn()); | 600 v.fsIn(), v.fsIn(), v.fsIn()); |
611 fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()
); | 601 fragBuilder->codeAppendf("%s = abs(%s);", func.c_str(), func.c_str()
); |
612 fragBuilder->codeAppendf("%s = %s / %s;", | 602 fragBuilder->codeAppendf("%s = %s / %s;", |
613 edgeAlpha.c_str(), func.c_str(), gFM.c_str(
)); | 603 edgeAlpha.c_str(), func.c_str(), gFM.c_str(
)); |
614 fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", | 604 fragBuilder->codeAppendf("%s = max(1.0 - %s, 0.0);", |
615 edgeAlpha.c_str(), edgeAlpha.c_str()); | 605 edgeAlpha.c_str(), edgeAlpha.c_str()); |
616 // Add line below for smooth cubic ramp | 606 // Add line below for smooth cubic ramp |
617 // fragBuilder->codeAppendf("%s = %s * %s * (3.0 - 2.0 * %s);", | 607 // fragBuilder->codeAppendf("%s = %s * %s * (3.0 - 2.0 * %s);", |
618 // edgeAlpha.c_str(), edgeAlpha.c_str(), edge
Alpha.c_str(), | 608 // edgeAlpha.c_str(), edgeAlpha.c_str(), edge
Alpha.c_str(), |
619 // edgeAlpha.c_str()); | 609 // edgeAlpha.c_str()); |
620 break; | 610 break; |
621 } | 611 } |
622 case kFillAA_GrProcessorEdgeType: { | 612 case kFillAA_GrProcessorEdgeType: { |
623 SkAssertResult(fragBuilder->enableFeature( | |
624 GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeatur
e)); | |
625 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); | 613 fragBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsI
n()); |
626 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); | 614 fragBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsI
n()); |
627 fragBuilder->codeAppendf("%s =" | 615 fragBuilder->codeAppendf("%s =" |
628 "3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %
s.z * %s.y;", | 616 "3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %
s.z * %s.y;", |
629 dfdx.c_str(), v.fsIn(), v.fsIn(), dklmdx.c_
str(), v.fsIn(), | 617 dfdx.c_str(), v.fsIn(), v.fsIn(), dklmdx.c_
str(), v.fsIn(), |
630 dklmdx.c_str(), v.fsIn(), dklmdx.c_str()); | 618 dklmdx.c_str(), v.fsIn(), dklmdx.c_str()); |
631 fragBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.
z - %s.z * %s.y;", | 619 fragBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.
z - %s.z * %s.y;", |
632 dfdy.c_str(), v.fsIn(), v.fsIn(), dklmdy.c_
str(), v.fsIn(), | 620 dfdy.c_str(), v.fsIn(), v.fsIn(), dklmdy.c_
str(), v.fsIn(), |
633 dklmdy.c_str(), v.fsIn(), dklmdy.c_str()); | 621 dklmdy.c_str(), v.fsIn(), dklmdy.c_str()); |
634 fragBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_st
r(), dfdy.c_str()); | 622 fragBuilder->codeAppendf("%s = vec2(%s, %s);", gF.c_str(), dfdx.c_st
r(), dfdy.c_str()); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 sk_sp<GrGeometryProcessor> gp; | 691 sk_sp<GrGeometryProcessor> gp; |
704 do { | 692 do { |
705 GrPrimitiveEdgeType edgeType = | 693 GrPrimitiveEdgeType edgeType = |
706 static_cast<GrPrimitiveEdgeType>( | 694 static_cast<GrPrimitiveEdgeType>( |
707 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 695 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
708 gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), | 696 gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), |
709 GrTest::TestMatrix(d->fRandom), edgeType, *d->f
Caps); | 697 GrTest::TestMatrix(d->fRandom), edgeType, *d->f
Caps); |
710 } while (nullptr == gp); | 698 } while (nullptr == gp); |
711 return gp; | 699 return gp; |
712 } | 700 } |
OLD | NEW |