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 |
11 #include "GrReducedClip.h" | 11 #include "GrReducedClip.h" |
12 #endif | 12 #endif |
13 | 13 |
14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
15 #include "SkData.h" | 15 #include "SkData.h" |
16 #include "SkDocument.h" | 16 #include "SkDocument.h" |
17 #include "SkImage.h" | 17 #include "SkImage.h" |
18 #include "SkMatrix.h" | 18 #include "SkMatrix.h" |
19 #include "SkPaint.h" | 19 #include "SkPaint.h" |
20 #include "SkPath.h" | 20 #include "SkPath.h" |
21 #include "SkPathEffect.h" | |
22 #include "SkPixelRef.h" | 21 #include "SkPixelRef.h" |
23 #include "SkRRect.h" | 22 #include "SkRRect.h" |
24 #include "SkString.h" | 23 #include "SkString.h" |
25 #include "SkTypeface.h" | 24 #include "SkTypeface.h" |
26 | 25 |
27 extern "C" { | 26 extern "C" { |
28 #include "lua.h" | 27 #include "lua.h" |
29 #include "lualib.h" | 28 #include "lualib.h" |
30 #include "lauxlib.h" | 29 #include "lauxlib.h" |
31 } | 30 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 const char key[], lua_CFunction value) { | 149 const char key[], lua_CFunction value) { |
151 lua_pushcfunction(L, value); | 150 lua_pushcfunction(L, value); |
152 lua_setfield(L, -2, key); | 151 lua_setfield(L, -2, key); |
153 } | 152 } |
154 | 153 |
155 static void setarray_number(lua_State* L, int index, double value) { | 154 static void setarray_number(lua_State* L, int index, double value) { |
156 lua_pushnumber(L, value); | 155 lua_pushnumber(L, value); |
157 lua_rawseti(L, -2, index); | 156 lua_rawseti(L, -2, index); |
158 } | 157 } |
159 | 158 |
| 159 static void setarray_scalar(lua_State* L, int index, SkScalar value) { |
| 160 setarray_number(L, index, SkScalarToLua(value)); |
| 161 } |
| 162 |
160 void SkLua::pushBool(bool value, const char key[]) { | 163 void SkLua::pushBool(bool value, const char key[]) { |
161 lua_pushboolean(fL, value); | 164 lua_pushboolean(fL, value); |
162 CHECK_SETFIELD(key); | 165 CHECK_SETFIELD(key); |
163 } | 166 } |
164 | 167 |
165 void SkLua::pushString(const char str[], const char key[]) { | 168 void SkLua::pushString(const char str[], const char key[]) { |
166 lua_pushstring(fL, str); | 169 lua_pushstring(fL, str); |
167 CHECK_SETFIELD(key); | 170 CHECK_SETFIELD(key); |
168 } | 171 } |
169 | 172 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 for (int i = 0; i < count; ++i) { | 215 for (int i = 0; i < count; ++i) { |
213 // make it base-1 to match lua convention | 216 // make it base-1 to match lua convention |
214 lua_newtable(fL); | 217 lua_newtable(fL); |
215 this->pushScalar(array[i].fX, "x"); | 218 this->pushScalar(array[i].fX, "x"); |
216 this->pushScalar(array[i].fY, "y"); | 219 this->pushScalar(array[i].fY, "y"); |
217 lua_rawseti(fL, -2, i + 1); | 220 lua_rawseti(fL, -2, i + 1); |
218 } | 221 } |
219 CHECK_SETFIELD(key); | 222 CHECK_SETFIELD(key); |
220 } | 223 } |
221 | 224 |
| 225 void SkLua::pushArrayScalar(const SkScalar array[], int count, const char key[])
{ |
| 226 lua_newtable(fL); |
| 227 for (int i = 0; i < count; ++i) { |
| 228 // make it base-1 to match lua convention |
| 229 setarray_scalar(fL, i + 1, array[i]); |
| 230 } |
| 231 CHECK_SETFIELD(key); |
| 232 } |
| 233 |
222 void SkLua::pushRect(const SkRect& r, const char key[]) { | 234 void SkLua::pushRect(const SkRect& r, const char key[]) { |
223 lua_newtable(fL); | 235 lua_newtable(fL); |
224 setfield_scalar(fL, "left", r.fLeft); | 236 setfield_scalar(fL, "left", r.fLeft); |
225 setfield_scalar(fL, "top", r.fTop); | 237 setfield_scalar(fL, "top", r.fTop); |
226 setfield_scalar(fL, "right", r.fRight); | 238 setfield_scalar(fL, "right", r.fRight); |
227 setfield_scalar(fL, "bottom", r.fBottom); | 239 setfield_scalar(fL, "bottom", r.fBottom); |
228 CHECK_SETFIELD(key); | 240 CHECK_SETFIELD(key); |
229 } | 241 } |
230 | 242 |
231 void SkLua::pushRRect(const SkRRect& rr, const char key[]) { | 243 void SkLua::pushRRect(const SkRRect& rr, const char key[]) { |
232 push_obj(fL, rr); | 244 push_obj(fL, rr); |
233 CHECK_SETFIELD(key); | 245 CHECK_SETFIELD(key); |
234 } | 246 } |
235 | 247 |
| 248 void SkLua::pushDash(const SkPathEffect::DashInfo& info, const char key[]) { |
| 249 lua_newtable(fL); |
| 250 setfield_scalar(fL, "phase", info.fPhase); |
| 251 this->pushArrayScalar(info.fIntervals, info.fCount, "intervals"); |
| 252 CHECK_SETFIELD(key); |
| 253 } |
| 254 |
| 255 |
236 void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) { | 256 void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) { |
237 push_obj(fL, matrix); | 257 push_obj(fL, matrix); |
238 CHECK_SETFIELD(key); | 258 CHECK_SETFIELD(key); |
239 } | 259 } |
240 | 260 |
241 void SkLua::pushPaint(const SkPaint& paint, const char key[]) { | 261 void SkLua::pushPaint(const SkPaint& paint, const char key[]) { |
242 push_obj(fL, paint); | 262 push_obj(fL, paint); |
243 CHECK_SETFIELD(key); | 263 CHECK_SETFIELD(key); |
244 } | 264 } |
245 | 265 |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 static const struct luaL_Reg gSkShader_Methods[] = { | 1019 static const struct luaL_Reg gSkShader_Methods[] = { |
1000 { "isOpaque", lshader_isOpaque }, | 1020 { "isOpaque", lshader_isOpaque }, |
1001 { "asABitmap", lshader_asABitmap }, | 1021 { "asABitmap", lshader_asABitmap }, |
1002 { "asAGradient", lshader_asAGradient }, | 1022 { "asAGradient", lshader_asAGradient }, |
1003 { "__gc", lshader_gc }, | 1023 { "__gc", lshader_gc }, |
1004 { NULL, NULL } | 1024 { NULL, NULL } |
1005 }; | 1025 }; |
1006 | 1026 |
1007 /////////////////////////////////////////////////////////////////////////////// | 1027 /////////////////////////////////////////////////////////////////////////////// |
1008 | 1028 |
| 1029 static int lpatheffect_asADash(lua_State* L) { |
| 1030 SkPathEffect* pe = get_ref<SkPathEffect>(L, 1); |
| 1031 if (pe) { |
| 1032 SkPathEffect::DashInfo info; |
| 1033 SkPathEffect::DashType dashType = pe->asADash(&info); |
| 1034 if (SkPathEffect::kDash_DashType == dashType) { |
| 1035 SkAutoTArray<SkScalar> intervals(info.fCount); |
| 1036 info.fIntervals = intervals.get(); |
| 1037 pe->asADash(&info); |
| 1038 SkLua(L).pushDash(info); |
| 1039 return 1; |
| 1040 } |
| 1041 } |
| 1042 return 0; |
| 1043 } |
| 1044 |
1009 static int lpatheffect_gc(lua_State* L) { | 1045 static int lpatheffect_gc(lua_State* L) { |
1010 get_ref<SkPathEffect>(L, 1)->unref(); | 1046 get_ref<SkPathEffect>(L, 1)->unref(); |
1011 return 0; | 1047 return 0; |
1012 } | 1048 } |
1013 | 1049 |
1014 static const struct luaL_Reg gSkPathEffect_Methods[] = { | 1050 static const struct luaL_Reg gSkPathEffect_Methods[] = { |
| 1051 { "asADash", lpatheffect_asADash }, |
1015 { "__gc", lpatheffect_gc }, | 1052 { "__gc", lpatheffect_gc }, |
1016 { NULL, NULL } | 1053 { NULL, NULL } |
1017 }; | 1054 }; |
1018 | 1055 |
1019 /////////////////////////////////////////////////////////////////////////////// | 1056 /////////////////////////////////////////////////////////////////////////////// |
1020 | 1057 |
1021 static int lmatrix_getType(lua_State* L) { | 1058 static int lmatrix_getType(lua_State* L) { |
1022 SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType(); | 1059 SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType(); |
1023 | 1060 |
1024 lua_newtable(L); | 1061 lua_newtable(L); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 REG_CLASS(L, SkShader); | 1500 REG_CLASS(L, SkShader); |
1464 REG_CLASS(L, SkTypeface); | 1501 REG_CLASS(L, SkTypeface); |
1465 REG_CLASS(L, SkMatrix); | 1502 REG_CLASS(L, SkMatrix); |
1466 } | 1503 } |
1467 | 1504 |
1468 extern "C" int luaopen_skia(lua_State* L); | 1505 extern "C" int luaopen_skia(lua_State* L); |
1469 extern "C" int luaopen_skia(lua_State* L) { | 1506 extern "C" int luaopen_skia(lua_State* L) { |
1470 SkLua::Load(L); | 1507 SkLua::Load(L); |
1471 return 0; | 1508 return 0; |
1472 } | 1509 } |
OLD | NEW |