| 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 "GrOvalEffect.h" | 8 #include "GrOvalEffect.h" |
| 9 | 9 |
| 10 #include "GrFragmentProcessor.h" | 10 #include "GrFragmentProcessor.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 SkScalar fPrevRadius; | 108 SkScalar fPrevRadius; |
| 109 | 109 |
| 110 typedef GrGLSLFragmentProcessor INHERITED; | 110 typedef GrGLSLFragmentProcessor INHERITED; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 void GLCircleEffect::emitCode(EmitArgs& args) { | 113 void GLCircleEffect::emitCode(EmitArgs& args) { |
| 114 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); | 114 const CircleEffect& ce = args.fFp.cast<CircleEffect>(); |
| 115 const char *circleName; | 115 const char *circleName; |
| 116 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0.
5)) for regular | 116 // The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0.
5)) for regular |
| 117 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills. | 117 // fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills. |
| 118 fCircleUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFra
gment_Visibility, | 118 fCircleUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, |
| 119 kVec4f_GrSLType, kDefault_
GrSLPrecision, | 119 kVec4f_GrSLType, kDefault_
GrSLPrecision, |
| 120 "circle", | 120 "circle", |
| 121 &circleName); | 121 &circleName); |
| 122 | 122 |
| 123 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 123 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 124 const char* fragmentPos = fragBuilder->fragmentPosition(); | 124 const char* fragmentPos = fragBuilder->fragmentPosition(); |
| 125 | 125 |
| 126 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); | 126 SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType()); |
| 127 // TODO: Right now the distance to circle caclulation is performed in a spac
e normalized to the | 127 // TODO: Right now the distance to circle caclulation is performed in a spac
e normalized to the |
| 128 // radius and then denormalized. This is to prevent overflow on devices that
have a "real" | 128 // radius and then denormalized. This is to prevent overflow on devices that
have a "real" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 SkVector fPrevRadii; | 279 SkVector fPrevRadii; |
| 280 | 280 |
| 281 typedef GrGLSLFragmentProcessor INHERITED; | 281 typedef GrGLSLFragmentProcessor INHERITED; |
| 282 }; | 282 }; |
| 283 | 283 |
| 284 void GLEllipseEffect::emitCode(EmitArgs& args) { | 284 void GLEllipseEffect::emitCode(EmitArgs& args) { |
| 285 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>(); | 285 const EllipseEffect& ee = args.fFp.cast<EllipseEffect>(); |
| 286 const char *ellipseName; | 286 const char *ellipseName; |
| 287 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) | 287 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) |
| 288 // The last two terms can underflow on mediump, so we use highp. | 288 // The last two terms can underflow on mediump, so we use highp. |
| 289 fEllipseUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFr
agment_Visibility, | 289 fEllipseUniform = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, |
| 290 kVec4f_GrSLType, kHigh_Gr
SLPrecision, | 290 kVec4f_GrSLType, kHigh_Gr
SLPrecision, |
| 291 "ellipse", | 291 "ellipse", |
| 292 &ellipseName); | 292 &ellipseName); |
| 293 // If we're on a device with a "real" mediump then we'll do the distance com
putation in a space | 293 // If we're on a device with a "real" mediump then we'll do the distance com
putation in a space |
| 294 // that is normalized by the larger radius. The scale uniform will be scale,
1/scale. The | 294 // that is normalized by the larger radius. The scale uniform will be scale,
1/scale. The |
| 295 // inverse squared radii uniform values are already in this normalized space
. The center is | 295 // inverse squared radii uniform values are already in this normalized space
. The center is |
| 296 // not. | 296 // not. |
| 297 const char* scaleName = nullptr; | 297 const char* scaleName = nullptr; |
| 298 if (args.fGLSLCaps->floatPrecisionVaries()) { | 298 if (args.fGLSLCaps->floatPrecisionVaries()) { |
| 299 fScaleUniform = args.fUniformHandler->addUniform( | 299 fScaleUniform = args.fUniformHandler->addUniform( |
| 300 GrGLSLUniformHandler::kFragment_Visibility, kVec2f_GrSLType, kDefaul
t_GrSLPrecision, | 300 kFragment_GrShaderFlag, kVec2f_GrSLType, kDefault_GrSLPrecision, |
| 301 "scale", &scaleName); | 301 "scale", &scaleName); |
| 302 } | 302 } |
| 303 | 303 |
| 304 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 304 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 305 const char* fragmentPos = fragBuilder->fragmentPosition(); | 305 const char* fragmentPos = fragBuilder->fragmentPosition(); |
| 306 | 306 |
| 307 // d is the offset to the ellipse center | 307 // d is the offset to the ellipse center |
| 308 fragBuilder->codeAppendf("vec2 d = %s.xy - %s.xy;", fragmentPos, ellipseName
); | 308 fragBuilder->codeAppendf("vec2 d = %s.xy - %s.xy;", fragmentPos, ellipseName
); |
| 309 if (scaleName) { | 309 if (scaleName) { |
| 310 fragBuilder->codeAppendf("d *= %s.y;", scaleName); | 310 fragBuilder->codeAppendf("d *= %s.y;", scaleName); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 w /= 2; | 401 w /= 2; |
| 402 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 402 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
| 403 } else { | 403 } else { |
| 404 w /= 2; | 404 w /= 2; |
| 405 h /= 2; | 405 h /= 2; |
| 406 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 406 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
| 407 } | 407 } |
| 408 | 408 |
| 409 return nullptr; | 409 return nullptr; |
| 410 } | 410 } |
| OLD | NEW |