| 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 "GrConvexPolyEffect.h" | 10 #include "GrConvexPolyEffect.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 // If we're on a device with a "real" mediump then the length calculation co
uld overflow. | 169 // If we're on a device with a "real" mediump then the length calculation co
uld overflow. |
| 170 SkString clampedCircleDistance; | 170 SkString clampedCircleDistance; |
| 171 if (args.fGLSLCaps->floatPrecisionVaries()) { | 171 if (args.fGLSLCaps->floatPrecisionVaries()) { |
| 172 clampedCircleDistance.printf("clamp(%s.x * (1.0 - length(dxy * %s.y)), 0
.0, 1.0);", | 172 clampedCircleDistance.printf("clamp(%s.x * (1.0 - length(dxy * %s.y)), 0
.0, 1.0);", |
| 173 radiusPlusHalfName, radiusPlusHalfName); | 173 radiusPlusHalfName, radiusPlusHalfName); |
| 174 } else { | 174 } else { |
| 175 clampedCircleDistance.printf("clamp(%s.x - length(dxy), 0.0, 1.0);", rad
iusPlusHalfName); | 175 clampedCircleDistance.printf("clamp(%s.x - length(dxy), 0.0, 1.0);", rad
iusPlusHalfName); |
| 176 } | 176 } |
| 177 | 177 |
| 178 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 178 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 179 const char* fragmentPos = fragBuilder->fragmentPosition(); | 179 const char* fragmentPos = fragBuilder->fragmentPosition(); |
| 180 // At each quarter-circle corner we compute a vector that is the offset of t
he fragment position | 180 // At each quarter-circle corner we compute a vector that is the offset of t
he fragment position |
| 181 // from the circle center. The vector is pinned in x and y to be in the quar
ter-plane relevant | 181 // from the circle center. The vector is pinned in x and y to be in the quar
ter-plane relevant |
| 182 // to that corner. This means that points near the interior near the rrect t
op edge will have | 182 // to that corner. This means that points near the interior near the rrect t
op edge will have |
| 183 // a vector that points straight up for both the TL left and TR corners. Com
puting an | 183 // a vector that points straight up for both the TL left and TR corners. Com
puting an |
| 184 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, | 184 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, |
| 185 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of | 185 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of |
| 186 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dius > 0.5 they will | 186 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dius > 0.5 they will |
| 187 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. | 187 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. |
| 188 // The code below is a simplified version of the above that performs maxs on
the vector | 188 // The code below is a simplified version of the above that performs maxs on
the vector |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { | 506 void GLEllipticalRRectEffect::emitCode(EmitArgs& args) { |
| 507 const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); | 507 const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>(); |
| 508 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 508 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 509 const char *rectName; | 509 const char *rectName; |
| 510 // The inner rect is the rrect bounds inset by the x/y radii | 510 // The inner rect is the rrect bounds inset by the x/y radii |
| 511 fInnerRectUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, | 511 fInnerRectUniform = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 512 kVec4f_GrSLType, kDefault_GrS
LPrecision, | 512 kVec4f_GrSLType, kDefault_GrS
LPrecision, |
| 513 "innerRect", | 513 "innerRect", |
| 514 &rectName); | 514 &rectName); |
| 515 | 515 |
| 516 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 516 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 517 const char* fragmentPos = fragBuilder->fragmentPosition(); | 517 const char* fragmentPos = fragBuilder->fragmentPosition(); |
| 518 // At each quarter-ellipse corner we compute a vector that is the offset of
the fragment pos | 518 // At each quarter-ellipse corner we compute a vector that is the offset of
the fragment pos |
| 519 // to the ellipse center. The vector is pinned in x and y to be in the quart
er-plane relevant | 519 // to the ellipse center. The vector is pinned in x and y to be in the quart
er-plane relevant |
| 520 // to that corner. This means that points near the interior near the rrect t
op edge will have | 520 // to that corner. This means that points near the interior near the rrect t
op edge will have |
| 521 // a vector that points straight up for both the TL left and TR corners. Com
puting an | 521 // a vector that points straight up for both the TL left and TR corners. Com
puting an |
| 522 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, | 522 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, |
| 523 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of | 523 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of |
| 524 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dii > 0.5 they will | 524 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dii > 0.5 they will |
| 525 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. | 525 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. |
| 526 // | 526 // |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 if (rrect.isNinePatch()) { | 769 if (rrect.isNinePatch()) { |
| 770 return EllipticalRRectEffect::Create(edgeType, rrect); | 770 return EllipticalRRectEffect::Create(edgeType, rrect); |
| 771 } | 771 } |
| 772 return nullptr; | 772 return nullptr; |
| 773 } | 773 } |
| 774 } | 774 } |
| 775 } | 775 } |
| 776 | 776 |
| 777 return nullptr; | 777 return nullptr; |
| 778 } | 778 } |
| OLD | NEW |