| 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" |
| 31 | 32 |
| 32 extern "C" { | 33 extern "C" { |
| 33 #include "lua.h" | 34 #include "lua.h" |
| 34 #include "lualib.h" | 35 #include "lualib.h" |
| 35 #include "lauxlib.h" | 36 #include "lauxlib.h" |
| 36 } | 37 } |
| 37 | 38 |
| 38 // return the metatable name for a given class | 39 // return the metatable name for a given class |
| 39 template <typename T> const char* get_mtname(); | 40 template <typename T> const char* get_mtname(); |
| 40 #define DEF_MTNAME(T) \ | 41 #define DEF_MTNAME(T) \ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 DEF_MTNAME(SkRRect) | 52 DEF_MTNAME(SkRRect) |
| 52 DEF_MTNAME(SkPath) | 53 DEF_MTNAME(SkPath) |
| 53 DEF_MTNAME(SkPaint) | 54 DEF_MTNAME(SkPaint) |
| 54 DEF_MTNAME(SkPathEffect) | 55 DEF_MTNAME(SkPathEffect) |
| 55 DEF_MTNAME(SkPicture) | 56 DEF_MTNAME(SkPicture) |
| 56 DEF_MTNAME(SkPictureRecorder) | 57 DEF_MTNAME(SkPictureRecorder) |
| 57 DEF_MTNAME(SkShader) | 58 DEF_MTNAME(SkShader) |
| 58 DEF_MTNAME(SkSurface) | 59 DEF_MTNAME(SkSurface) |
| 59 DEF_MTNAME(SkTextBlob) | 60 DEF_MTNAME(SkTextBlob) |
| 60 DEF_MTNAME(SkTypeface) | 61 DEF_MTNAME(SkTypeface) |
| 62 DEF_MTNAME(SkXfermode) |
| 61 | 63 |
| 62 template <typename T> T* push_new(lua_State* L) { | 64 template <typename T> T* push_new(lua_State* L) { |
| 63 T* addr = (T*)lua_newuserdata(L, sizeof(T)); | 65 T* addr = (T*)lua_newuserdata(L, sizeof(T)); |
| 64 new (addr) T; | 66 new (addr) T; |
| 65 luaL_getmetatable(L, get_mtname<T>()); | 67 luaL_getmetatable(L, get_mtname<T>()); |
| 66 lua_setmetatable(L, -2); | 68 lua_setmetatable(L, -2); |
| 67 return addr; | 69 return addr; |
| 68 } | 70 } |
| 69 | 71 |
| 70 template <typename T> void push_obj(lua_State* L, const T& obj) { | 72 template <typename T> void push_obj(lua_State* L, const T& obj) { |
| (...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1074 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); | 1076 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); |
| 1075 setfield_bool_if(L, "rasterizer", !!paint->getRasterizer()); | 1077 setfield_bool_if(L, "rasterizer", !!paint->getRasterizer()); |
| 1076 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); | 1078 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); |
| 1077 setfield_bool_if(L, "shader", !!paint->getShader()); | 1079 setfield_bool_if(L, "shader", !!paint->getShader()); |
| 1078 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); | 1080 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); |
| 1079 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); | 1081 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); |
| 1080 setfield_bool_if(L, "xfermode", !!paint->getXfermode()); | 1082 setfield_bool_if(L, "xfermode", !!paint->getXfermode()); |
| 1081 return 1; | 1083 return 1; |
| 1082 } | 1084 } |
| 1083 | 1085 |
| 1086 static int lpaint_getXfermode(lua_State* L) { |
| 1087 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1088 SkXfermode* xfermode = paint->getXfermode(); |
| 1089 if (xfermode) { |
| 1090 push_ref(L, xfermode); |
| 1091 return 1; |
| 1092 } |
| 1093 return 0; |
| 1094 } |
| 1095 |
| 1096 static int lpaint_setXfermode(lua_State* L) { |
| 1097 SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1098 paint->setXfermode(get_ref<SkXfermode>(L, 2)); |
| 1099 return 0; |
| 1100 } |
| 1101 |
| 1084 static int lpaint_getColorFilter(lua_State* L) { | 1102 static int lpaint_getColorFilter(lua_State* L) { |
| 1085 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1103 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1086 SkColorFilter* cf = paint->getColorFilter(); | 1104 SkColorFilter* cf = paint->getColorFilter(); |
| 1087 if (cf) { | 1105 if (cf) { |
| 1088 push_ref(L, cf); | 1106 push_ref(L, cf); |
| 1089 return 1; | 1107 return 1; |
| 1090 } | 1108 } |
| 1091 return 0; | 1109 return 0; |
| 1092 } | 1110 } |
| 1093 | 1111 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 { "getStrokeWidth", lpaint_getStrokeWidth }, | 1203 { "getStrokeWidth", lpaint_getStrokeWidth }, |
| 1186 { "setStrokeWidth", lpaint_setStrokeWidth }, | 1204 { "setStrokeWidth", lpaint_setStrokeWidth }, |
| 1187 { "getStrokeMiter", lpaint_getStrokeMiter }, | 1205 { "getStrokeMiter", lpaint_getStrokeMiter }, |
| 1188 { "measureText", lpaint_measureText }, | 1206 { "measureText", lpaint_measureText }, |
| 1189 { "getFontMetrics", lpaint_getFontMetrics }, | 1207 { "getFontMetrics", lpaint_getFontMetrics }, |
| 1190 { "getEffects", lpaint_getEffects }, | 1208 { "getEffects", lpaint_getEffects }, |
| 1191 { "getColorFilter", lpaint_getColorFilter }, | 1209 { "getColorFilter", lpaint_getColorFilter }, |
| 1192 { "setColorFilter", lpaint_setColorFilter }, | 1210 { "setColorFilter", lpaint_setColorFilter }, |
| 1193 { "getImageFilter", lpaint_getImageFilter }, | 1211 { "getImageFilter", lpaint_getImageFilter }, |
| 1194 { "setImageFilter", lpaint_setImageFilter }, | 1212 { "setImageFilter", lpaint_setImageFilter }, |
| 1213 { "getXfermode", lpaint_getXfermode }, |
| 1214 { "setXfermode", lpaint_setXfermode }, |
| 1195 { "getShader", lpaint_getShader }, | 1215 { "getShader", lpaint_getShader }, |
| 1196 { "setShader", lpaint_setShader }, | 1216 { "setShader", lpaint_setShader }, |
| 1197 { "getPathEffect", lpaint_getPathEffect }, | 1217 { "getPathEffect", lpaint_getPathEffect }, |
| 1198 { "__gc", lpaint_gc }, | 1218 { "__gc", lpaint_gc }, |
| 1199 { nullptr, nullptr } | 1219 { nullptr, nullptr } |
| 1200 }; | 1220 }; |
| 1201 | 1221 |
| 1202 /////////////////////////////////////////////////////////////////////////////// | 1222 /////////////////////////////////////////////////////////////////////////////// |
| 1203 | 1223 |
| 1204 static const char* mode2string(SkShader::TileMode mode) { | 1224 static const char* mode2string(SkShader::TileMode mode) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 } | 1327 } |
| 1308 | 1328 |
| 1309 static const struct luaL_Reg gSkPathEffect_Methods[] = { | 1329 static const struct luaL_Reg gSkPathEffect_Methods[] = { |
| 1310 { "asADash", lpatheffect_asADash }, | 1330 { "asADash", lpatheffect_asADash }, |
| 1311 { "__gc", lpatheffect_gc }, | 1331 { "__gc", lpatheffect_gc }, |
| 1312 { nullptr, nullptr } | 1332 { nullptr, nullptr } |
| 1313 }; | 1333 }; |
| 1314 | 1334 |
| 1315 /////////////////////////////////////////////////////////////////////////////// | 1335 /////////////////////////////////////////////////////////////////////////////// |
| 1316 | 1336 |
| 1337 static int lpxfermode_getTypeName(lua_State* L) { |
| 1338 lua_pushstring(L, get_ref<SkXfermode>(L, 1)->getTypeName()); |
| 1339 return 1; |
| 1340 } |
| 1341 |
| 1342 static int lpxfermode_gc(lua_State* L) { |
| 1343 get_ref<SkXfermode>(L, 1)->unref(); |
| 1344 return 0; |
| 1345 } |
| 1346 |
| 1347 static const struct luaL_Reg gSkXfermode_Methods[] = { |
| 1348 { "getTypeName", lpxfermode_getTypeName }, |
| 1349 { "__gc", lpxfermode_gc }, |
| 1350 { nullptr, nullptr } |
| 1351 }; |
| 1352 |
| 1353 /////////////////////////////////////////////////////////////////////////////// |
| 1354 |
| 1317 static int lpcolorfilter_gc(lua_State* L) { | 1355 static int lpcolorfilter_gc(lua_State* L) { |
| 1318 get_ref<SkColorFilter>(L, 1)->unref(); | 1356 get_ref<SkColorFilter>(L, 1)->unref(); |
| 1319 return 0; | 1357 return 0; |
| 1320 } | 1358 } |
| 1321 | 1359 |
| 1322 static const struct luaL_Reg gSkColorFilter_Methods[] = { | 1360 static const struct luaL_Reg gSkColorFilter_Methods[] = { |
| 1323 { "__gc", lpcolorfilter_gc }, | 1361 { "__gc", lpcolorfilter_gc }, |
| 1324 { nullptr, nullptr } | 1362 { nullptr, nullptr } |
| 1325 }; | 1363 }; |
| 1326 | 1364 |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2088 REG_CLASS(L, SkPaint); | 2126 REG_CLASS(L, SkPaint); |
| 2089 REG_CLASS(L, SkPath); | 2127 REG_CLASS(L, SkPath); |
| 2090 REG_CLASS(L, SkPathEffect); | 2128 REG_CLASS(L, SkPathEffect); |
| 2091 REG_CLASS(L, SkPicture); | 2129 REG_CLASS(L, SkPicture); |
| 2092 REG_CLASS(L, SkPictureRecorder); | 2130 REG_CLASS(L, SkPictureRecorder); |
| 2093 REG_CLASS(L, SkRRect); | 2131 REG_CLASS(L, SkRRect); |
| 2094 REG_CLASS(L, SkShader); | 2132 REG_CLASS(L, SkShader); |
| 2095 REG_CLASS(L, SkSurface); | 2133 REG_CLASS(L, SkSurface); |
| 2096 REG_CLASS(L, SkTextBlob); | 2134 REG_CLASS(L, SkTextBlob); |
| 2097 REG_CLASS(L, SkTypeface); | 2135 REG_CLASS(L, SkTypeface); |
| 2136 REG_CLASS(L, SkXfermode); |
| 2098 } | 2137 } |
| 2099 | 2138 |
| 2100 extern "C" int luaopen_skia(lua_State* L); | 2139 extern "C" int luaopen_skia(lua_State* L); |
| 2101 extern "C" int luaopen_skia(lua_State* L) { | 2140 extern "C" int luaopen_skia(lua_State* L) { |
| 2102 SkLua::Load(L); | 2141 SkLua::Load(L); |
| 2103 return 0; | 2142 return 0; |
| 2104 } | 2143 } |
| OLD | NEW |