Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Unified Diff: src/utils/SkLua.cpp

Issue 1776973003: partial switch over to sp usage of shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move into lua container Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/glyph_pos_align.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkLua.cpp
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index dd746404015f4e13e676b1435f22502c85060fdc..b84ba0f5188e844c14d1c3805eb91f7f71f22d05 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -82,6 +82,12 @@ template <typename T> T* push_ref(lua_State* L, T* ref) {
return ref;
}
+template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) {
+ *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release();
+ luaL_getmetatable(L, get_mtname<T>());
+ lua_setmetatable(L, -2);
+}
+
template <typename T> T* get_ref(lua_State* L, int index) {
return *(T**)luaL_checkudata(L, index, get_mtname<T>());
}
@@ -1977,11 +1983,11 @@ static int lsk_newLinearGradient(lua_State* L) {
SkPoint pts[] = { { x0, y0 }, { x1, y1 } };
SkColor colors[] = { c0, c1 };
- SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
- if (nullptr == s) {
+ auto s = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
+ if (!s) {
lua_pushnil(L);
} else {
- push_ref(L, s)->unref();
+ push_ref(L, std::move(s));
}
return 1;
}
« no previous file with comments | « gm/glyph_pos_align.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698