| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 static void setarray_number(lua_State* L, int index, double value) { | 215 static void setarray_number(lua_State* L, int index, double value) { |
| 216 lua_pushnumber(L, value); | 216 lua_pushnumber(L, value); |
| 217 lua_rawseti(L, -2, index); | 217 lua_rawseti(L, -2, index); |
| 218 } | 218 } |
| 219 | 219 |
| 220 static void setarray_scalar(lua_State* L, int index, SkScalar value) { | 220 static void setarray_scalar(lua_State* L, int index, SkScalar value) { |
| 221 setarray_number(L, index, SkScalarToLua(value)); | 221 setarray_number(L, index, SkScalarToLua(value)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 static void setarray_string(lua_State* L, int index, const char str[]) { |
| 225 lua_pushstring(L, str); |
| 226 lua_rawseti(L, -2, index); |
| 227 } |
| 228 |
| 224 void SkLua::pushBool(bool value, const char key[]) { | 229 void SkLua::pushBool(bool value, const char key[]) { |
| 225 lua_pushboolean(fL, value); | 230 lua_pushboolean(fL, value); |
| 226 CHECK_SETFIELD(key); | 231 CHECK_SETFIELD(key); |
| 227 } | 232 } |
| 228 | 233 |
| 229 void SkLua::pushString(const char str[], const char key[]) { | 234 void SkLua::pushString(const char str[], const char key[]) { |
| 230 lua_pushstring(fL, str); | 235 lua_pushstring(fL, str); |
| 231 CHECK_SETFIELD(key); | 236 CHECK_SETFIELD(key); |
| 232 } | 237 } |
| 233 | 238 |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 static int lpaint_getPathEffect(lua_State* L) { | 1157 static int lpaint_getPathEffect(lua_State* L) { |
| 1153 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1158 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1154 SkPathEffect* pe = paint->getPathEffect(); | 1159 SkPathEffect* pe = paint->getPathEffect(); |
| 1155 if (pe) { | 1160 if (pe) { |
| 1156 push_ref(L, pe); | 1161 push_ref(L, pe); |
| 1157 return 1; | 1162 return 1; |
| 1158 } | 1163 } |
| 1159 return 0; | 1164 return 0; |
| 1160 } | 1165 } |
| 1161 | 1166 |
| 1167 static int lpaint_getFillPath(lua_State* L) { |
| 1168 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1169 const SkPath* path = get_obj<SkPath>(L, 2); |
| 1170 |
| 1171 SkPath fillpath; |
| 1172 paint->getFillPath(*path, &fillpath); |
| 1173 |
| 1174 SkLua lua(L); |
| 1175 lua.pushPath(fillpath); |
| 1176 |
| 1177 return 1; |
| 1178 } |
| 1179 |
| 1162 static int lpaint_gc(lua_State* L) { | 1180 static int lpaint_gc(lua_State* L) { |
| 1163 get_obj<SkPaint>(L, 1)->~SkPaint(); | 1181 get_obj<SkPaint>(L, 1)->~SkPaint(); |
| 1164 return 0; | 1182 return 0; |
| 1165 } | 1183 } |
| 1166 | 1184 |
| 1167 static const struct luaL_Reg gSkPaint_Methods[] = { | 1185 static const struct luaL_Reg gSkPaint_Methods[] = { |
| 1168 { "isAntiAlias", lpaint_isAntiAlias }, | 1186 { "isAntiAlias", lpaint_isAntiAlias }, |
| 1169 { "setAntiAlias", lpaint_setAntiAlias }, | 1187 { "setAntiAlias", lpaint_setAntiAlias }, |
| 1170 { "isDither", lpaint_isDither }, | 1188 { "isDither", lpaint_isDither }, |
| 1171 { "setDither", lpaint_setDither }, | 1189 { "setDither", lpaint_setDither }, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 { "getEffects", lpaint_getEffects }, | 1228 { "getEffects", lpaint_getEffects }, |
| 1211 { "getColorFilter", lpaint_getColorFilter }, | 1229 { "getColorFilter", lpaint_getColorFilter }, |
| 1212 { "setColorFilter", lpaint_setColorFilter }, | 1230 { "setColorFilter", lpaint_setColorFilter }, |
| 1213 { "getImageFilter", lpaint_getImageFilter }, | 1231 { "getImageFilter", lpaint_getImageFilter }, |
| 1214 { "setImageFilter", lpaint_setImageFilter }, | 1232 { "setImageFilter", lpaint_setImageFilter }, |
| 1215 { "getXfermode", lpaint_getXfermode }, | 1233 { "getXfermode", lpaint_getXfermode }, |
| 1216 { "setXfermode", lpaint_setXfermode }, | 1234 { "setXfermode", lpaint_setXfermode }, |
| 1217 { "getShader", lpaint_getShader }, | 1235 { "getShader", lpaint_getShader }, |
| 1218 { "setShader", lpaint_setShader }, | 1236 { "setShader", lpaint_setShader }, |
| 1219 { "getPathEffect", lpaint_getPathEffect }, | 1237 { "getPathEffect", lpaint_getPathEffect }, |
| 1238 { "getFillPath", lpaint_getFillPath }, |
| 1220 { "__gc", lpaint_gc }, | 1239 { "__gc", lpaint_gc }, |
| 1221 { nullptr, nullptr } | 1240 { nullptr, nullptr } |
| 1222 }; | 1241 }; |
| 1223 | 1242 |
| 1224 /////////////////////////////////////////////////////////////////////////////// | 1243 /////////////////////////////////////////////////////////////////////////////// |
| 1225 | 1244 |
| 1226 static const char* mode2string(SkShader::TileMode mode) { | 1245 static const char* mode2string(SkShader::TileMode mode) { |
| 1227 static const char* gNames[] = { "clamp", "repeat", "mirror" }; | 1246 static const char* gNames[] = { "clamp", "repeat", "mirror" }; |
| 1228 SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames)); | 1247 SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames)); |
| 1229 return gNames[mode]; | 1248 return gNames[mode]; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 ret_count += 4; | 1598 ret_count += 4; |
| 1580 } | 1599 } |
| 1581 return ret_count; | 1600 return ret_count; |
| 1582 } | 1601 } |
| 1583 | 1602 |
| 1584 static int lpath_countPoints(lua_State* L) { | 1603 static int lpath_countPoints(lua_State* L) { |
| 1585 lua_pushinteger(L, get_obj<SkPath>(L, 1)->countPoints()); | 1604 lua_pushinteger(L, get_obj<SkPath>(L, 1)->countPoints()); |
| 1586 return 1; | 1605 return 1; |
| 1587 } | 1606 } |
| 1588 | 1607 |
| 1608 static int lpath_getVerbs(lua_State* L) { |
| 1609 const SkPath* path = get_obj<SkPath>(L, 1); |
| 1610 SkPath::Iter iter(*path, false); |
| 1611 SkPoint pts[4]; |
| 1612 |
| 1613 lua_newtable(L); |
| 1614 |
| 1615 bool done = false; |
| 1616 int i = 0; |
| 1617 do { |
| 1618 switch (iter.next(pts, true)) { |
| 1619 case SkPath::kMove_Verb: |
| 1620 setarray_string(L, ++i, "move"); |
| 1621 break; |
| 1622 case SkPath::kClose_Verb: |
| 1623 setarray_string(L, ++i, "close"); |
| 1624 break; |
| 1625 case SkPath::kLine_Verb: |
| 1626 setarray_string(L, ++i, "line"); |
| 1627 break; |
| 1628 case SkPath::kQuad_Verb: |
| 1629 setarray_string(L, ++i, "quad"); |
| 1630 break; |
| 1631 case SkPath::kConic_Verb: |
| 1632 setarray_string(L, ++i, "conic"); |
| 1633 break; |
| 1634 case SkPath::kCubic_Verb: |
| 1635 setarray_string(L, ++i, "cubic"); |
| 1636 break; |
| 1637 case SkPath::kDone_Verb: |
| 1638 setarray_string(L, ++i, "done"); |
| 1639 done = true; |
| 1640 break; |
| 1641 } |
| 1642 } while (!done); |
| 1643 |
| 1644 return 1; |
| 1645 } |
| 1646 |
| 1589 static int lpath_reset(lua_State* L) { | 1647 static int lpath_reset(lua_State* L) { |
| 1590 get_obj<SkPath>(L, 1)->reset(); | 1648 get_obj<SkPath>(L, 1)->reset(); |
| 1591 return 0; | 1649 return 0; |
| 1592 } | 1650 } |
| 1593 | 1651 |
| 1594 static int lpath_moveTo(lua_State* L) { | 1652 static int lpath_moveTo(lua_State* L) { |
| 1595 get_obj<SkPath>(L, 1)->moveTo(lua2scalar(L, 2), lua2scalar(L, 3)); | 1653 get_obj<SkPath>(L, 1)->moveTo(lua2scalar(L, 2), lua2scalar(L, 3)); |
| 1596 return 0; | 1654 return 0; |
| 1597 } | 1655 } |
| 1598 | 1656 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1621 | 1679 |
| 1622 static int lpath_gc(lua_State* L) { | 1680 static int lpath_gc(lua_State* L) { |
| 1623 get_obj<SkPath>(L, 1)->~SkPath(); | 1681 get_obj<SkPath>(L, 1)->~SkPath(); |
| 1624 return 0; | 1682 return 0; |
| 1625 } | 1683 } |
| 1626 | 1684 |
| 1627 static const struct luaL_Reg gSkPath_Methods[] = { | 1685 static const struct luaL_Reg gSkPath_Methods[] = { |
| 1628 { "getBounds", lpath_getBounds }, | 1686 { "getBounds", lpath_getBounds }, |
| 1629 { "getFillType", lpath_getFillType }, | 1687 { "getFillType", lpath_getFillType }, |
| 1630 { "getSegmentTypes", lpath_getSegmentTypes }, | 1688 { "getSegmentTypes", lpath_getSegmentTypes }, |
| 1689 { "getVerbs", lpath_getVerbs }, |
| 1631 { "isConvex", lpath_isConvex }, | 1690 { "isConvex", lpath_isConvex }, |
| 1632 { "isEmpty", lpath_isEmpty }, | 1691 { "isEmpty", lpath_isEmpty }, |
| 1633 { "isRect", lpath_isRect }, | 1692 { "isRect", lpath_isRect }, |
| 1634 { "isNestedFillRects", lpath_isNestedFillRects }, | 1693 { "isNestedFillRects", lpath_isNestedFillRects }, |
| 1635 { "countPoints", lpath_countPoints }, | 1694 { "countPoints", lpath_countPoints }, |
| 1636 { "reset", lpath_reset }, | 1695 { "reset", lpath_reset }, |
| 1637 { "moveTo", lpath_moveTo }, | 1696 { "moveTo", lpath_moveTo }, |
| 1638 { "lineTo", lpath_lineTo }, | 1697 { "lineTo", lpath_lineTo }, |
| 1639 { "quadTo", lpath_quadTo }, | 1698 { "quadTo", lpath_quadTo }, |
| 1640 { "cubicTo", lpath_cubicTo }, | 1699 { "cubicTo", lpath_cubicTo }, |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 REG_CLASS(L, SkTextBlob); | 2194 REG_CLASS(L, SkTextBlob); |
| 2136 REG_CLASS(L, SkTypeface); | 2195 REG_CLASS(L, SkTypeface); |
| 2137 REG_CLASS(L, SkXfermode); | 2196 REG_CLASS(L, SkXfermode); |
| 2138 } | 2197 } |
| 2139 | 2198 |
| 2140 extern "C" int luaopen_skia(lua_State* L); | 2199 extern "C" int luaopen_skia(lua_State* L); |
| 2141 extern "C" int luaopen_skia(lua_State* L) { | 2200 extern "C" int luaopen_skia(lua_State* L) { |
| 2142 SkLua::Load(L); | 2201 SkLua::Load(L); |
| 2143 return 0; | 2202 return 0; |
| 2144 } | 2203 } |
| OLD | NEW |