| 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 "SkData.h" | 16 #include "SkData.h" |
| 17 #include "SkDecodingImageGenerator.h" | 17 #include "SkDecodingImageGenerator.h" |
| 18 #include "SkDocument.h" | 18 #include "SkDocument.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" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 lua_setmetatable(L, -2); | 65 lua_setmetatable(L, -2); |
| 65 return addr; | 66 return addr; |
| 66 } | 67 } |
| 67 | 68 |
| 68 template <typename T> void push_obj(lua_State* L, const T& obj) { | 69 template <typename T> void push_obj(lua_State* L, const T& obj) { |
| 69 new (lua_newuserdata(L, sizeof(T))) T(obj); | 70 new (lua_newuserdata(L, sizeof(T))) T(obj); |
| 70 luaL_getmetatable(L, get_mtname<T>()); | 71 luaL_getmetatable(L, get_mtname<T>()); |
| 71 lua_setmetatable(L, -2); | 72 lua_setmetatable(L, -2); |
| 72 } | 73 } |
| 73 | 74 |
| 74 template <typename T> void push_ref(lua_State* L, T* ref) { | 75 template <typename T> T* push_ref(lua_State* L, T* ref) { |
| 75 *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref); | 76 *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref); |
| 76 luaL_getmetatable(L, get_mtname<T>()); | 77 luaL_getmetatable(L, get_mtname<T>()); |
| 77 lua_setmetatable(L, -2); | 78 lua_setmetatable(L, -2); |
| 79 return ref; |
| 78 } | 80 } |
| 79 | 81 |
| 80 template <typename T> T* get_ref(lua_State* L, int index) { | 82 template <typename T> T* get_ref(lua_State* L, int index) { |
| 81 return *(T**)luaL_checkudata(L, index, get_mtname<T>()); | 83 return *(T**)luaL_checkudata(L, index, get_mtname<T>()); |
| 82 } | 84 } |
| 83 | 85 |
| 84 template <typename T> T* get_obj(lua_State* L, int index) { | 86 template <typename T> T* get_obj(lua_State* L, int index) { |
| 85 return (T*)luaL_checkudata(L, index, get_mtname<T>()); | 87 return (T*)luaL_checkudata(L, index, get_mtname<T>()); |
| 86 } | 88 } |
| 87 | 89 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 static int lcanvas_clear(lua_State* L) { | 438 static int lcanvas_clear(lua_State* L) { |
| 437 get_ref<SkCanvas>(L, 1)->clear(0); | 439 get_ref<SkCanvas>(L, 1)->clear(0); |
| 438 return 0; | 440 return 0; |
| 439 } | 441 } |
| 440 | 442 |
| 441 static int lcanvas_drawColor(lua_State* L) { | 443 static int lcanvas_drawColor(lua_State* L) { |
| 442 get_ref<SkCanvas>(L, 1)->drawColor(lua2color(L, 2)); | 444 get_ref<SkCanvas>(L, 1)->drawColor(lua2color(L, 2)); |
| 443 return 0; | 445 return 0; |
| 444 } | 446 } |
| 445 | 447 |
| 448 static int lcanvas_drawPaint(lua_State* L) { |
| 449 get_ref<SkCanvas>(L, 1)->drawPaint(*get_obj<SkPaint>(L, 2)); |
| 450 return 0; |
| 451 } |
| 452 |
| 446 static int lcanvas_drawRect(lua_State* L) { | 453 static int lcanvas_drawRect(lua_State* L) { |
| 447 SkRect rect; | 454 SkRect rect; |
| 448 get_ref<SkCanvas>(L, 1)->drawRect(*lua2rect(L, 2, &rect), | 455 get_ref<SkCanvas>(L, 1)->drawRect(*lua2rect(L, 2, &rect), |
| 449 *get_obj<SkPaint>(L, 3)); | 456 *get_obj<SkPaint>(L, 3)); |
| 450 return 0; | 457 return 0; |
| 451 } | 458 } |
| 452 | 459 |
| 453 static int lcanvas_drawOval(lua_State* L) { | 460 static int lcanvas_drawOval(lua_State* L) { |
| 454 SkRect rect; | 461 SkRect rect; |
| 455 get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect), | 462 get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect), |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 } | 646 } |
| 640 | 647 |
| 641 static int lcanvas_newSurface(lua_State* L) { | 648 static int lcanvas_newSurface(lua_State* L) { |
| 642 int width = lua2int_def(L, 2, 0); | 649 int width = lua2int_def(L, 2, 0); |
| 643 int height = lua2int_def(L, 2, 0); | 650 int height = lua2int_def(L, 2, 0); |
| 644 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 651 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 645 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info); | 652 SkSurface* surface = get_ref<SkCanvas>(L, 1)->newSurface(info); |
| 646 if (NULL == surface) { | 653 if (NULL == surface) { |
| 647 lua_pushnil(L); | 654 lua_pushnil(L); |
| 648 } else { | 655 } else { |
| 649 push_ref(L, surface); | 656 push_ref(L, surface)->unref(); |
| 650 surface->unref(); | |
| 651 } | 657 } |
| 652 return 1; | 658 return 1; |
| 653 } | 659 } |
| 654 | 660 |
| 655 static int lcanvas_gc(lua_State* L) { | 661 static int lcanvas_gc(lua_State* L) { |
| 656 get_ref<SkCanvas>(L, 1)->unref(); | 662 get_ref<SkCanvas>(L, 1)->unref(); |
| 657 return 0; | 663 return 0; |
| 658 } | 664 } |
| 659 | 665 |
| 660 const struct luaL_Reg gSkCanvas_Methods[] = { | 666 const struct luaL_Reg gSkCanvas_Methods[] = { |
| 661 { "clear", lcanvas_clear }, | 667 { "clear", lcanvas_clear }, |
| 662 { "drawColor", lcanvas_drawColor }, | 668 { "drawColor", lcanvas_drawColor }, |
| 669 { "drawPaint", lcanvas_drawPaint }, |
| 663 { "drawRect", lcanvas_drawRect }, | 670 { "drawRect", lcanvas_drawRect }, |
| 664 { "drawOval", lcanvas_drawOval }, | 671 { "drawOval", lcanvas_drawOval }, |
| 665 { "drawCircle", lcanvas_drawCircle }, | 672 { "drawCircle", lcanvas_drawCircle }, |
| 666 { "drawImage", lcanvas_drawImage }, | 673 { "drawImage", lcanvas_drawImage }, |
| 667 { "drawImageRect", lcanvas_drawImageRect }, | 674 { "drawImageRect", lcanvas_drawImageRect }, |
| 668 { "drawPath", lcanvas_drawPath }, | 675 { "drawPath", lcanvas_drawPath }, |
| 669 { "drawPicture", lcanvas_drawPicture }, | 676 { "drawPicture", lcanvas_drawPicture }, |
| 670 { "drawText", lcanvas_drawText }, | 677 { "drawText", lcanvas_drawText }, |
| 671 { "getSaveCount", lcanvas_getSaveCount }, | 678 { "getSaveCount", lcanvas_getSaveCount }, |
| 672 { "getTotalMatrix", lcanvas_getTotalMatrix }, | 679 { "getTotalMatrix", lcanvas_getTotalMatrix }, |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 static int lpaint_getShader(lua_State* L) { | 1012 static int lpaint_getShader(lua_State* L) { |
| 1006 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1013 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1007 SkShader* shader = paint->getShader(); | 1014 SkShader* shader = paint->getShader(); |
| 1008 if (shader) { | 1015 if (shader) { |
| 1009 push_ref(L, shader); | 1016 push_ref(L, shader); |
| 1010 return 1; | 1017 return 1; |
| 1011 } | 1018 } |
| 1012 return 0; | 1019 return 0; |
| 1013 } | 1020 } |
| 1014 | 1021 |
| 1022 static int lpaint_setShader(lua_State* L) { |
| 1023 SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1024 paint->setShader(get_ref<SkShader>(L, 2)); |
| 1025 return 0; |
| 1026 } |
| 1027 |
| 1015 static int lpaint_getPathEffect(lua_State* L) { | 1028 static int lpaint_getPathEffect(lua_State* L) { |
| 1016 const SkPaint* paint = get_obj<SkPaint>(L, 1); | 1029 const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 1017 SkPathEffect* pe = paint->getPathEffect(); | 1030 SkPathEffect* pe = paint->getPathEffect(); |
| 1018 if (pe) { | 1031 if (pe) { |
| 1019 push_ref(L, pe); | 1032 push_ref(L, pe); |
| 1020 return 1; | 1033 return 1; |
| 1021 } | 1034 } |
| 1022 return 0; | 1035 return 0; |
| 1023 } | 1036 } |
| 1024 | 1037 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 { "getTextEncoding", lpaint_getTextEncoding }, | 1076 { "getTextEncoding", lpaint_getTextEncoding }, |
| 1064 { "getStrokeWidth", lpaint_getStrokeWidth }, | 1077 { "getStrokeWidth", lpaint_getStrokeWidth }, |
| 1065 { "setStrokeWidth", lpaint_setStrokeWidth }, | 1078 { "setStrokeWidth", lpaint_setStrokeWidth }, |
| 1066 { "getStrokeMiter", lpaint_getStrokeMiter }, | 1079 { "getStrokeMiter", lpaint_getStrokeMiter }, |
| 1067 { "measureText", lpaint_measureText }, | 1080 { "measureText", lpaint_measureText }, |
| 1068 { "getFontMetrics", lpaint_getFontMetrics }, | 1081 { "getFontMetrics", lpaint_getFontMetrics }, |
| 1069 { "getEffects", lpaint_getEffects }, | 1082 { "getEffects", lpaint_getEffects }, |
| 1070 { "getImageFilter", lpaint_getImageFilter }, | 1083 { "getImageFilter", lpaint_getImageFilter }, |
| 1071 { "setImageFilter", lpaint_setImageFilter }, | 1084 { "setImageFilter", lpaint_setImageFilter }, |
| 1072 { "getShader", lpaint_getShader }, | 1085 { "getShader", lpaint_getShader }, |
| 1086 { "setShader", lpaint_setShader }, |
| 1073 { "getPathEffect", lpaint_getPathEffect }, | 1087 { "getPathEffect", lpaint_getPathEffect }, |
| 1074 { "__gc", lpaint_gc }, | 1088 { "__gc", lpaint_gc }, |
| 1075 { NULL, NULL } | 1089 { NULL, NULL } |
| 1076 }; | 1090 }; |
| 1077 | 1091 |
| 1078 /////////////////////////////////////////////////////////////////////////////// | 1092 /////////////////////////////////////////////////////////////////////////////// |
| 1079 | 1093 |
| 1080 static const char* mode2string(SkShader::TileMode mode) { | 1094 static const char* mode2string(SkShader::TileMode mode) { |
| 1081 static const char* gNames[] = { "clamp", "repeat", "mirror" }; | 1095 static const char* gNames[] = { "clamp", "repeat", "mirror" }; |
| 1082 SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames)); | 1096 SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames)); |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1557 // know that it is supposed to be treated as a canvas... | 1571 // know that it is supposed to be treated as a canvas... |
| 1558 } | 1572 } |
| 1559 return 1; | 1573 return 1; |
| 1560 } | 1574 } |
| 1561 | 1575 |
| 1562 static int lsurface_newImageSnapshot(lua_State* L) { | 1576 static int lsurface_newImageSnapshot(lua_State* L) { |
| 1563 SkImage* image = get_ref<SkSurface>(L, 1)->newImageSnapshot(); | 1577 SkImage* image = get_ref<SkSurface>(L, 1)->newImageSnapshot(); |
| 1564 if (NULL == image) { | 1578 if (NULL == image) { |
| 1565 lua_pushnil(L); | 1579 lua_pushnil(L); |
| 1566 } else { | 1580 } else { |
| 1567 push_ref(L, image); | 1581 push_ref(L, image)->unref(); |
| 1568 image->unref(); | |
| 1569 } | 1582 } |
| 1570 return 1; | 1583 return 1; |
| 1571 } | 1584 } |
| 1572 | 1585 |
| 1573 static int lsurface_newSurface(lua_State* L) { | 1586 static int lsurface_newSurface(lua_State* L) { |
| 1574 int width = lua2int_def(L, 2, 0); | 1587 int width = lua2int_def(L, 2, 0); |
| 1575 int height = lua2int_def(L, 3, 0); | 1588 int height = lua2int_def(L, 3, 0); |
| 1576 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 1589 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1577 SkSurface* surface = get_ref<SkSurface>(L, 1)->newSurface(info); | 1590 SkSurface* surface = get_ref<SkSurface>(L, 1)->newSurface(info); |
| 1578 if (NULL == surface) { | 1591 if (NULL == surface) { |
| 1579 lua_pushnil(L); | 1592 lua_pushnil(L); |
| 1580 } else { | 1593 } else { |
| 1581 push_ref(L, surface); | 1594 push_ref(L, surface)->unref(); |
| 1582 surface->unref(); | |
| 1583 } | 1595 } |
| 1584 return 1; | 1596 return 1; |
| 1585 } | 1597 } |
| 1586 | 1598 |
| 1587 static int lsurface_gc(lua_State* L) { | 1599 static int lsurface_gc(lua_State* L) { |
| 1588 get_ref<SkSurface>(L, 1)->unref(); | 1600 get_ref<SkSurface>(L, 1)->unref(); |
| 1589 return 0; | 1601 return 0; |
| 1590 } | 1602 } |
| 1591 | 1603 |
| 1592 static const struct luaL_Reg gSkSurface_Methods[] = { | 1604 static const struct luaL_Reg gSkSurface_Methods[] = { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 push_ref(L, canvas); | 1640 push_ref(L, canvas); |
| 1629 return 1; | 1641 return 1; |
| 1630 } | 1642 } |
| 1631 | 1643 |
| 1632 static int lpicturerecorder_endRecording(lua_State* L) { | 1644 static int lpicturerecorder_endRecording(lua_State* L) { |
| 1633 SkPicture* pic = get_obj<SkPictureRecorder>(L, 1)->endRecording(); | 1645 SkPicture* pic = get_obj<SkPictureRecorder>(L, 1)->endRecording(); |
| 1634 if (NULL == pic) { | 1646 if (NULL == pic) { |
| 1635 lua_pushnil(L); | 1647 lua_pushnil(L); |
| 1636 return 1; | 1648 return 1; |
| 1637 } | 1649 } |
| 1638 push_ref(L, pic); | 1650 push_ref(L, pic)->unref(); |
| 1639 pic->unref(); // lua is the only owner, so we unref ours | |
| 1640 return 1; | 1651 return 1; |
| 1641 } | 1652 } |
| 1642 | 1653 |
| 1643 static int lpicturerecorder_gc(lua_State* L) { | 1654 static int lpicturerecorder_gc(lua_State* L) { |
| 1644 get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder(); | 1655 get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder(); |
| 1645 return 0; | 1656 return 0; |
| 1646 } | 1657 } |
| 1647 | 1658 |
| 1648 static const struct luaL_Reg gSkPictureRecorder_Methods[] = { | 1659 static const struct luaL_Reg gSkPictureRecorder_Methods[] = { |
| 1649 { "beginRecording", lpicturerecorder_beginRecording }, | 1660 { "beginRecording", lpicturerecorder_beginRecording }, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 const char* file = NULL; | 1734 const char* file = NULL; |
| 1724 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { | 1735 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { |
| 1725 file = lua_tolstring(L, 1, NULL); | 1736 file = lua_tolstring(L, 1, NULL); |
| 1726 } | 1737 } |
| 1727 | 1738 |
| 1728 SkDocument* doc = SkDocument::CreatePDF(file); | 1739 SkDocument* doc = SkDocument::CreatePDF(file); |
| 1729 if (NULL == doc) { | 1740 if (NULL == doc) { |
| 1730 // do I need to push a nil on the stack and return 1? | 1741 // do I need to push a nil on the stack and return 1? |
| 1731 return 0; | 1742 return 0; |
| 1732 } else { | 1743 } else { |
| 1733 push_ref(L, doc); | 1744 push_ref(L, doc)->unref(); |
| 1734 doc->unref(); | |
| 1735 return 1; | 1745 return 1; |
| 1736 } | 1746 } |
| 1737 } | 1747 } |
| 1738 | 1748 |
| 1739 static int lsk_newBlurImageFilter(lua_State* L) { | 1749 static int lsk_newBlurImageFilter(lua_State* L) { |
| 1740 SkScalar sigmaX = lua2scalar_def(L, 1, 0); | 1750 SkScalar sigmaX = lua2scalar_def(L, 1, 0); |
| 1741 SkScalar sigmaY = lua2scalar_def(L, 2, 0); | 1751 SkScalar sigmaY = lua2scalar_def(L, 2, 0); |
| 1742 SkImageFilter* imf = SkBlurImageFilter::Create(sigmaX, sigmaY); | 1752 SkImageFilter* imf = SkBlurImageFilter::Create(sigmaX, sigmaY); |
| 1743 if (NULL == imf) { | 1753 if (NULL == imf) { |
| 1744 lua_pushnil(L); | 1754 lua_pushnil(L); |
| 1745 } else { | 1755 } else { |
| 1746 push_ref(L, imf); | 1756 push_ref(L, imf)->unref(); |
| 1747 imf->unref(); | |
| 1748 } | 1757 } |
| 1749 return 1; | 1758 return 1; |
| 1750 } | 1759 } |
| 1760 |
| 1761 static int lsk_newLinearGradient(lua_State* L) { |
| 1762 SkScalar x0 = lua2scalar_def(L, 1, 0); |
| 1763 SkScalar y0 = lua2scalar_def(L, 2, 0); |
| 1764 SkColor c0 = lua2color(L, 3); |
| 1765 SkScalar x1 = lua2scalar_def(L, 4, 0); |
| 1766 SkScalar y1 = lua2scalar_def(L, 5, 0); |
| 1767 SkColor c1 = lua2color(L, 6); |
| 1768 |
| 1769 SkPoint pts[] = { { x0, y0 }, { x1, y1 } }; |
| 1770 SkColor colors[] = { c0, c1 }; |
| 1771 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader:
:kClamp_TileMode); |
| 1772 if (NULL == s) { |
| 1773 lua_pushnil(L); |
| 1774 } else { |
| 1775 push_ref(L, s)->unref(); |
| 1776 } |
| 1777 return 1; |
| 1778 } |
| 1751 | 1779 |
| 1752 static int lsk_newMatrix(lua_State* L) { | 1780 static int lsk_newMatrix(lua_State* L) { |
| 1753 push_new<SkMatrix>(L)->reset(); | 1781 push_new<SkMatrix>(L)->reset(); |
| 1754 return 1; | 1782 return 1; |
| 1755 } | 1783 } |
| 1756 | 1784 |
| 1757 static int lsk_newPaint(lua_State* L) { | 1785 static int lsk_newPaint(lua_State* L) { |
| 1758 push_new<SkPaint>(L); | 1786 push_new<SkPaint>(L); |
| 1759 return 1; | 1787 return 1; |
| 1760 } | 1788 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1785 style = lua_tointegerx(L, 2, NULL) & SkTypeface::kBoldItalic; | 1813 style = lua_tointegerx(L, 2, NULL) & SkTypeface::kBoldItalic; |
| 1786 } | 1814 } |
| 1787 } | 1815 } |
| 1788 | 1816 |
| 1789 SkTypeface* face = SkTypeface::CreateFromName(name, | 1817 SkTypeface* face = SkTypeface::CreateFromName(name, |
| 1790 (SkTypeface::Style)style); | 1818 (SkTypeface::Style)style); |
| 1791 // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, f
ace->getRefCnt()); | 1819 // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, f
ace->getRefCnt()); |
| 1792 if (NULL == face) { | 1820 if (NULL == face) { |
| 1793 face = SkTypeface::RefDefault(); | 1821 face = SkTypeface::RefDefault(); |
| 1794 } | 1822 } |
| 1795 push_ref(L, face); | 1823 push_ref(L, face)->unref(); |
| 1796 face->unref(); | |
| 1797 return 1; | 1824 return 1; |
| 1798 } | 1825 } |
| 1799 | 1826 |
| 1800 static int lsk_newRasterSurface(lua_State* L) { | 1827 static int lsk_newRasterSurface(lua_State* L) { |
| 1801 int width = lua2int_def(L, 2, 0); | 1828 int width = lua2int_def(L, 2, 0); |
| 1802 int height = lua2int_def(L, 2, 0); | 1829 int height = lua2int_def(L, 2, 0); |
| 1803 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 1830 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1804 SkSurface* surface = SkSurface::NewRaster(info); | 1831 SkSurface* surface = SkSurface::NewRaster(info); |
| 1805 if (NULL == surface) { | 1832 if (NULL == surface) { |
| 1806 lua_pushnil(L); | 1833 lua_pushnil(L); |
| 1807 } else { | 1834 } else { |
| 1808 push_ref(L, surface); | 1835 push_ref(L, surface)->unref(); |
| 1809 surface->unref(); | |
| 1810 } | 1836 } |
| 1811 return 1; | 1837 return 1; |
| 1812 } | 1838 } |
| 1813 | 1839 |
| 1814 static int lsk_loadImage(lua_State* L) { | 1840 static int lsk_loadImage(lua_State* L) { |
| 1815 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { | 1841 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { |
| 1816 const char* name = lua_tolstring(L, 1, NULL); | 1842 const char* name = lua_tolstring(L, 1, NULL); |
| 1817 SkAutoDataUnref data(SkData::NewFromFileName(name)); | 1843 SkAutoDataUnref data(SkData::NewFromFileName(name)); |
| 1818 if (data.get()) { | 1844 if (data.get()) { |
| 1819 SkImage* image = SkImage::NewFromGenerator( | 1845 SkImage* image = SkImage::NewFromGenerator( |
| 1820 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator:
:Options())); | 1846 SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator:
:Options())); |
| 1821 | 1847 |
| 1822 if (image) { | 1848 if (image) { |
| 1823 push_ref(L, image); | 1849 push_ref(L, image)->unref(); |
| 1824 image->unref(); | |
| 1825 return 1; | 1850 return 1; |
| 1826 } | 1851 } |
| 1827 } | 1852 } |
| 1828 } | 1853 } |
| 1829 return 0; | 1854 return 0; |
| 1830 } | 1855 } |
| 1831 | 1856 |
| 1832 static void register_Sk(lua_State* L) { | 1857 static void register_Sk(lua_State* L) { |
| 1833 lua_newtable(L); | 1858 lua_newtable(L); |
| 1834 lua_pushvalue(L, -1); | 1859 lua_pushvalue(L, -1); |
| 1835 lua_setglobal(L, "Sk"); | 1860 lua_setglobal(L, "Sk"); |
| 1836 // the Sk table is still on top | 1861 // the Sk table is still on top |
| 1837 | 1862 |
| 1838 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); | 1863 setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); |
| 1839 setfield_function(L, "loadImage", lsk_loadImage); | 1864 setfield_function(L, "loadImage", lsk_loadImage); |
| 1840 setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter); | 1865 setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter); |
| 1866 setfield_function(L, "newLinearGradient", lsk_newLinearGradient); |
| 1841 setfield_function(L, "newMatrix", lsk_newMatrix); | 1867 setfield_function(L, "newMatrix", lsk_newMatrix); |
| 1842 setfield_function(L, "newPaint", lsk_newPaint); | 1868 setfield_function(L, "newPaint", lsk_newPaint); |
| 1843 setfield_function(L, "newPath", lsk_newPath); | 1869 setfield_function(L, "newPath", lsk_newPath); |
| 1844 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); | 1870 setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); |
| 1845 setfield_function(L, "newRRect", lsk_newRRect); | 1871 setfield_function(L, "newRRect", lsk_newRRect); |
| 1846 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); | 1872 setfield_function(L, "newRasterSurface", lsk_newRasterSurface); |
| 1847 setfield_function(L, "newTypeface", lsk_newTypeface); | 1873 setfield_function(L, "newTypeface", lsk_newTypeface); |
| 1848 lua_pop(L, 1); // pop off the Sk table | 1874 lua_pop(L, 1); // pop off the Sk table |
| 1849 } | 1875 } |
| 1850 | 1876 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1873 REG_CLASS(L, SkSurface); | 1899 REG_CLASS(L, SkSurface); |
| 1874 REG_CLASS(L, SkTypeface); | 1900 REG_CLASS(L, SkTypeface); |
| 1875 REG_CLASS(L, SkMatrix); | 1901 REG_CLASS(L, SkMatrix); |
| 1876 } | 1902 } |
| 1877 | 1903 |
| 1878 extern "C" int luaopen_skia(lua_State* L); | 1904 extern "C" int luaopen_skia(lua_State* L); |
| 1879 extern "C" int luaopen_skia(lua_State* L) { | 1905 extern "C" int luaopen_skia(lua_State* L) { |
| 1880 SkLua::Load(L); | 1906 SkLua::Load(L); |
| 1881 return 0; | 1907 return 0; |
| 1882 } | 1908 } |
| OLD | NEW |