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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « gm/glyph_pos_align.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 lua_setmetatable(L, -2); 75 lua_setmetatable(L, -2);
76 } 76 }
77 77
78 template <typename T> T* push_ref(lua_State* L, T* ref) { 78 template <typename T> T* push_ref(lua_State* L, T* ref) {
79 *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref); 79 *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref);
80 luaL_getmetatable(L, get_mtname<T>()); 80 luaL_getmetatable(L, get_mtname<T>());
81 lua_setmetatable(L, -2); 81 lua_setmetatable(L, -2);
82 return ref; 82 return ref;
83 } 83 }
84 84
85 template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) {
86 *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release();
87 luaL_getmetatable(L, get_mtname<T>());
88 lua_setmetatable(L, -2);
89 }
90
85 template <typename T> T* get_ref(lua_State* L, int index) { 91 template <typename T> T* get_ref(lua_State* L, int index) {
86 return *(T**)luaL_checkudata(L, index, get_mtname<T>()); 92 return *(T**)luaL_checkudata(L, index, get_mtname<T>());
87 } 93 }
88 94
89 template <typename T> T* get_obj(lua_State* L, int index) { 95 template <typename T> T* get_obj(lua_State* L, int index) {
90 return (T*)luaL_checkudata(L, index, get_mtname<T>()); 96 return (T*)luaL_checkudata(L, index, get_mtname<T>());
91 } 97 }
92 98
93 static bool lua2bool(lua_State* L, int index) { 99 static bool lua2bool(lua_State* L, int index) {
94 return !!lua_toboolean(L, index); 100 return !!lua_toboolean(L, index);
(...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 static int lsk_newLinearGradient(lua_State* L) { 1976 static int lsk_newLinearGradient(lua_State* L) {
1971 SkScalar x0 = lua2scalar_def(L, 1, 0); 1977 SkScalar x0 = lua2scalar_def(L, 1, 0);
1972 SkScalar y0 = lua2scalar_def(L, 2, 0); 1978 SkScalar y0 = lua2scalar_def(L, 2, 0);
1973 SkColor c0 = lua2color(L, 3); 1979 SkColor c0 = lua2color(L, 3);
1974 SkScalar x1 = lua2scalar_def(L, 4, 0); 1980 SkScalar x1 = lua2scalar_def(L, 4, 0);
1975 SkScalar y1 = lua2scalar_def(L, 5, 0); 1981 SkScalar y1 = lua2scalar_def(L, 5, 0);
1976 SkColor c1 = lua2color(L, 6); 1982 SkColor c1 = lua2color(L, 6);
1977 1983
1978 SkPoint pts[] = { { x0, y0 }, { x1, y1 } }; 1984 SkPoint pts[] = { { x0, y0 }, { x1, y1 } };
1979 SkColor colors[] = { c0, c1 }; 1985 SkColor colors[] = { c0, c1 };
1980 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShad er::kClamp_TileMode); 1986 auto s = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode);
1981 if (nullptr == s) { 1987 if (!s) {
1982 lua_pushnil(L); 1988 lua_pushnil(L);
1983 } else { 1989 } else {
1984 push_ref(L, s)->unref(); 1990 push_ref(L, std::move(s));
1985 } 1991 }
1986 return 1; 1992 return 1;
1987 } 1993 }
1988 1994
1989 static int lsk_newMatrix(lua_State* L) { 1995 static int lsk_newMatrix(lua_State* L) {
1990 push_new<SkMatrix>(L)->reset(); 1996 push_new<SkMatrix>(L)->reset();
1991 return 1; 1997 return 1;
1992 } 1998 }
1993 1999
1994 static int lsk_newPaint(lua_State* L) { 2000 static int lsk_newPaint(lua_State* L) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 REG_CLASS(L, SkTextBlob); 2137 REG_CLASS(L, SkTextBlob);
2132 REG_CLASS(L, SkTypeface); 2138 REG_CLASS(L, SkTypeface);
2133 REG_CLASS(L, SkXfermode); 2139 REG_CLASS(L, SkXfermode);
2134 } 2140 }
2135 2141
2136 extern "C" int luaopen_skia(lua_State* L); 2142 extern "C" int luaopen_skia(lua_State* L);
2137 extern "C" int luaopen_skia(lua_State* L) { 2143 extern "C" int luaopen_skia(lua_State* L) {
2138 SkLua::Load(L); 2144 SkLua::Load(L);
2139 return 0; 2145 return 0;
2140 } 2146 }
OLDNEW
« 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