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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 get_ref<SkCanvas>(L, 1)->translate(tx, ty); | 620 get_ref<SkCanvas>(L, 1)->translate(tx, ty); |
621 return 0; | 621 return 0; |
622 } | 622 } |
623 | 623 |
624 static int lcanvas_rotate(lua_State* L) { | 624 static int lcanvas_rotate(lua_State* L) { |
625 SkScalar degrees = lua2scalar_def(L, 2, 0); | 625 SkScalar degrees = lua2scalar_def(L, 2, 0); |
626 get_ref<SkCanvas>(L, 1)->rotate(degrees); | 626 get_ref<SkCanvas>(L, 1)->rotate(degrees); |
627 return 0; | 627 return 0; |
628 } | 628 } |
629 | 629 |
630 static int lcanvas_concat(lua_State* L) { | |
631 get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2)); | |
632 return 0; | |
633 } | |
634 | |
630 static int lcanvas_newSurface(lua_State* L) { | 635 static int lcanvas_newSurface(lua_State* L) { |
631 int width = lua2int_def(L, 2, 0); | 636 int width = lua2int_def(L, 2, 0); |
632 int height = lua2int_def(L, 2, 0); | 637 int height = lua2int_def(L, 2, 0); |
633 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 638 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
634 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info); | 639 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info); |
635 if (NULL == surface) { | 640 if (NULL == surface) { |
636 lua_pushnil(L); | 641 lua_pushnil(L); |
637 } else { | 642 } else { |
638 push_ref(L, surface); | 643 push_ref(L, surface); |
639 surface->unref(); | 644 surface->unref(); |
(...skipping 21 matching lines...) Expand all Loading... | |
661 { "getTotalMatrix", lcanvas_getTotalMatrix }, | 666 { "getTotalMatrix", lcanvas_getTotalMatrix }, |
662 { "getClipStack", lcanvas_getClipStack }, | 667 { "getClipStack", lcanvas_getClipStack }, |
663 #if SK_SUPPORT_GPU | 668 #if SK_SUPPORT_GPU |
664 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, | 669 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, |
665 #endif | 670 #endif |
666 { "save", lcanvas_save }, | 671 { "save", lcanvas_save }, |
667 { "restore", lcanvas_restore }, | 672 { "restore", lcanvas_restore }, |
668 { "scale", lcanvas_scale }, | 673 { "scale", lcanvas_scale }, |
669 { "translate", lcanvas_translate }, | 674 { "translate", lcanvas_translate }, |
670 { "rotate", lcanvas_rotate }, | 675 { "rotate", lcanvas_rotate }, |
676 { "concat", lcanvas_concat }, | |
671 | 677 |
672 { "newSurface", lcanvas_newSurface }, | 678 { "newSurface", lcanvas_newSurface }, |
673 | 679 |
674 { "__gc", lcanvas_gc }, | 680 { "__gc", lcanvas_gc }, |
675 { NULL, NULL } | 681 { NULL, NULL } |
676 }; | 682 }; |
677 | 683 |
678 /////////////////////////////////////////////////////////////////////////////// | 684 /////////////////////////////////////////////////////////////////////////////// |
679 | 685 |
680 static int ldocument_beginPage(lua_State* L) { | 686 static int ldocument_beginPage(lua_State* L) { |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 | 1180 |
1175 static int lmatrix_getTranslateX(lua_State* L) { | 1181 static int lmatrix_getTranslateX(lua_State* L) { |
1176 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX()); | 1182 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX()); |
1177 return 1; | 1183 return 1; |
1178 } | 1184 } |
1179 | 1185 |
1180 static int lmatrix_getTranslateY(lua_State* L) { | 1186 static int lmatrix_getTranslateY(lua_State* L) { |
1181 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY()); | 1187 lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY()); |
1182 return 1; | 1188 return 1; |
1183 } | 1189 } |
1184 | 1190 |
robertphillips
2014/10/14 16:33:14
Can we define constants in Lua and pass an int rat
| |
1191 static int lmatrix_setRectToRect(lua_State* L) { | |
1192 SkMatrix* matrix = get_obj<SkMatrix>(L, 1); | |
1193 SkRect srcR, dstR; | |
1194 lua2rect(L, 2, &srcR); | |
1195 lua2rect(L, 3, &dstR); | |
1196 const char* scaleToFitStr = lua_tostring(L, 4); | |
1197 SkMatrix::ScaleToFit scaleToFit = SkMatrix::kFill_ScaleToFit; | |
1198 | |
1199 if (scaleToFitStr) { | |
1200 const struct { | |
1201 const char* fName; | |
1202 SkMatrix::ScaleToFit fScaleToFit; | |
1203 } rec[] = { | |
1204 { "fill", SkMatrix::kFill_ScaleToFit }, | |
1205 { "start", SkMatrix::kStart_ScaleToFit }, | |
1206 { "center", SkMatrix::kCenter_ScaleToFit }, | |
1207 { "end", SkMatrix::kEnd_ScaleToFit }, | |
1208 }; | |
1209 | |
1210 for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { | |
1211 if (strcmp(rec[i].fName, scaleToFitStr) == 0) { | |
1212 scaleToFit = rec[i].fScaleToFit; | |
1213 break; | |
1214 } | |
1215 } | |
1216 } | |
1217 | |
1218 matrix->setRectToRect(srcR, dstR, scaleToFit); | |
1219 return 0; | |
1220 } | |
1221 | |
1185 static const struct luaL_Reg gSkMatrix_Methods[] = { | 1222 static const struct luaL_Reg gSkMatrix_Methods[] = { |
1186 { "getType", lmatrix_getType }, | 1223 { "getType", lmatrix_getType }, |
1187 { "getScaleX", lmatrix_getScaleX }, | 1224 { "getScaleX", lmatrix_getScaleX }, |
1188 { "getScaleY", lmatrix_getScaleY }, | 1225 { "getScaleY", lmatrix_getScaleY }, |
1189 { "getTranslateX", lmatrix_getTranslateX }, | 1226 { "getTranslateX", lmatrix_getTranslateX }, |
1190 { "getTranslateY", lmatrix_getTranslateY }, | 1227 { "getTranslateY", lmatrix_getTranslateY }, |
1228 { "setRectToRect", lmatrix_setRectToRect }, | |
1191 { NULL, NULL } | 1229 { NULL, NULL } |
1192 }; | 1230 }; |
1193 | 1231 |
1194 /////////////////////////////////////////////////////////////////////////////// | 1232 /////////////////////////////////////////////////////////////////////////////// |
1195 | 1233 |
1196 static int lpath_getBounds(lua_State* L) { | 1234 static int lpath_getBounds(lua_State* L) { |
1197 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); | 1235 SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); |
1198 return 1; | 1236 return 1; |
1199 } | 1237 } |
1200 | 1238 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1643 if (NULL == doc) { | 1681 if (NULL == doc) { |
1644 // do I need to push a nil on the stack and return 1? | 1682 // do I need to push a nil on the stack and return 1? |
1645 return 0; | 1683 return 0; |
1646 } else { | 1684 } else { |
1647 push_ref(L, doc); | 1685 push_ref(L, doc); |
1648 doc->unref(); | 1686 doc->unref(); |
1649 return 1; | 1687 return 1; |
1650 } | 1688 } |
1651 } | 1689 } |
1652 | 1690 |
1691 static int lsk_newMatrix(lua_State* L) { | |
1692 push_new<SkMatrix>(L)->reset(); | |
1693 return 1; | |
1694 } | |
1695 | |
1653 static int lsk_newPaint(lua_State* L) { | 1696 static int lsk_newPaint(lua_State* L) { |
1654 push_new<SkPaint>(L); | 1697 push_new<SkPaint>(L); |
1655 return 1; | 1698 return 1; |
1656 } | 1699 } |
1657 | 1700 |
1658 static int lsk_newPath(lua_State* L) { | 1701 static int lsk_newPath(lua_State* L) { |
1659 push_new<SkPath>(L); | 1702 push_new<SkPath>(L); |
1660 return 1; | 1703 return 1; |
1661 } | 1704 } |
1662 | 1705 |
1663 static int lsk_newPictureRecorder(lua_State* L) { | 1706 static int lsk_newPictureRecorder(lua_State* L) { |
1664 push_new<SkPictureRecorder>(L); | 1707 push_new<SkPictureRecorder>(L); |
1665 return 1; | 1708 return 1; |
1666 } | 1709 } |
1667 | 1710 |
1668 static int lsk_newRRect(lua_State* L) { | 1711 static int lsk_newRRect(lua_State* L) { |
1669 SkRRect* rr = push_new<SkRRect>(L); | 1712 push_new<SkRRect>(L)->setEmpty(); |
1670 rr->setEmpty(); | |
1671 return 1; | 1713 return 1; |
1672 } | 1714 } |
1673 | 1715 |
1674 static int lsk_newTypeface(lua_State* L) { | 1716 static int lsk_newTypeface(lua_State* L) { |
1675 const char* name = NULL; | 1717 const char* name = NULL; |
1676 int style = SkTypeface::kNormal; | 1718 int style = SkTypeface::kNormal; |
1677 | 1719 |
1678 int count = lua_gettop(L); | 1720 int count = lua_gettop(L); |
1679 if (count > 0 && lua_isstring(L, 1)) { | 1721 if (count > 0 && lua_isstring(L, 1)) { |
1680 name = lua_tolstring(L, 1, NULL); | 1722 name = lua_tolstring(L, 1, NULL); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1727 } | 1769 } |
1728 | 1770 |
1729 static void register_Sk(lua_State* L) { | 1771 static void register_Sk(lua_State* L) { |
1730 lua_newtable(L); | 1772 lua_newtable(L); |
1731 lua_pushvalue(L, -1); | 1773 lua_pushvalue(L, -1); |
1732 lua_setglobal(L, "Sk"); | 1774 lua_setglobal(L, "Sk"); |
1733 // the Sk table is still on top | 1775 // the Sk table is still on top |
1734 | 1776 |
1735 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); | 1777 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); |
1736 setfield_function(L, "loadImage", lsk_loadImage); | 1778 setfield_function(L, "loadImage", lsk_loadImage); |
1779 setfield_function(L, "newMatrix", lsk_newMatrix); | |
1737 setfield_function(L, "newPaint", lsk_newPaint); | 1780 setfield_function(L, "newPaint", lsk_newPaint); |
1738 setfield_function(L, "newPath", lsk_newPath); | 1781 setfield_function(L, "newPath", lsk_newPath); |
1739 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); | 1782 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); |
1740 setfield_function(L, "newRRect", lsk_newRRect); | 1783 setfield_function(L, "newRRect", lsk_newRRect); |
1741 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); | 1784 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); |
1742 setfield_function(L, "newTypeface", lsk_newTypeface); | 1785 setfield_function(L, "newTypeface", lsk_newTypeface); |
1743 lua_pop(L, 1); // pop off the Sk table | 1786 lua_pop(L, 1); // pop off the Sk table |
1744 } | 1787 } |
1745 | 1788 |
1746 #define REG_CLASS(L, C) \ | 1789 #define REG_CLASS(L, C) \ |
(...skipping 20 matching lines...) Expand all Loading... | |
1767 REG_CLASS(L, SkSurface); | 1810 REG_CLASS(L, SkSurface); |
1768 REG_CLASS(L, SkTypeface); | 1811 REG_CLASS(L, SkTypeface); |
1769 REG_CLASS(L, SkMatrix); | 1812 REG_CLASS(L, SkMatrix); |
1770 } | 1813 } |
1771 | 1814 |
1772 extern "C" int luaopen_skia(lua_State* L); | 1815 extern "C" int luaopen_skia(lua_State* L); |
1773 extern "C" int luaopen_skia(lua_State* L) { | 1816 extern "C" int luaopen_skia(lua_State* L) { |
1774 SkLua::Load(L); | 1817 SkLua::Load(L); |
1775 return 0; | 1818 return 0; |
1776 } | 1819 } |
OLD | NEW |