Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkLua.h" | 8 #include "SkLua.h" |
| 9 | 9 |
| 10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| (...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 } | 1260 } |
| 1261 } | 1261 } |
| 1262 return 0; | 1262 return 0; |
| 1263 } | 1263 } |
| 1264 | 1264 |
| 1265 static int lshader_asAGradient(lua_State* L) { | 1265 static int lshader_asAGradient(lua_State* L) { |
| 1266 SkShader* shader = get_ref<SkShader>(L, 1); | 1266 SkShader* shader = get_ref<SkShader>(L, 1); |
| 1267 if (shader) { | 1267 if (shader) { |
| 1268 SkShader::GradientInfo info; | 1268 SkShader::GradientInfo info; |
| 1269 sk_bzero(&info, sizeof(info)); | 1269 sk_bzero(&info, sizeof(info)); |
| 1270 shader->asAGradient(&info); | |
| 1270 | 1271 |
| 1271 SkColor colors[3]; // hacked in for extracting info on 3 color case. | 1272 SkAutoTArray<SkScalar> pos(info.fColorCount); |
|
reed1
2016/06/28 17:50:18
Can we move these two lines into the if, so we're
| |
| 1272 SkScalar pos[3]; | 1273 info.fColorOffsets = pos.get(); |
| 1273 | |
| 1274 info.fColorCount = 3; | |
| 1275 info.fColors = &colors[0]; | |
| 1276 info.fColorOffsets = &pos[0]; | |
| 1277 | 1274 |
| 1278 SkShader::GradientType t = shader->asAGradient(&info); | 1275 SkShader::GradientType t = shader->asAGradient(&info); |
| 1279 | 1276 |
| 1280 if (SkShader::kNone_GradientType != t) { | 1277 if (SkShader::kNone_GradientType != t) { |
| 1281 lua_newtable(L); | 1278 lua_newtable(L); |
| 1282 setfield_string(L, "type", gradtype2string(t)); | |
| 1283 setfield_number(L, "colorCount", info.fColorCount); | |
| 1284 setfield_string(L, "tile", mode2string(info.fTileMode)); | |
| 1285 | 1279 |
| 1286 if (info.fColorCount == 3){ | 1280 bool containsHardStops = false; |
| 1287 setfield_number(L, "midPos", pos[1]); | 1281 bool isEvenlySpaced = true; |
| 1282 for (int i = 1; i < info.fColorCount; i++) { | |
| 1283 if (SkScalarNearlyEqual(info.fColorOffsets[i], info.fColorOffset s[i-1])) { | |
| 1284 containsHardStops = true; | |
| 1285 } | |
| 1286 if (!SkScalarNearlyEqual(info.fColorOffsets[i], i/(info.fColorCo unt - 1.0f))) { | |
| 1287 isEvenlySpaced = false; | |
| 1288 } | |
| 1288 } | 1289 } |
| 1289 | 1290 |
| 1291 setfield_string(L, "type", gradtype2string(t)); | |
| 1292 setfield_string(L, "tile", mode2string(info.fTileMode )); | |
| 1293 setfield_number(L, "colorCount", info.fColorCount); | |
| 1294 setfield_boolean(L, "containsHardStops", containsHardStops); | |
| 1295 setfield_boolean(L, "isEvenlySpaced", isEvenlySpaced); | |
| 1296 | |
|
reed1
2016/06/28 17:50:17
We're not pushing the actual t-values into a table
| |
| 1290 return 1; | 1297 return 1; |
| 1291 } | 1298 } |
| 1292 } | 1299 } |
| 1293 return 0; | 1300 return 0; |
| 1294 } | 1301 } |
| 1295 | 1302 |
| 1296 static int lshader_gc(lua_State* L) { | 1303 static int lshader_gc(lua_State* L) { |
| 1297 get_ref<SkShader>(L, 1)->unref(); | 1304 get_ref<SkShader>(L, 1)->unref(); |
| 1298 return 0; | 1305 return 0; |
| 1299 } | 1306 } |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2136 REG_CLASS(L, SkTextBlob); | 2143 REG_CLASS(L, SkTextBlob); |
| 2137 REG_CLASS(L, SkTypeface); | 2144 REG_CLASS(L, SkTypeface); |
| 2138 REG_CLASS(L, SkXfermode); | 2145 REG_CLASS(L, SkXfermode); |
| 2139 } | 2146 } |
| 2140 | 2147 |
| 2141 extern "C" int luaopen_skia(lua_State* L); | 2148 extern "C" int luaopen_skia(lua_State* L); |
| 2142 extern "C" int luaopen_skia(lua_State* L) { | 2149 extern "C" int luaopen_skia(lua_State* L) { |
| 2143 SkLua::Load(L); | 2150 SkLua::Load(L); |
| 2144 return 0; | 2151 return 0; |
| 2145 } | 2152 } |
| OLD | NEW |