Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/utils/SkLua.cpp

Issue 2103973002: Changes to Lua gradient scraping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Count number of hard stops Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/lua/gradients.lua » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 SkShader::GradientInfo info; 1268 SkShader::GradientInfo info;
1269 sk_bzero(&info, sizeof(info)); 1269 sk_bzero(&info, sizeof(info));
1270 1270
1271 SkShader::GradientType t = shader->asAGradient(&info); 1271 SkShader::GradientType t = shader->asAGradient(&info);
1272 1272
1273 if (SkShader::kNone_GradientType != t) { 1273 if (SkShader::kNone_GradientType != t) {
1274 SkAutoTArray<SkScalar> pos(info.fColorCount); 1274 SkAutoTArray<SkScalar> pos(info.fColorCount);
1275 info.fColorOffsets = pos.get(); 1275 info.fColorOffsets = pos.get();
1276 shader->asAGradient(&info); 1276 shader->asAGradient(&info);
1277 1277
1278 bool containsHardStops = false; 1278 int numHardStops = 0;
1279 bool isEvenlySpaced = true; 1279 bool isEvenlySpaced = true;
1280 for (int i = 1; i < info.fColorCount; i++) { 1280 for (int i = 1; i < info.fColorCount; i++) {
1281 if (SkScalarNearlyEqual(info.fColorOffsets[i], info.fColorOffset s[i-1])) { 1281 if (SkScalarNearlyEqual(info.fColorOffsets[i], info.fColorOffset s[i-1])) {
1282 containsHardStops = true; 1282 numHardStops++;
1283 } 1283 }
1284 if (!SkScalarNearlyEqual(info.fColorOffsets[i], i/(info.fColorCo unt - 1.0f))) { 1284 if (!SkScalarNearlyEqual(info.fColorOffsets[i], i/(info.fColorCo unt - 1.0f))) {
1285 isEvenlySpaced = false; 1285 isEvenlySpaced = false;
1286 } 1286 }
1287 } 1287 }
1288 1288
1289 lua_newtable(L); 1289 lua_newtable(L);
1290 setfield_string(L, "type", gradtype2string(t)); 1290 setfield_string(L, "type", gradtype2string(t));
1291 setfield_string(L, "tile", mode2string(info.fTileMode )); 1291 setfield_string(L, "tile", mode2string(info.fTileMode));
1292 setfield_number(L, "colorCount", info.fColorCount); 1292 setfield_number(L, "colorCount", info.fColorCount);
1293 setfield_boolean(L, "containsHardStops", containsHardStops); 1293 setfield_number(L, "numHardStops", numHardStops);
1294 setfield_boolean(L, "isEvenlySpaced", isEvenlySpaced); 1294 setfield_boolean(L, "isEvenlySpaced", isEvenlySpaced);
1295 1295
1296 lua_newtable(L); 1296 lua_newtable(L);
1297 for (int i = 0; i < info.fColorCount; i++) { 1297 for (int i = 0; i < info.fColorCount; i++) {
1298 // Lua uses 1-based indexing 1298 // Lua uses 1-based indexing
1299 setarray_scalar(L, i+1, pos[i]); 1299 setarray_scalar(L, i+1, pos[i]);
1300 } 1300 }
1301 lua_setfield(L, -2, "positions"); 1301 lua_setfield(L, -2, "positions");
1302 1302
1303 return 1; 1303 return 1;
1304 } 1304 }
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 REG_CLASS(L, SkTextBlob); 2149 REG_CLASS(L, SkTextBlob);
2150 REG_CLASS(L, SkTypeface); 2150 REG_CLASS(L, SkTypeface);
2151 REG_CLASS(L, SkXfermode); 2151 REG_CLASS(L, SkXfermode);
2152 } 2152 }
2153 2153
2154 extern "C" int luaopen_skia(lua_State* L); 2154 extern "C" int luaopen_skia(lua_State* L);
2155 extern "C" int luaopen_skia(lua_State* L) { 2155 extern "C" int luaopen_skia(lua_State* L) {
2156 SkLua::Load(L); 2156 SkLua::Load(L);
2157 return 0; 2157 return 0;
2158 } 2158 }
OLDNEW
« no previous file with comments | « no previous file | tools/lua/gradients.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698