OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrRRectEffect.h" | 8 #include "GrRRectEffect.h" |
9 | 9 |
10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 invRadiiLTRBSqdName, invRadiiLTRBSqdName); | 565 invRadiiLTRBSqdName, invRadiiLTRBSqdName); |
566 break; | 566 break; |
567 } | 567 } |
568 default: | 568 default: |
569 GrCrash("RRect should always be simple or nine-patch."); | 569 GrCrash("RRect should always be simple or nine-patch."); |
570 } | 570 } |
571 // implicit is the evaluation of (x/a)^2 + (y/b)^2 - 1. | 571 // implicit is the evaluation of (x/a)^2 + (y/b)^2 - 1. |
572 builder->fsCodeAppend("\t\tfloat implicit = dot(Z, dxy) - 1.0;\n"); | 572 builder->fsCodeAppend("\t\tfloat implicit = dot(Z, dxy) - 1.0;\n"); |
573 // grad_dot is the squared length of the gradient of the implicit. | 573 // grad_dot is the squared length of the gradient of the implicit. |
574 builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); | 574 builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); |
575 builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); | 575 if (builder->ctxInfo().caps()->dropsTileOnZeroDivide()) { |
| 576 builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); |
| 577 } |
576 builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_
dot);\n"); | 578 builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_
dot);\n"); |
577 | 579 |
578 if (kFillAA_GrEffectEdgeType == erre.getEdgeType()) { | 580 if (kFillAA_GrEffectEdgeType == erre.getEdgeType()) { |
579 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.0, 1
.0);\n"); | 581 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.0, 1
.0);\n"); |
580 } else { | 582 } else { |
581 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.0, 1
.0);\n"); | 583 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.0, 1
.0);\n"); |
582 } | 584 } |
583 | 585 |
584 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 586 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
585 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); | 587 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st
r()); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 if (rrect.isNinePatch()) { | 722 if (rrect.isNinePatch()) { |
721 return EllipticalRRectEffect::Create(edgeType, rrect); | 723 return EllipticalRRectEffect::Create(edgeType, rrect); |
722 } | 724 } |
723 return NULL; | 725 return NULL; |
724 } | 726 } |
725 } | 727 } |
726 } | 728 } |
727 | 729 |
728 return NULL; | 730 return NULL; |
729 } | 731 } |
OLD | NEW |