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 "SkBlurImageFilter.h" | 14 #include "SkBlurImageFilter.h" |
15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 16 #include "SkColorFilter.h" |
16 #include "SkData.h" | 17 #include "SkData.h" |
17 #include "SkDocument.h" | 18 #include "SkDocument.h" |
18 #include "SkGradientShader.h" | 19 #include "SkGradientShader.h" |
19 #include "SkImage.h" | 20 #include "SkImage.h" |
20 #include "SkMatrix.h" | 21 #include "SkMatrix.h" |
21 #include "SkPaint.h" | 22 #include "SkPaint.h" |
22 #include "SkPath.h" | 23 #include "SkPath.h" |
23 #include "SkPictureRecorder.h" | 24 #include "SkPictureRecorder.h" |
24 #include "SkPixelRef.h" | 25 #include "SkPixelRef.h" |
25 #include "SkRRect.h" | 26 #include "SkRRect.h" |
26 #include "SkString.h" | 27 #include "SkString.h" |
27 #include "SkSurface.h" | 28 #include "SkSurface.h" |
28 #include "SkTextBlob.h" | 29 #include "SkTextBlob.h" |
29 #include "SkTypeface.h" | 30 #include "SkTypeface.h" |
30 | 31 |
31 extern "C" { | 32 extern "C" { |
32 #include "lua.h" | 33 #include "lua.h" |
33 #include "lualib.h" | 34 #include "lualib.h" |
34 #include "lauxlib.h" | 35 #include "lauxlib.h" |
35 } | 36 } |
36 | 37 |
37 // return the metatable name for a given class | 38 // return the metatable name for a given class |
38 template <typename T> const char* get_mtname(); | 39 template <typename T> const char* get_mtname(); |
39 #define DEF_MTNAME(T) \ | 40 #define DEF_MTNAME(T) \ |
40 template <> const char* get_mtname<T>() { \ | 41 template <> const char* get_mtname<T>() { \ |
41 return #T "_LuaMetaTableName"; \ | 42 return #T "_LuaMetaTableName"; \ |
42 } | 43 } |
43 | 44 |
44 DEF_MTNAME(SkCanvas) | 45 DEF_MTNAME(SkCanvas) |
| 46 DEF_MTNAME(SkColorFilter) |
45 DEF_MTNAME(SkDocument) | 47 DEF_MTNAME(SkDocument) |
46 DEF_MTNAME(SkImage) | 48 DEF_MTNAME(SkImage) |
47 DEF_MTNAME(SkImageFilter) | 49 DEF_MTNAME(SkImageFilter) |
48 DEF_MTNAME(SkMatrix) | 50 DEF_MTNAME(SkMatrix) |
49 DEF_MTNAME(SkRRect) | 51 DEF_MTNAME(SkRRect) |
50 DEF_MTNAME(SkPath) | 52 DEF_MTNAME(SkPath) |
51 DEF_MTNAME(SkPaint) | 53 DEF_MTNAME(SkPaint) |
52 DEF_MTNAME(SkPathEffect) | 54 DEF_MTNAME(SkPathEffect) |
53 DEF_MTNAME(SkPicture) | 55 DEF_MTNAME(SkPicture) |
54 DEF_MTNAME(SkPictureRecorder) | 56 DEF_MTNAME(SkPictureRecorder) |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); | 1074 setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); |
1073 setfield_bool_if(L, "rasterizer", !!paint->getRasterizer()); | 1075 setfield_bool_if(L, "rasterizer", !!paint->getRasterizer()); |
1074 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); | 1076 setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); |
1075 setfield_bool_if(L, "shader", !!paint->getShader()); | 1077 setfield_bool_if(L, "shader", !!paint->getShader()); |
1076 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); | 1078 setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); |
1077 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); | 1079 setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); |
1078 setfield_bool_if(L, "xfermode", !!paint->getXfermode()); | 1080 setfield_bool_if(L, "xfermode", !!paint->getXfermode()); |
1079 return 1; | 1081 return 1; |
1080 } | 1082 } |
1081 | 1083 |
| 1084 static int lpaint_getColorFilter(lua_State* L) { |
| 1085 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1086 SkColorFilter* cf = paint->getColorFilter(); |
| 1087 if (cf) { |
| 1088 push_ref(L, cf); |
| 1089 return 1; |
| 1090 } |
| 1091 return 0; |
| 1092 } |
| 1093 |
| 1094 static int lpaint_setColorFilter(lua_State* L) { |
| 1095 SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1096 paint->setColorFilter(get_ref<SkColorFilter>(L, 2)); |
| 1097 return 0; |
| 1098 } |
| 1099 |
1082 static int lpaint_getImageFilter(lua_State* L) { | 1100 static int lpaint_getImageFilter(lua_State* L) { |
1083 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1101 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
1084 SkImageFilter* imf = paint->getImageFilter(); | 1102 SkImageFilter* imf = paint->getImageFilter(); |
1085 if (imf) { | 1103 if (imf) { |
1086 push_ref(L, imf); | 1104 push_ref(L, imf); |
1087 return 1; | 1105 return 1; |
1088 } | 1106 } |
1089 return 0; | 1107 return 0; |
1090 } | 1108 } |
1091 | 1109 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 { "setStroke", lpaint_setStroke }, | 1181 { "setStroke", lpaint_setStroke }, |
1164 { "getStrokeCap", lpaint_getStrokeCap }, | 1182 { "getStrokeCap", lpaint_getStrokeCap }, |
1165 { "getStrokeJoin", lpaint_getStrokeJoin }, | 1183 { "getStrokeJoin", lpaint_getStrokeJoin }, |
1166 { "getTextEncoding", lpaint_getTextEncoding }, | 1184 { "getTextEncoding", lpaint_getTextEncoding }, |
1167 { "getStrokeWidth", lpaint_getStrokeWidth }, | 1185 { "getStrokeWidth", lpaint_getStrokeWidth }, |
1168 { "setStrokeWidth", lpaint_setStrokeWidth }, | 1186 { "setStrokeWidth", lpaint_setStrokeWidth }, |
1169 { "getStrokeMiter", lpaint_getStrokeMiter }, | 1187 { "getStrokeMiter", lpaint_getStrokeMiter }, |
1170 { "measureText", lpaint_measureText }, | 1188 { "measureText", lpaint_measureText }, |
1171 { "getFontMetrics", lpaint_getFontMetrics }, | 1189 { "getFontMetrics", lpaint_getFontMetrics }, |
1172 { "getEffects", lpaint_getEffects }, | 1190 { "getEffects", lpaint_getEffects }, |
| 1191 { "getColorFilter", lpaint_getColorFilter }, |
| 1192 { "setColorFilter", lpaint_setColorFilter }, |
1173 { "getImageFilter", lpaint_getImageFilter }, | 1193 { "getImageFilter", lpaint_getImageFilter }, |
1174 { "setImageFilter", lpaint_setImageFilter }, | 1194 { "setImageFilter", lpaint_setImageFilter }, |
1175 { "getShader", lpaint_getShader }, | 1195 { "getShader", lpaint_getShader }, |
1176 { "setShader", lpaint_setShader }, | 1196 { "setShader", lpaint_setShader }, |
1177 { "getPathEffect", lpaint_getPathEffect }, | 1197 { "getPathEffect", lpaint_getPathEffect }, |
1178 { "__gc", lpaint_gc }, | 1198 { "__gc", lpaint_gc }, |
1179 { nullptr, nullptr } | 1199 { nullptr, nullptr } |
1180 }; | 1200 }; |
1181 | 1201 |
1182 /////////////////////////////////////////////////////////////////////////////// | 1202 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 } | 1307 } |
1288 | 1308 |
1289 static const struct luaL_Reg gSkPathEffect_Methods[] = { | 1309 static const struct luaL_Reg gSkPathEffect_Methods[] = { |
1290 { "asADash", lpatheffect_asADash }, | 1310 { "asADash", lpatheffect_asADash }, |
1291 { "__gc", lpatheffect_gc }, | 1311 { "__gc", lpatheffect_gc }, |
1292 { nullptr, nullptr } | 1312 { nullptr, nullptr } |
1293 }; | 1313 }; |
1294 | 1314 |
1295 /////////////////////////////////////////////////////////////////////////////// | 1315 /////////////////////////////////////////////////////////////////////////////// |
1296 | 1316 |
| 1317 static int lpcolorfilter_gc(lua_State* L) { |
| 1318 get_ref<SkColorFilter>(L, 1)->unref(); |
| 1319 return 0; |
| 1320 } |
| 1321 |
| 1322 static const struct luaL_Reg gSkColorFilter_Methods[] = { |
| 1323 { "__gc", lpcolorfilter_gc }, |
| 1324 { nullptr, nullptr } |
| 1325 }; |
| 1326 |
| 1327 /////////////////////////////////////////////////////////////////////////////// |
| 1328 |
1297 static int lpimagefilter_gc(lua_State* L) { | 1329 static int lpimagefilter_gc(lua_State* L) { |
1298 get_ref<SkImageFilter>(L, 1)->unref(); | 1330 get_ref<SkImageFilter>(L, 1)->unref(); |
1299 return 0; | 1331 return 0; |
1300 } | 1332 } |
1301 | 1333 |
1302 static const struct luaL_Reg gSkImageFilter_Methods[] = { | 1334 static const struct luaL_Reg gSkImageFilter_Methods[] = { |
1303 { "__gc", lpimagefilter_gc }, | 1335 { "__gc", lpimagefilter_gc }, |
1304 { nullptr, nullptr } | 1336 { nullptr, nullptr } |
1305 }; | 1337 }; |
1306 | 1338 |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2041 luaL_newmetatable(L, get_mtname<C>()); \ | 2073 luaL_newmetatable(L, get_mtname<C>()); \ |
2042 lua_pushvalue(L, -1); \ | 2074 lua_pushvalue(L, -1); \ |
2043 lua_setfield(L, -2, "__index"); \ | 2075 lua_setfield(L, -2, "__index"); \ |
2044 luaL_setfuncs(L, g##C##_Methods, 0); \ | 2076 luaL_setfuncs(L, g##C##_Methods, 0); \ |
2045 lua_pop(L, 1); /* pop off the meta-table */ \ | 2077 lua_pop(L, 1); /* pop off the meta-table */ \ |
2046 } while (0) | 2078 } while (0) |
2047 | 2079 |
2048 void SkLua::Load(lua_State* L) { | 2080 void SkLua::Load(lua_State* L) { |
2049 register_Sk(L); | 2081 register_Sk(L); |
2050 REG_CLASS(L, SkCanvas); | 2082 REG_CLASS(L, SkCanvas); |
| 2083 REG_CLASS(L, SkColorFilter); |
2051 REG_CLASS(L, SkDocument); | 2084 REG_CLASS(L, SkDocument); |
2052 REG_CLASS(L, SkImage); | 2085 REG_CLASS(L, SkImage); |
2053 REG_CLASS(L, SkImageFilter); | 2086 REG_CLASS(L, SkImageFilter); |
2054 REG_CLASS(L, SkMatrix); | 2087 REG_CLASS(L, SkMatrix); |
2055 REG_CLASS(L, SkPaint); | 2088 REG_CLASS(L, SkPaint); |
2056 REG_CLASS(L, SkPath); | 2089 REG_CLASS(L, SkPath); |
2057 REG_CLASS(L, SkPathEffect); | 2090 REG_CLASS(L, SkPathEffect); |
2058 REG_CLASS(L, SkPicture); | 2091 REG_CLASS(L, SkPicture); |
2059 REG_CLASS(L, SkPictureRecorder); | 2092 REG_CLASS(L, SkPictureRecorder); |
2060 REG_CLASS(L, SkRRect); | 2093 REG_CLASS(L, SkRRect); |
2061 REG_CLASS(L, SkShader); | 2094 REG_CLASS(L, SkShader); |
2062 REG_CLASS(L, SkSurface); | 2095 REG_CLASS(L, SkSurface); |
2063 REG_CLASS(L, SkTextBlob); | 2096 REG_CLASS(L, SkTextBlob); |
2064 REG_CLASS(L, SkTypeface); | 2097 REG_CLASS(L, SkTypeface); |
2065 } | 2098 } |
2066 | 2099 |
2067 extern "C" int luaopen_skia(lua_State* L); | 2100 extern "C" int luaopen_skia(lua_State* L); |
2068 extern "C" int luaopen_skia(lua_State* L) { | 2101 extern "C" int luaopen_skia(lua_State* L) { |
2069 SkLua::Load(L); | 2102 SkLua::Load(L); |
2070 return 0; | 2103 return 0; |
2071 } | 2104 } |
OLD | NEW |