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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 &ellipseName); | 310 &ellipseName); |
311 const char* fragmentPos = builder->fragmentPosition(); | 311 const char* fragmentPos = builder->fragmentPosition(); |
312 | 312 |
313 // d is the offset to the ellipse center | 313 // d is the offset to the ellipse center |
314 builder->fsCodeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse
Name); | 314 builder->fsCodeAppendf("\t\tvec2 d = %s.xy - %s.xy;\n", fragmentPos, ellipse
Name); |
315 builder->fsCodeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); | 315 builder->fsCodeAppendf("\t\tvec2 Z = d * %s.zw;\n", ellipseName); |
316 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. | 316 // implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. |
317 builder->fsCodeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); | 317 builder->fsCodeAppend("\t\tfloat implicit = dot(Z, d) - 1.0;\n"); |
318 // grad_dot is the squared length of the gradient of the implicit. | 318 // grad_dot is the squared length of the gradient of the implicit. |
319 builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); | 319 builder->fsCodeAppendf("\t\tfloat grad_dot = 4.0 * dot(Z, Z);\n"); |
320 if (builder->ctxInfo().caps()->dropsTileOnZeroDivide()) { | 320 // avoid calling inversesqrt on zero. |
321 builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); | 321 builder->fsCodeAppend("\t\tgrad_dot = max(grad_dot, 1.0e-4);\n"); |
322 } | |
323 builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_
dot);\n"); | 322 builder->fsCodeAppendf("\t\tfloat approx_dist = implicit * inversesqrt(grad_
dot);\n"); |
324 | 323 |
325 switch (ee.getEdgeType()) { | 324 switch (ee.getEdgeType()) { |
326 case kFillAA_GrEffectEdgeType: | 325 case kFillAA_GrEffectEdgeType: |
327 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.
0, 1.0);\n"); | 326 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 - approx_dist, 0.
0, 1.0);\n"); |
328 break; | 327 break; |
329 case kInverseFillAA_GrEffectEdgeType: | 328 case kInverseFillAA_GrEffectEdgeType: |
330 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.
0, 1.0);\n"); | 329 builder->fsCodeAppend("\t\tfloat alpha = clamp(0.5 + approx_dist, 0.
0, 1.0);\n"); |
331 break; | 330 break; |
332 case kFillBW_GrEffectEdgeType: | 331 case kFillBW_GrEffectEdgeType: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 w /= 2; | 371 w /= 2; |
373 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); | 372 return CircleEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, oval
.fTop + w), w); |
374 } else { | 373 } else { |
375 w /= 2; | 374 w /= 2; |
376 h /= 2; | 375 h /= 2; |
377 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); | 376 return EllipseEffect::Create(edgeType, SkPoint::Make(oval.fLeft + w, ova
l.fTop + h), w, h); |
378 } | 377 } |
379 | 378 |
380 return NULL; | 379 return NULL; |
381 } | 380 } |
OLD | NEW |