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 "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // The circle uniform is (center.x, center.y, radius + 0.5) for regular fill
s and | 140 // The circle uniform is (center.x, center.y, radius + 0.5) for regular fill
s and |
141 // (... ,radius - 0.5) for inverse fills. | 141 // (... ,radius - 0.5) for inverse fills. |
142 fCircleUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, | 142 fCircleUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, |
143 kVec3f_GrSLType, | 143 kVec3f_GrSLType, |
144 "circle", | 144 "circle", |
145 &circleName); | 145 &circleName); |
146 const char* fragmentPos = builder->fragmentPosition(); | 146 const char* fragmentPos = builder->fragmentPosition(); |
147 | 147 |
148 SkASSERT(kHairlineAA_GrEffectEdgeType != ce.getEdgeType()); | 148 SkASSERT(kHairlineAA_GrEffectEdgeType != ce.getEdgeType()); |
149 if (GrEffectEdgeTypeIsInverseFill(ce.getEdgeType())) { | 149 if (GrEffectEdgeTypeIsInverseFill(ce.getEdgeType())) { |
150 builder->fsCodeAppendf("\t\tfloat d = length(%s.xy - %s.xy) - %s.z;\n", | 150 builder->fsCodeAppendf("\t\tfloat d = length(%s.xy - %s) - %s.z;\n", |
151 circleName, fragmentPos, circleName); | 151 circleName, fragmentPos, circleName); |
152 } else { | 152 } else { |
153 builder->fsCodeAppendf("\t\tfloat d = %s.z - length(%s.xy - %s.xy);\n", | 153 builder->fsCodeAppendf("\t\tfloat d = %s.z - length(%s - %s.xy);\n", |
154 circleName, fragmentPos, circleName); | 154 circleName, fragmentPos, circleName); |
155 } | 155 } |
156 if (GrEffectEdgeTypeIsAA(ce.getEdgeType())) { | 156 if (GrEffectEdgeTypeIsAA(ce.getEdgeType())) { |
157 builder->fsCodeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); | 157 builder->fsCodeAppend("\t\td = clamp(d, 0.0, 1.0);\n"); |
158 } else { | 158 } else { |
159 builder->fsCodeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); | 159 builder->fsCodeAppend("\t\td = d > 0.5 ? 1.0 : 0.0;\n"); |
160 } | 160 } |
161 | 161 |
162 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 162 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
163 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str())
; | 163 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("d")).c_str())
; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); | 311 const EllipseEffect& ee = drawEffect.castEffect<EllipseEffect>(); |
312 const char *ellipseName; | 312 const char *ellipseName; |
313 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) | 313 // The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2) |
314 fEllipseUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibilit
y, | 314 fEllipseUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibilit
y, |
315 kVec4f_GrSLType, | 315 kVec4f_GrSLType, |
316 "ellipse", | 316 "ellipse", |
317 &ellipseName); | 317 &ellipseName); |
318 const char* fragmentPos = builder->fragmentPosition(); | 318 const char* fragmentPos = builder->fragmentPosition(); |
319 | 319 |
320 // d is the offset to the ellipse center | 320 // d is the offset to the ellipse center |
321 builder->fsCodeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse
Name); | 321 builder->fsCodeAppendf("\t\tvec2 d = %s - %s.xy;\n", fragmentPos, ellipseNam
e); |
322 builder->fsCodeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); | 322 builder->fsCodeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); |
323 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. | 323 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. |
324 builder->fsCodeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); | 324 builder->fsCodeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); |
325 // grad_dot is the squared length of the gradient of the implicit. | 325 // grad_dot is the squared length of the gradient of the implicit. |
326 builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); | 326 builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); |
327 // avoid calling inversesqrt on zero. | 327 // avoid calling inversesqrt on zero. |
328 builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); | 328 builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); |
329 builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_
dot);\n"); | 329 builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_
dot);\n"); |
330 | 330 |
331 switch (ee.getEdgeType()) { | 331 switch (ee.getEdgeType()) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 w /= 2; | 378 w /= 2; |
379 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 379 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
380 } else { | 380 } else { |
381 w /= 2; | 381 w /= 2; |
382 h /= 2; | 382 h /= 2; |
383 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 383 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
384 } | 384 } |
385 | 385 |
386 return NULL; | 386 return NULL; |
387 } | 387 } |
OLD | NEW |