| 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 10 matching lines...) Expand all Loading... |
| 21 #include "SkMatrix.h" | 21 #include "SkMatrix.h" |
| 22 #include "SkPaint.h" | 22 #include "SkPaint.h" |
| 23 #include "SkPath.h" | 23 #include "SkPath.h" |
| 24 #include "SkPictureRecorder.h" | 24 #include "SkPictureRecorder.h" |
| 25 #include "SkPixelRef.h" | 25 #include "SkPixelRef.h" |
| 26 #include "SkRRect.h" | 26 #include "SkRRect.h" |
| 27 #include "SkString.h" | 27 #include "SkString.h" |
| 28 #include "SkSurface.h" | 28 #include "SkSurface.h" |
| 29 #include "SkTextBlob.h" | 29 #include "SkTextBlob.h" |
| 30 #include "SkTypeface.h" | 30 #include "SkTypeface.h" |
| 31 #include "SkXfermode.h" | |
| 32 | 31 |
| 33 extern "C" { | 32 extern "C" { |
| 34 #include "lua.h" | 33 #include "lua.h" |
| 35 #include "lualib.h" | 34 #include "lualib.h" |
| 36 #include "lauxlib.h" | 35 #include "lauxlib.h" |
| 37 } | 36 } |
| 38 | 37 |
| 39 // return the metatable name for a given class | 38 // return the metatable name for a given class |
| 40 template <typename T> const char* get_mtname(); | 39 template <typename T> const char* get_mtname(); |
| 41 #define DEF_MTNAME(T) \ | 40 #define DEF_MTNAME(T) \ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 DEF_MTNAME(SkRRect) | 51 DEF_MTNAME(SkRRect) |
| 53 DEF_MTNAME(SkPath) | 52 DEF_MTNAME(SkPath) |
| 54 DEF_MTNAME(SkPaint) | 53 DEF_MTNAME(SkPaint) |
| 55 DEF_MTNAME(SkPathEffect) | 54 DEF_MTNAME(SkPathEffect) |
| 56 DEF_MTNAME(SkPicture) | 55 DEF_MTNAME(SkPicture) |
| 57 DEF_MTNAME(SkPictureRecorder) | 56 DEF_MTNAME(SkPictureRecorder) |
| 58 DEF_MTNAME(SkShader) | 57 DEF_MTNAME(SkShader) |
| 59 DEF_MTNAME(SkSurface) | 58 DEF_MTNAME(SkSurface) |
| 60 DEF_MTNAME(SkTextBlob) | 59 DEF_MTNAME(SkTextBlob) |
| 61 DEF_MTNAME(SkTypeface) | 60 DEF_MTNAME(SkTypeface) |
| 62 DEF_MTNAME(SkXfermode) | |
| 63 | 61 |
| 64 template <typename T> T* push_new(lua_State* L) { | 62 template <typename T> T* push_new(lua_State* L) { |
| 65 T* addr = (T*)lua_newuserdata(L, sizeof(T)); | 63 T* addr = (T*)lua_newuserdata(L, sizeof(T)); |
| 66 new (addr) T; | 64 new (addr) T; |
| 67 luaL_getmetatable(L, get_mtname<T>()); | 65 luaL_getmetatable(L, get_mtname<T>()); |
| 68 lua_setmetatable(L, -2); | 66 lua_setmetatable(L, -2); |
| 69 return addr; | 67 return addr; |
| 70 } | 68 } |
| 71 | 69 |
| 72 template <typename T> void push_obj(lua_State* L, const T& obj) { | 70 template <typename T> void push_obj(lua_State* L, const T& obj) { |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1064 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1067 | 1065 |
| 1068 lua_newtable(L); | 1066 lua_newtable(L); |
| 1069 setfield_bool_if(L, "looper", !!paint->getLooper()); | 1067 setfield_bool_if(L, "looper", !!paint->getLooper()); |
| 1070 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); | 1068 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); |
| 1071 setfield_bool_if(L, "rasterizer", !!paint->getRasterizer()); | 1069 setfield_bool_if(L, "rasterizer", !!paint->getRasterizer()); |
| 1072 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); | 1070 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); |
| 1073 setfield_bool_if(L, "shader", !!paint->getShader()); | 1071 setfield_bool_if(L, "shader", !!paint->getShader()); |
| 1074 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); | 1072 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); |
| 1075 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); | 1073 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); |
| 1076 setfield_bool_if(L, "xfermode", !!paint->getXfermode()); | |
| 1077 return 1; | 1074 return 1; |
| 1078 } | 1075 } |
| 1079 | 1076 |
| 1080 static int lpaint_getXfermode(lua_State* L) { | |
| 1081 const SkPaint* paint = get_obj<SkPaint>(L, 1); | |
| 1082 SkXfermode* xfermode = paint->getXfermode(); | |
| 1083 if (xfermode) { | |
| 1084 push_ref(L, xfermode); | |
| 1085 return 1; | |
| 1086 } | |
| 1087 return 0; | |
| 1088 } | |
| 1089 | |
| 1090 static int lpaint_setXfermode(lua_State* L) { | |
| 1091 SkPaint* paint = get_obj<SkPaint>(L, 1); | |
| 1092 paint->setXfermode(sk_ref_sp(get_ref<SkXfermode>(L, 2))); | |
| 1093 return 0; | |
| 1094 } | |
| 1095 | |
| 1096 static int lpaint_getColorFilter(lua_State* L) { | 1077 static int lpaint_getColorFilter(lua_State* L) { |
| 1097 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1078 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1098 SkColorFilter* cf = paint->getColorFilter(); | 1079 SkColorFilter* cf = paint->getColorFilter(); |
| 1099 if (cf) { | 1080 if (cf) { |
| 1100 push_ref(L, cf); | 1081 push_ref(L, cf); |
| 1101 return 1; | 1082 return 1; |
| 1102 } | 1083 } |
| 1103 return 0; | 1084 return 0; |
| 1104 } | 1085 } |
| 1105 | 1086 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 { "getStrokeWidth", lpaint_getStrokeWidth }, | 1191 { "getStrokeWidth", lpaint_getStrokeWidth }, |
| 1211 { "setStrokeWidth", lpaint_setStrokeWidth }, | 1192 { "setStrokeWidth", lpaint_setStrokeWidth }, |
| 1212 { "getStrokeMiter", lpaint_getStrokeMiter }, | 1193 { "getStrokeMiter", lpaint_getStrokeMiter }, |
| 1213 { "measureText", lpaint_measureText }, | 1194 { "measureText", lpaint_measureText }, |
| 1214 { "getFontMetrics", lpaint_getFontMetrics }, | 1195 { "getFontMetrics", lpaint_getFontMetrics }, |
| 1215 { "getEffects", lpaint_getEffects }, | 1196 { "getEffects", lpaint_getEffects }, |
| 1216 { "getColorFilter", lpaint_getColorFilter }, | 1197 { "getColorFilter", lpaint_getColorFilter }, |
| 1217 { "setColorFilter", lpaint_setColorFilter }, | 1198 { "setColorFilter", lpaint_setColorFilter }, |
| 1218 { "getImageFilter", lpaint_getImageFilter }, | 1199 { "getImageFilter", lpaint_getImageFilter }, |
| 1219 { "setImageFilter", lpaint_setImageFilter }, | 1200 { "setImageFilter", lpaint_setImageFilter }, |
| 1220 { "getXfermode", lpaint_getXfermode }, | |
| 1221 { "setXfermode", lpaint_setXfermode }, | |
| 1222 { "getShader", lpaint_getShader }, | 1201 { "getShader", lpaint_getShader }, |
| 1223 { "setShader", lpaint_setShader }, | 1202 { "setShader", lpaint_setShader }, |
| 1224 { "getPathEffect", lpaint_getPathEffect }, | 1203 { "getPathEffect", lpaint_getPathEffect }, |
| 1225 { "getFillPath", lpaint_getFillPath }, | 1204 { "getFillPath", lpaint_getFillPath }, |
| 1226 { "__gc", lpaint_gc }, | 1205 { "__gc", lpaint_gc }, |
| 1227 { nullptr, nullptr } | 1206 { nullptr, nullptr } |
| 1228 }; | 1207 }; |
| 1229 | 1208 |
| 1230 /////////////////////////////////////////////////////////////////////////////// | 1209 /////////////////////////////////////////////////////////////////////////////// |
| 1231 | 1210 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 } | 1313 } |
| 1335 | 1314 |
| 1336 static const struct luaL_Reg gSkPathEffect_Methods[] = { | 1315 static const struct luaL_Reg gSkPathEffect_Methods[] = { |
| 1337 { "asADash", lpatheffect_asADash }, | 1316 { "asADash", lpatheffect_asADash }, |
| 1338 { "__gc", lpatheffect_gc }, | 1317 { "__gc", lpatheffect_gc }, |
| 1339 { nullptr, nullptr } | 1318 { nullptr, nullptr } |
| 1340 }; | 1319 }; |
| 1341 | 1320 |
| 1342 /////////////////////////////////////////////////////////////////////////////// | 1321 /////////////////////////////////////////////////////////////////////////////// |
| 1343 | 1322 |
| 1344 static int lpxfermode_getTypeName(lua_State* L) { | |
| 1345 lua_pushstring(L, get_ref<SkXfermode>(L, 1)->getTypeName()); | |
| 1346 return 1; | |
| 1347 } | |
| 1348 | |
| 1349 static int lpxfermode_gc(lua_State* L) { | |
| 1350 get_ref<SkXfermode>(L, 1)->unref(); | |
| 1351 return 0; | |
| 1352 } | |
| 1353 | |
| 1354 static const struct luaL_Reg gSkXfermode_Methods[] = { | |
| 1355 { "getTypeName", lpxfermode_getTypeName }, | |
| 1356 { "__gc", lpxfermode_gc }, | |
| 1357 { nullptr, nullptr } | |
| 1358 }; | |
| 1359 | |
| 1360 /////////////////////////////////////////////////////////////////////////////// | |
| 1361 | |
| 1362 static int lpcolorfilter_gc(lua_State* L) { | 1323 static int lpcolorfilter_gc(lua_State* L) { |
| 1363 get_ref<SkColorFilter>(L, 1)->unref(); | 1324 get_ref<SkColorFilter>(L, 1)->unref(); |
| 1364 return 0; | 1325 return 0; |
| 1365 } | 1326 } |
| 1366 | 1327 |
| 1367 static const struct luaL_Reg gSkColorFilter_Methods[] = { | 1328 static const struct luaL_Reg gSkColorFilter_Methods[] = { |
| 1368 { "__gc", lpcolorfilter_gc }, | 1329 { "__gc", lpcolorfilter_gc }, |
| 1369 { nullptr, nullptr } | 1330 { nullptr, nullptr } |
| 1370 }; | 1331 }; |
| 1371 | 1332 |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 REG_CLASS(L, SkPaint); | 2132 REG_CLASS(L, SkPaint); |
| 2172 REG_CLASS(L, SkPath); | 2133 REG_CLASS(L, SkPath); |
| 2173 REG_CLASS(L, SkPathEffect); | 2134 REG_CLASS(L, SkPathEffect); |
| 2174 REG_CLASS(L, SkPicture); | 2135 REG_CLASS(L, SkPicture); |
| 2175 REG_CLASS(L, SkPictureRecorder); | 2136 REG_CLASS(L, SkPictureRecorder); |
| 2176 REG_CLASS(L, SkRRect); | 2137 REG_CLASS(L, SkRRect); |
| 2177 REG_CLASS(L, SkShader); | 2138 REG_CLASS(L, SkShader); |
| 2178 REG_CLASS(L, SkSurface); | 2139 REG_CLASS(L, SkSurface); |
| 2179 REG_CLASS(L, SkTextBlob); | 2140 REG_CLASS(L, SkTextBlob); |
| 2180 REG_CLASS(L, SkTypeface); | 2141 REG_CLASS(L, SkTypeface); |
| 2181 REG_CLASS(L, SkXfermode); | |
| 2182 } | 2142 } |
| 2183 | 2143 |
| 2184 extern "C" int luaopen_skia(lua_State* L); | 2144 extern "C" int luaopen_skia(lua_State* L); |
| 2185 extern "C" int luaopen_skia(lua_State* L) { | 2145 extern "C" int luaopen_skia(lua_State* L) { |
| 2186 SkLua::Load(L); | 2146 SkLua::Load(L); |
| 2187 return 0; | 2147 return 0; |
| 2188 } | 2148 } |
| OLD | NEW |