| 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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1749 // note: we don't unref canvas, since getCanvas did not ref it. | 1749 // note: we don't unref canvas, since getCanvas did not ref it. |
| 1750 // warning: this is weird: now Lua owns a ref on this canvas, but what i
f they let | 1750 // warning: this is weird: now Lua owns a ref on this canvas, but what i
f they let |
| 1751 // the real owner (the surface) go away, but still hold onto the canvas? | 1751 // the real owner (the surface) go away, but still hold onto the canvas? |
| 1752 // *really* we want to sort of ref the surface again, but have the nativ
e object | 1752 // *really* we want to sort of ref the surface again, but have the nativ
e object |
| 1753 // know that it is supposed to be treated as a canvas... | 1753 // know that it is supposed to be treated as a canvas... |
| 1754 } | 1754 } |
| 1755 return 1; | 1755 return 1; |
| 1756 } | 1756 } |
| 1757 | 1757 |
| 1758 static int lsurface_newImageSnapshot(lua_State* L) { | 1758 static int lsurface_newImageSnapshot(lua_State* L) { |
| 1759 SkImage* image = get_ref<SkSurface>(L, 1)->newImageSnapshot(); | 1759 sk_sp<SkImage> image = get_ref<SkSurface>(L, 1)->makeImageSnapshot(); |
| 1760 if (nullptr == image) { | 1760 if (!image) { |
| 1761 lua_pushnil(L); | 1761 lua_pushnil(L); |
| 1762 } else { | 1762 } else { |
| 1763 push_ref(L, image)->unref(); | 1763 push_ref(L, image); |
| 1764 } | 1764 } |
| 1765 return 1; | 1765 return 1; |
| 1766 } | 1766 } |
| 1767 | 1767 |
| 1768 static int lsurface_newSurface(lua_State* L) { | 1768 static int lsurface_newSurface(lua_State* L) { |
| 1769 int width = lua2int_def(L, 2, 0); | 1769 int width = lua2int_def(L, 2, 0); |
| 1770 int height = lua2int_def(L, 3, 0); | 1770 int height = lua2int_def(L, 3, 0); |
| 1771 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 1771 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
| 1772 SkSurface* surface = get_ref<SkSurface>(L, 1)->newSurface(info); | 1772 SkSurface* surface = get_ref<SkSurface>(L, 1)->newSurface(info); |
| 1773 if (nullptr == surface) { | 1773 if (nullptr == surface) { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 lua_pushnil(L); | 2068 lua_pushnil(L); |
| 2069 } else { | 2069 } else { |
| 2070 push_ref(L, surface)->unref(); | 2070 push_ref(L, surface)->unref(); |
| 2071 } | 2071 } |
| 2072 return 1; | 2072 return 1; |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 static int lsk_loadImage(lua_State* L) { | 2075 static int lsk_loadImage(lua_State* L) { |
| 2076 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { | 2076 if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { |
| 2077 const char* name = lua_tolstring(L, 1, nullptr); | 2077 const char* name = lua_tolstring(L, 1, nullptr); |
| 2078 SkAutoDataUnref data(SkData::NewFromFileName(name)); | 2078 sk_sp<SkData> data(SkData::MakeFromFileName(name)); |
| 2079 if (data.get()) { | 2079 if (data) { |
| 2080 SkImage* image = SkImage::NewFromEncoded(data); | 2080 auto image = SkImage::MakeFromEncoded(std::move(data)); |
| 2081 if (image) { | 2081 if (image) { |
| 2082 push_ref(L, image)->unref(); | 2082 push_ref(L, std::move(image)); |
| 2083 return 1; | 2083 return 1; |
| 2084 } | 2084 } |
| 2085 } | 2085 } |
| 2086 } | 2086 } |
| 2087 return 0; | 2087 return 0; |
| 2088 } | 2088 } |
| 2089 | 2089 |
| 2090 static void register_Sk(lua_State* L) { | 2090 static void register_Sk(lua_State* L) { |
| 2091 lua_newtable(L); | 2091 lua_newtable(L); |
| 2092 lua_pushvalue(L, -1); | 2092 lua_pushvalue(L, -1); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2136 REG_CLASS(L, SkTextBlob); | 2136 REG_CLASS(L, SkTextBlob); |
| 2137 REG_CLASS(L, SkTypeface); | 2137 REG_CLASS(L, SkTypeface); |
| 2138 REG_CLASS(L, SkXfermode); | 2138 REG_CLASS(L, SkXfermode); |
| 2139 } | 2139 } |
| 2140 | 2140 |
| 2141 extern "C" int luaopen_skia(lua_State* L); | 2141 extern "C" int luaopen_skia(lua_State* L); |
| 2142 extern "C" int luaopen_skia(lua_State* L) { | 2142 extern "C" int luaopen_skia(lua_State* L) { |
| 2143 SkLua::Load(L); | 2143 SkLua::Load(L); |
| 2144 return 0; | 2144 return 0; |
| 2145 } | 2145 } |
| OLD | NEW |