Chromium Code Reviews| Index: src/utils/SkLua.cpp |
| diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp |
| index 98880d0154788501df0295da494409414e43dec8..8b5202447c716d957ef89e44d3d1098cf31f720e 100644 |
| --- a/src/utils/SkLua.cpp |
| +++ b/src/utils/SkLua.cpp |
| @@ -1267,26 +1267,33 @@ static int lshader_asAGradient(lua_State* L) { |
| if (shader) { |
| SkShader::GradientInfo info; |
| sk_bzero(&info, sizeof(info)); |
| + shader->asAGradient(&info); |
| - SkColor colors[3]; // hacked in for extracting info on 3 color case. |
| - SkScalar pos[3]; |
| - |
| - info.fColorCount = 3; |
| - info.fColors = &colors[0]; |
| - info.fColorOffsets = &pos[0]; |
| + SkAutoTArray<SkScalar> pos(info.fColorCount); |
|
reed1
2016/06/28 17:50:18
Can we move these two lines into the if, so we're
|
| + info.fColorOffsets = pos.get(); |
| SkShader::GradientType t = shader->asAGradient(&info); |
| if (SkShader::kNone_GradientType != t) { |
| lua_newtable(L); |
| - setfield_string(L, "type", gradtype2string(t)); |
| - setfield_number(L, "colorCount", info.fColorCount); |
| - setfield_string(L, "tile", mode2string(info.fTileMode)); |
| - if (info.fColorCount == 3){ |
| - setfield_number(L, "midPos", pos[1]); |
| + bool containsHardStops = false; |
| + bool isEvenlySpaced = true; |
| + for (int i = 1; i < info.fColorCount; i++) { |
| + if (SkScalarNearlyEqual(info.fColorOffsets[i], info.fColorOffsets[i-1])) { |
| + containsHardStops = true; |
| + } |
| + if (!SkScalarNearlyEqual(info.fColorOffsets[i], i/(info.fColorCount - 1.0f))) { |
| + isEvenlySpaced = false; |
| + } |
| } |
| + setfield_string(L, "type", gradtype2string(t)); |
| + setfield_string(L, "tile", mode2string(info.fTileMode)); |
| + setfield_number(L, "colorCount", info.fColorCount); |
| + setfield_boolean(L, "containsHardStops", containsHardStops); |
| + setfield_boolean(L, "isEvenlySpaced", isEvenlySpaced); |
| + |
|
reed1
2016/06/28 17:50:17
We're not pushing the actual t-values into a table
|
| return 1; |
| } |
| } |