reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/utils/SkLua.h" |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 9 | |
| 10 | #if SK_SUPPORT_GPU |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | //#include "src/gpu/GrReducedClip.h" |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 12 | #endif |
| 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkCanvas.h" |
| 15 | #include "include/core/SkColorFilter.h" |
| 16 | #include "include/core/SkData.h" |
| 17 | #include "include/core/SkFont.h" |
| 18 | #include "include/core/SkFontMetrics.h" |
| 19 | #include "include/core/SkFontStyle.h" |
| 20 | #include "include/core/SkImage.h" |
| 21 | #include "include/core/SkMatrix.h" |
| 22 | #include "include/core/SkPaint.h" |
| 23 | #include "include/core/SkPath.h" |
| 24 | #include "include/core/SkPictureRecorder.h" |
| 25 | #include "include/core/SkRRect.h" |
| 26 | #include "include/core/SkString.h" |
| 27 | #include "include/core/SkSurface.h" |
| 28 | #include "include/core/SkTextBlob.h" |
| 29 | #include "include/core/SkTypeface.h" |
| 30 | #include "include/docs/SkPDFDocument.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "include/effects/SkGradientShader.h" |
Michael Ludwig | 06eacf4 | 2019-08-01 16:02:27 -0400 | [diff] [blame] | 32 | #include "include/effects/SkImageFilters.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 33 | #include "include/private/SkTo.h" |
| 34 | #include "modules/skshaper/include/SkShaper.h" |
Mike Klein | 79aea6a | 2018-06-11 10:45:26 -0400 | [diff] [blame] | 35 | #include <new> |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 36 | |
| 37 | extern "C" { |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 38 | #include "lua.h" |
| 39 | #include "lualib.h" |
| 40 | #include "lauxlib.h" |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 43 | struct DocHolder { |
| 44 | sk_sp<SkDocument> fDoc; |
| 45 | std::unique_ptr<SkWStream> fStream; |
| 46 | }; |
| 47 | |
reed@google.com | fd34587 | 2013-05-22 20:53:42 +0000 | [diff] [blame] | 48 | // return the metatable name for a given class |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 49 | template <typename T> const char* get_mtname(); |
reed@google.com | fd34587 | 2013-05-22 20:53:42 +0000 | [diff] [blame] | 50 | #define DEF_MTNAME(T) \ |
| 51 | template <> const char* get_mtname<T>() { \ |
| 52 | return #T "_LuaMetaTableName"; \ |
| 53 | } |
| 54 | |
| 55 | DEF_MTNAME(SkCanvas) |
reed | 22a517f | 2015-12-04 20:45:59 -0800 | [diff] [blame] | 56 | DEF_MTNAME(SkColorFilter) |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 57 | DEF_MTNAME(DocHolder) |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 58 | DEF_MTNAME(SkFont) |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 59 | DEF_MTNAME(SkImage) |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 60 | DEF_MTNAME(SkImageFilter) |
reed@google.com | fd34587 | 2013-05-22 20:53:42 +0000 | [diff] [blame] | 61 | DEF_MTNAME(SkMatrix) |
| 62 | DEF_MTNAME(SkRRect) |
| 63 | DEF_MTNAME(SkPath) |
| 64 | DEF_MTNAME(SkPaint) |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 65 | DEF_MTNAME(SkPathEffect) |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 66 | DEF_MTNAME(SkPicture) |
| 67 | DEF_MTNAME(SkPictureRecorder) |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 68 | DEF_MTNAME(SkShader) |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 69 | DEF_MTNAME(SkSurface) |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 70 | DEF_MTNAME(SkTextBlob) |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 71 | DEF_MTNAME(SkTypeface) |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 72 | DEF_MTNAME(SkFontStyle) |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 73 | |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 74 | template <typename T, typename... Args> T* push_new(lua_State* L, Args&&... args) { |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 75 | T* addr = (T*)lua_newuserdata(L, sizeof(T)); |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 76 | new (addr) T(std::forward<Args>(args)...); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 77 | luaL_getmetatable(L, get_mtname<T>()); |
| 78 | lua_setmetatable(L, -2); |
| 79 | return addr; |
| 80 | } |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 81 | |
| 82 | template <typename T> void push_obj(lua_State* L, const T& obj) { |
| 83 | new (lua_newuserdata(L, sizeof(T))) T(obj); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 84 | luaL_getmetatable(L, get_mtname<T>()); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 85 | lua_setmetatable(L, -2); |
| 86 | } |
| 87 | |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 88 | template <typename T> T* push_ptr(lua_State* L, T* ptr) { |
| 89 | *(T**)lua_newuserdata(L, sizeof(T*)) = ptr; |
| 90 | luaL_getmetatable(L, get_mtname<T>()); |
| 91 | lua_setmetatable(L, -2); |
| 92 | return ptr; |
| 93 | } |
| 94 | |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 95 | template <typename T> T* push_ref(lua_State* L, T* ref) { |
commit-bot@chromium.org | 77887af | 2013-12-17 14:28:19 +0000 | [diff] [blame] | 96 | *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 97 | luaL_getmetatable(L, get_mtname<T>()); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 98 | lua_setmetatable(L, -2); |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 99 | return ref; |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 100 | } |
| 101 | |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 102 | template <typename T> void push_ref(lua_State* L, sk_sp<T> sp) { |
| 103 | *(T**)lua_newuserdata(L, sizeof(T*)) = sp.release(); |
| 104 | luaL_getmetatable(L, get_mtname<T>()); |
| 105 | lua_setmetatable(L, -2); |
| 106 | } |
| 107 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 108 | template <typename T> T* get_ref(lua_State* L, int index) { |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 109 | return *(T**)luaL_checkudata(L, index, get_mtname<T>()); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | template <typename T> T* get_obj(lua_State* L, int index) { |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 113 | return (T*)luaL_checkudata(L, index, get_mtname<T>()); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 114 | } |
| 115 | |
reed@google.com | 88c9ec9 | 2013-05-22 15:43:21 +0000 | [diff] [blame] | 116 | static bool lua2bool(lua_State* L, int index) { |
| 117 | return !!lua_toboolean(L, index); |
| 118 | } |
| 119 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 120 | /////////////////////////////////////////////////////////////////////////////// |
| 121 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 122 | SkLua::SkLua(const char termCode[]) : fTermCode(termCode), fWeOwnL(true) { |
| 123 | fL = luaL_newstate(); |
| 124 | luaL_openlibs(fL); |
| 125 | SkLua::Load(fL); |
| 126 | } |
| 127 | |
| 128 | SkLua::SkLua(lua_State* L) : fL(L), fWeOwnL(false) {} |
| 129 | |
| 130 | SkLua::~SkLua() { |
| 131 | if (fWeOwnL) { |
| 132 | if (fTermCode.size() > 0) { |
| 133 | lua_getglobal(fL, fTermCode.c_str()); |
| 134 | if (lua_pcall(fL, 0, 0, 0) != LUA_OK) { |
| 135 | SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); |
| 136 | } |
| 137 | } |
| 138 | lua_close(fL); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | bool SkLua::runCode(const char code[]) { |
| 143 | int err = luaL_loadstring(fL, code) || lua_pcall(fL, 0, 0, 0); |
| 144 | if (err) { |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 145 | SkDebugf("--- lua failed: %s\n", lua_tostring(fL, -1)); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 146 | return false; |
| 147 | } |
| 148 | return true; |
| 149 | } |
| 150 | |
| 151 | bool SkLua::runCode(const void* code, size_t size) { |
| 152 | SkString str((const char*)code, size); |
| 153 | return this->runCode(str.c_str()); |
| 154 | } |
| 155 | |
| 156 | /////////////////////////////////////////////////////////////////////////////// |
| 157 | |
| 158 | #define CHECK_SETFIELD(key) do if (key) lua_setfield(fL, -2, key); while (0) |
| 159 | |
reed@google.com | 2956387 | 2013-07-10 21:23:49 +0000 | [diff] [blame] | 160 | static void setfield_bool_if(lua_State* L, const char key[], bool pred) { |
| 161 | if (pred) { |
| 162 | lua_pushboolean(L, true); |
| 163 | lua_setfield(L, -2, key); |
| 164 | } |
| 165 | } |
| 166 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 167 | static void setfield_string(lua_State* L, const char key[], const char value[]) { |
| 168 | lua_pushstring(L, value); |
| 169 | lua_setfield(L, -2, key); |
| 170 | } |
| 171 | |
| 172 | static void setfield_number(lua_State* L, const char key[], double value) { |
| 173 | lua_pushnumber(L, value); |
| 174 | lua_setfield(L, -2, key); |
| 175 | } |
| 176 | |
humper@google.com | 2815c19 | 2013-07-10 22:42:30 +0000 | [diff] [blame] | 177 | static void setfield_boolean(lua_State* L, const char key[], bool value) { |
| 178 | lua_pushboolean(L, value); |
| 179 | lua_setfield(L, -2, key); |
| 180 | } |
| 181 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 182 | static void setfield_scalar(lua_State* L, const char key[], SkScalar value) { |
| 183 | setfield_number(L, key, SkScalarToLua(value)); |
| 184 | } |
| 185 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 186 | static void setfield_function(lua_State* L, |
| 187 | const char key[], lua_CFunction value) { |
| 188 | lua_pushcfunction(L, value); |
| 189 | lua_setfield(L, -2, key); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 190 | } |
| 191 | |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 192 | static int lua2int_def(lua_State* L, int index, int defaultValue) { |
| 193 | if (lua_isnumber(L, index)) { |
| 194 | return (int)lua_tonumber(L, index); |
| 195 | } else { |
| 196 | return defaultValue; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | static SkScalar lua2scalar(lua_State* L, int index) { |
| 201 | SkASSERT(lua_isnumber(L, index)); |
| 202 | return SkLuaToScalar(lua_tonumber(L, index)); |
| 203 | } |
| 204 | |
| 205 | static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) { |
| 206 | if (lua_isnumber(L, index)) { |
| 207 | return SkLuaToScalar(lua_tonumber(L, index)); |
| 208 | } else { |
| 209 | return defaultValue; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | static SkScalar getarray_scalar(lua_State* L, int stackIndex, int arrayIndex) { |
| 214 | SkASSERT(lua_istable(L, stackIndex)); |
| 215 | lua_rawgeti(L, stackIndex, arrayIndex); |
mtklein | 8aacf20 | 2014-12-18 13:29:54 -0800 | [diff] [blame] | 216 | |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 217 | SkScalar value = lua2scalar(L, -1); |
| 218 | lua_pop(L, 1); |
| 219 | return value; |
| 220 | } |
| 221 | |
| 222 | static void getarray_scalars(lua_State* L, int stackIndex, SkScalar dst[], int count) { |
| 223 | for (int i = 0; i < count; ++i) { |
| 224 | dst[i] = getarray_scalar(L, stackIndex, i + 1); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | static void getarray_points(lua_State* L, int stackIndex, SkPoint pts[], int count) { |
| 229 | getarray_scalars(L, stackIndex, &pts[0].fX, count * 2); |
| 230 | } |
| 231 | |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 232 | static void setarray_number(lua_State* L, int index, double value) { |
| 233 | lua_pushnumber(L, value); |
| 234 | lua_rawseti(L, -2, index); |
| 235 | } |
| 236 | |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 237 | static void setarray_scalar(lua_State* L, int index, SkScalar value) { |
| 238 | setarray_number(L, index, SkScalarToLua(value)); |
| 239 | } |
| 240 | |
hstern | 0b401ce | 2016-08-02 09:17:59 -0700 | [diff] [blame] | 241 | static void setarray_string(lua_State* L, int index, const char str[]) { |
| 242 | lua_pushstring(L, str); |
| 243 | lua_rawseti(L, -2, index); |
| 244 | } |
| 245 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 246 | void SkLua::pushBool(bool value, const char key[]) { |
| 247 | lua_pushboolean(fL, value); |
| 248 | CHECK_SETFIELD(key); |
| 249 | } |
| 250 | |
| 251 | void SkLua::pushString(const char str[], const char key[]) { |
| 252 | lua_pushstring(fL, str); |
| 253 | CHECK_SETFIELD(key); |
| 254 | } |
| 255 | |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 256 | void SkLua::pushString(const char str[], size_t length, const char key[]) { |
| 257 | // TODO: how to do this w/o making a copy? |
| 258 | SkString s(str, length); |
| 259 | lua_pushstring(fL, s.c_str()); |
| 260 | CHECK_SETFIELD(key); |
| 261 | } |
| 262 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 263 | void SkLua::pushString(const SkString& str, const char key[]) { |
| 264 | lua_pushstring(fL, str.c_str()); |
| 265 | CHECK_SETFIELD(key); |
| 266 | } |
| 267 | |
| 268 | void SkLua::pushColor(SkColor color, const char key[]) { |
| 269 | lua_newtable(fL); |
| 270 | setfield_number(fL, "a", SkColorGetA(color) / 255.0); |
| 271 | setfield_number(fL, "r", SkColorGetR(color) / 255.0); |
| 272 | setfield_number(fL, "g", SkColorGetG(color) / 255.0); |
| 273 | setfield_number(fL, "b", SkColorGetB(color) / 255.0); |
| 274 | CHECK_SETFIELD(key); |
| 275 | } |
| 276 | |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 277 | void SkLua::pushU32(uint32_t value, const char key[]) { |
| 278 | lua_pushnumber(fL, (double)value); |
| 279 | CHECK_SETFIELD(key); |
| 280 | } |
| 281 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 282 | void SkLua::pushScalar(SkScalar value, const char key[]) { |
| 283 | lua_pushnumber(fL, SkScalarToLua(value)); |
| 284 | CHECK_SETFIELD(key); |
| 285 | } |
| 286 | |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 287 | void SkLua::pushArrayU16(const uint16_t array[], int count, const char key[]) { |
| 288 | lua_newtable(fL); |
| 289 | for (int i = 0; i < count; ++i) { |
| 290 | // make it base-1 to match lua convention |
| 291 | setarray_number(fL, i + 1, (double)array[i]); |
| 292 | } |
| 293 | CHECK_SETFIELD(key); |
| 294 | } |
| 295 | |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 296 | void SkLua::pushArrayPoint(const SkPoint array[], int count, const char key[]) { |
| 297 | lua_newtable(fL); |
| 298 | for (int i = 0; i < count; ++i) { |
| 299 | // make it base-1 to match lua convention |
| 300 | lua_newtable(fL); |
| 301 | this->pushScalar(array[i].fX, "x"); |
| 302 | this->pushScalar(array[i].fY, "y"); |
| 303 | lua_rawseti(fL, -2, i + 1); |
| 304 | } |
| 305 | CHECK_SETFIELD(key); |
| 306 | } |
| 307 | |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 308 | void SkLua::pushArrayScalar(const SkScalar array[], int count, const char key[]) { |
| 309 | lua_newtable(fL); |
| 310 | for (int i = 0; i < count; ++i) { |
| 311 | // make it base-1 to match lua convention |
| 312 | setarray_scalar(fL, i + 1, array[i]); |
| 313 | } |
| 314 | CHECK_SETFIELD(key); |
| 315 | } |
| 316 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 317 | void SkLua::pushRect(const SkRect& r, const char key[]) { |
| 318 | lua_newtable(fL); |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 319 | setfield_scalar(fL, "left", r.fLeft); |
| 320 | setfield_scalar(fL, "top", r.fTop); |
| 321 | setfield_scalar(fL, "right", r.fRight); |
| 322 | setfield_scalar(fL, "bottom", r.fBottom); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 323 | CHECK_SETFIELD(key); |
| 324 | } |
| 325 | |
| 326 | void SkLua::pushRRect(const SkRRect& rr, const char key[]) { |
| 327 | push_obj(fL, rr); |
| 328 | CHECK_SETFIELD(key); |
| 329 | } |
| 330 | |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 331 | void SkLua::pushDash(const SkPathEffect::DashInfo& info, const char key[]) { |
| 332 | lua_newtable(fL); |
| 333 | setfield_scalar(fL, "phase", info.fPhase); |
| 334 | this->pushArrayScalar(info.fIntervals, info.fCount, "intervals"); |
| 335 | CHECK_SETFIELD(key); |
| 336 | } |
| 337 | |
| 338 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 339 | void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) { |
| 340 | push_obj(fL, matrix); |
| 341 | CHECK_SETFIELD(key); |
| 342 | } |
| 343 | |
| 344 | void SkLua::pushPaint(const SkPaint& paint, const char key[]) { |
| 345 | push_obj(fL, paint); |
| 346 | CHECK_SETFIELD(key); |
| 347 | } |
| 348 | |
| 349 | void SkLua::pushPath(const SkPath& path, const char key[]) { |
| 350 | push_obj(fL, path); |
| 351 | CHECK_SETFIELD(key); |
| 352 | } |
| 353 | |
| 354 | void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 355 | push_ptr(fL, canvas); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 356 | CHECK_SETFIELD(key); |
| 357 | } |
| 358 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 359 | void SkLua::pushTextBlob(const SkTextBlob* blob, const char key[]) { |
| 360 | push_ref(fL, const_cast<SkTextBlob*>(blob)); |
| 361 | CHECK_SETFIELD(key); |
| 362 | } |
| 363 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 364 | /////////////////////////////////////////////////////////////////////////////// |
| 365 | /////////////////////////////////////////////////////////////////////////////// |
| 366 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 367 | static SkScalar getfield_scalar(lua_State* L, int index, const char key[]) { |
| 368 | SkASSERT(lua_istable(L, index)); |
| 369 | lua_pushstring(L, key); |
| 370 | lua_gettable(L, index); |
mtklein | 8aacf20 | 2014-12-18 13:29:54 -0800 | [diff] [blame] | 371 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 372 | SkScalar value = lua2scalar(L, -1); |
| 373 | lua_pop(L, 1); |
| 374 | return value; |
| 375 | } |
| 376 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 377 | static SkScalar getfield_scalar_default(lua_State* L, int index, const char key[], SkScalar def) { |
| 378 | SkASSERT(lua_istable(L, index)); |
| 379 | lua_pushstring(L, key); |
| 380 | lua_gettable(L, index); |
skia.committer@gmail.com | 370c534 | 2013-06-09 07:01:05 +0000 | [diff] [blame] | 381 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 382 | SkScalar value; |
| 383 | if (lua_isnil(L, -1)) { |
| 384 | value = def; |
| 385 | } else { |
| 386 | value = lua2scalar(L, -1); |
| 387 | } |
| 388 | lua_pop(L, 1); |
| 389 | return value; |
| 390 | } |
| 391 | |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 392 | static SkScalar byte2unit(U8CPU byte) { |
| 393 | return byte / 255.0f; |
| 394 | } |
| 395 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 396 | static U8CPU unit2byte(SkScalar x) { |
| 397 | if (x <= 0) { |
| 398 | return 0; |
| 399 | } else if (x >= 1) { |
| 400 | return 255; |
| 401 | } else { |
| 402 | return SkScalarRoundToInt(x * 255); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | static SkColor lua2color(lua_State* L, int index) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 407 | return SkColorSetARGB(unit2byte(getfield_scalar_default(L, index, "a", 1)), |
| 408 | unit2byte(getfield_scalar_default(L, index, "r", 0)), |
| 409 | unit2byte(getfield_scalar_default(L, index, "g", 0)), |
| 410 | unit2byte(getfield_scalar_default(L, index, "b", 0))); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | static SkRect* lua2rect(lua_State* L, int index, SkRect* rect) { |
Mike Reed | 92b3335 | 2019-08-24 19:39:13 -0400 | [diff] [blame] | 414 | rect->setLTRB(getfield_scalar_default(L, index, "left", 0), |
| 415 | getfield_scalar_default(L, index, "top", 0), |
| 416 | getfield_scalar(L, index, "right"), |
| 417 | getfield_scalar(L, index, "bottom")); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 418 | return rect; |
| 419 | } |
| 420 | |
reed | f355df5 | 2014-10-12 12:18:40 -0700 | [diff] [blame] | 421 | static int lcanvas_clear(lua_State* L) { |
| 422 | get_ref<SkCanvas>(L, 1)->clear(0); |
| 423 | return 0; |
| 424 | } |
| 425 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 426 | static int lcanvas_drawColor(lua_State* L) { |
| 427 | get_ref<SkCanvas>(L, 1)->drawColor(lua2color(L, 2)); |
| 428 | return 0; |
| 429 | } |
| 430 | |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 431 | static int lcanvas_drawPaint(lua_State* L) { |
| 432 | get_ref<SkCanvas>(L, 1)->drawPaint(*get_obj<SkPaint>(L, 2)); |
| 433 | return 0; |
| 434 | } |
| 435 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 436 | static int lcanvas_drawRect(lua_State* L) { |
| 437 | SkRect rect; |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 438 | lua2rect(L, 2, &rect); |
| 439 | const SkPaint* paint = get_obj<SkPaint>(L, 3); |
| 440 | get_ref<SkCanvas>(L, 1)->drawRect(rect, *paint); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static int lcanvas_drawOval(lua_State* L) { |
| 445 | SkRect rect; |
| 446 | get_ref<SkCanvas>(L, 1)->drawOval(*lua2rect(L, 2, &rect), |
| 447 | *get_obj<SkPaint>(L, 3)); |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int lcanvas_drawCircle(lua_State* L) { |
| 452 | get_ref<SkCanvas>(L, 1)->drawCircle(lua2scalar(L, 2), |
| 453 | lua2scalar(L, 3), |
| 454 | lua2scalar(L, 4), |
| 455 | *get_obj<SkPaint>(L, 5)); |
| 456 | return 0; |
| 457 | } |
| 458 | |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 459 | static SkPaint* lua2OptionalPaint(lua_State* L, int index, SkPaint* paint) { |
| 460 | if (lua_isnumber(L, index)) { |
| 461 | paint->setAlpha(SkScalarRoundToInt(lua2scalar(L, index) * 255)); |
| 462 | return paint; |
reed | f355df5 | 2014-10-12 12:18:40 -0700 | [diff] [blame] | 463 | } else if (lua_isuserdata(L, index)) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 464 | const SkPaint* ptr = get_obj<SkPaint>(L, index); |
| 465 | if (ptr) { |
| 466 | *paint = *ptr; |
| 467 | return paint; |
| 468 | } |
| 469 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 470 | return nullptr; |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 471 | } |
| 472 | |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 473 | static int lcanvas_drawImage(lua_State* L) { |
| 474 | SkCanvas* canvas = get_ref<SkCanvas>(L, 1); |
| 475 | SkImage* image = get_ref<SkImage>(L, 2); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 476 | if (nullptr == image) { |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 477 | return 0; |
| 478 | } |
| 479 | SkScalar x = lua2scalar(L, 3); |
| 480 | SkScalar y = lua2scalar(L, 4); |
| 481 | |
| 482 | SkPaint paint; |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 483 | canvas->drawImage(image, x, y, lua2OptionalPaint(L, 5, &paint)); |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | |
reed | ba5fb93 | 2014-10-10 15:28:19 -0700 | [diff] [blame] | 487 | static int lcanvas_drawImageRect(lua_State* L) { |
| 488 | SkCanvas* canvas = get_ref<SkCanvas>(L, 1); |
| 489 | SkImage* image = get_ref<SkImage>(L, 2); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 490 | if (nullptr == image) { |
reed | ba5fb93 | 2014-10-10 15:28:19 -0700 | [diff] [blame] | 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | SkRect srcR, dstR; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 495 | SkRect* srcRPtr = nullptr; |
reed | ba5fb93 | 2014-10-10 15:28:19 -0700 | [diff] [blame] | 496 | if (!lua_isnil(L, 3)) { |
| 497 | srcRPtr = lua2rect(L, 3, &srcR); |
| 498 | } |
| 499 | lua2rect(L, 4, &dstR); |
mtklein | 8aacf20 | 2014-12-18 13:29:54 -0800 | [diff] [blame] | 500 | |
reed | ba5fb93 | 2014-10-10 15:28:19 -0700 | [diff] [blame] | 501 | SkPaint paint; |
reed | e47829b | 2015-08-06 10:02:53 -0700 | [diff] [blame] | 502 | canvas->legacy_drawImageRect(image, srcRPtr, dstR, lua2OptionalPaint(L, 5, &paint)); |
reed | ba5fb93 | 2014-10-10 15:28:19 -0700 | [diff] [blame] | 503 | return 0; |
| 504 | } |
| 505 | |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 506 | static int lcanvas_drawPatch(lua_State* L) { |
| 507 | SkPoint cubics[12]; |
| 508 | SkColor colorStorage[4]; |
| 509 | SkPoint texStorage[4]; |
| 510 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 511 | const SkColor* colors = nullptr; |
| 512 | const SkPoint* texs = nullptr; |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 513 | |
| 514 | getarray_points(L, 2, cubics, 12); |
| 515 | |
| 516 | colorStorage[0] = SK_ColorRED; |
| 517 | colorStorage[1] = SK_ColorGREEN; |
| 518 | colorStorage[2] = SK_ColorBLUE; |
| 519 | colorStorage[3] = SK_ColorGRAY; |
| 520 | |
| 521 | if (lua_isnil(L, 4)) { |
| 522 | colors = colorStorage; |
| 523 | } else { |
| 524 | getarray_points(L, 4, texStorage, 4); |
| 525 | texs = texStorage; |
| 526 | } |
| 527 | |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 528 | get_ref<SkCanvas>(L, 1)->drawPatch(cubics, colors, texs, *get_obj<SkPaint>(L, 5)); |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 529 | return 0; |
| 530 | } |
| 531 | |
reed@google.com | fd34587 | 2013-05-22 20:53:42 +0000 | [diff] [blame] | 532 | static int lcanvas_drawPath(lua_State* L) { |
| 533 | get_ref<SkCanvas>(L, 1)->drawPath(*get_obj<SkPath>(L, 2), |
| 534 | *get_obj<SkPaint>(L, 3)); |
| 535 | return 0; |
| 536 | } |
| 537 | |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 538 | // drawPicture(pic, x, y, paint) |
| 539 | static int lcanvas_drawPicture(lua_State* L) { |
| 540 | SkCanvas* canvas = get_ref<SkCanvas>(L, 1); |
| 541 | SkPicture* picture = get_ref<SkPicture>(L, 2); |
| 542 | SkScalar x = lua2scalar_def(L, 3, 0); |
| 543 | SkScalar y = lua2scalar_def(L, 4, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 544 | SkMatrix matrix, *matrixPtr = nullptr; |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 545 | if (x || y) { |
| 546 | matrix.setTranslate(x, y); |
| 547 | matrixPtr = &matrix; |
| 548 | } |
| 549 | SkPaint paint; |
| 550 | canvas->drawPicture(picture, matrixPtr, lua2OptionalPaint(L, 5, &paint)); |
| 551 | return 0; |
| 552 | } |
| 553 | |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 554 | static int lcanvas_drawText(lua_State* L) { |
| 555 | if (lua_gettop(L) < 5) { |
| 556 | return 0; |
| 557 | } |
| 558 | |
Mike Reed | 5f528e5 | 2019-01-28 10:57:28 -0500 | [diff] [blame] | 559 | // TODO: restore this logic based on SkFont instead of SkPaint |
| 560 | #if 0 |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 561 | if (lua_isstring(L, 2) && lua_isnumber(L, 3) && lua_isnumber(L, 4)) { |
| 562 | size_t len; |
| 563 | const char* text = lua_tolstring(L, 2, &len); |
Hal Canary | 292ece8 | 2019-01-09 10:59:08 -0500 | [diff] [blame] | 564 | get_ref<SkCanvas>(L, 1)->drawSimpleText( |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 565 | text, len, SkTextEncoding::kUTF8, |
Hal Canary | 292ece8 | 2019-01-09 10:59:08 -0500 | [diff] [blame] | 566 | lua2scalar(L, 3), lua2scalar(L, 4), |
| 567 | SkFont::LEGACY_ExtractFromPaint(*get_obj<SkPaint>(L, 5)), |
| 568 | *get_obj<SkPaint>(L, 5)); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 569 | } |
Mike Reed | e5f9cfa | 2019-01-10 13:55:35 -0500 | [diff] [blame] | 570 | #endif |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 574 | static int lcanvas_drawTextBlob(lua_State* L) { |
| 575 | const SkTextBlob* blob = get_ref<SkTextBlob>(L, 2); |
| 576 | SkScalar x = lua2scalar(L, 3); |
| 577 | SkScalar y = lua2scalar(L, 4); |
| 578 | const SkPaint& paint = *get_obj<SkPaint>(L, 5); |
| 579 | get_ref<SkCanvas>(L, 1)->drawTextBlob(blob, x, y, paint); |
| 580 | return 0; |
| 581 | } |
| 582 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 583 | static int lcanvas_getSaveCount(lua_State* L) { |
| 584 | lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount()); |
| 585 | return 1; |
| 586 | } |
| 587 | |
| 588 | static int lcanvas_getTotalMatrix(lua_State* L) { |
| 589 | SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); |
| 590 | return 1; |
| 591 | } |
| 592 | |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 593 | static int lcanvas_save(lua_State* L) { |
| 594 | lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); |
| 595 | return 1; |
| 596 | } |
| 597 | |
reed | 86217d8 | 2014-10-25 20:44:40 -0700 | [diff] [blame] | 598 | static int lcanvas_saveLayer(lua_State* L) { |
| 599 | SkPaint paint; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 600 | lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->saveLayer(nullptr, lua2OptionalPaint(L, 2, &paint))); |
reed | 86217d8 | 2014-10-25 20:44:40 -0700 | [diff] [blame] | 601 | return 1; |
| 602 | } |
| 603 | |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 604 | static int lcanvas_restore(lua_State* L) { |
| 605 | get_ref<SkCanvas>(L, 1)->restore(); |
| 606 | return 0; |
| 607 | } |
| 608 | |
mike@reedtribe.org | 1d32cc6 | 2013-06-13 01:28:56 +0000 | [diff] [blame] | 609 | static int lcanvas_scale(lua_State* L) { |
| 610 | SkScalar sx = lua2scalar_def(L, 2, 1); |
| 611 | SkScalar sy = lua2scalar_def(L, 3, sx); |
| 612 | get_ref<SkCanvas>(L, 1)->scale(sx, sy); |
| 613 | return 0; |
| 614 | } |
| 615 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 616 | static int lcanvas_translate(lua_State* L) { |
mike@reedtribe.org | 1d32cc6 | 2013-06-13 01:28:56 +0000 | [diff] [blame] | 617 | SkScalar tx = lua2scalar_def(L, 2, 0); |
| 618 | SkScalar ty = lua2scalar_def(L, 3, 0); |
| 619 | get_ref<SkCanvas>(L, 1)->translate(tx, ty); |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | static int lcanvas_rotate(lua_State* L) { |
| 624 | SkScalar degrees = lua2scalar_def(L, 2, 0); |
| 625 | get_ref<SkCanvas>(L, 1)->rotate(degrees); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 626 | return 0; |
| 627 | } |
| 628 | |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 629 | static int lcanvas_concat(lua_State* L) { |
| 630 | get_ref<SkCanvas>(L, 1)->concat(*get_obj<SkMatrix>(L, 2)); |
| 631 | return 0; |
| 632 | } |
| 633 | |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 634 | static int lcanvas_newSurface(lua_State* L) { |
| 635 | int width = lua2int_def(L, 2, 0); |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 636 | int height = lua2int_def(L, 3, 0); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 637 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 638 | auto surface = get_ref<SkCanvas>(L, 1)->makeSurface(info); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 639 | if (nullptr == surface) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 640 | lua_pushnil(L); |
| 641 | } else { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 642 | push_ref(L, surface); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 643 | } |
| 644 | return 1; |
| 645 | } |
| 646 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 647 | static int lcanvas_gc(lua_State* L) { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 648 | // don't know how to track a ptr... |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 649 | return 0; |
| 650 | } |
| 651 | |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 652 | const struct luaL_Reg gSkCanvas_Methods[] = { |
reed | f355df5 | 2014-10-12 12:18:40 -0700 | [diff] [blame] | 653 | { "clear", lcanvas_clear }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 654 | { "drawColor", lcanvas_drawColor }, |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 655 | { "drawPaint", lcanvas_drawPaint }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 656 | { "drawRect", lcanvas_drawRect }, |
| 657 | { "drawOval", lcanvas_drawOval }, |
| 658 | { "drawCircle", lcanvas_drawCircle }, |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 659 | { "drawImage", lcanvas_drawImage }, |
reed | ba5fb93 | 2014-10-10 15:28:19 -0700 | [diff] [blame] | 660 | { "drawImageRect", lcanvas_drawImageRect }, |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 661 | { "drawPatch", lcanvas_drawPatch }, |
reed@google.com | fd34587 | 2013-05-22 20:53:42 +0000 | [diff] [blame] | 662 | { "drawPath", lcanvas_drawPath }, |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 663 | { "drawPicture", lcanvas_drawPicture }, |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 664 | { "drawText", lcanvas_drawText }, |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 665 | { "drawTextBlob", lcanvas_drawTextBlob }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 666 | { "getSaveCount", lcanvas_getSaveCount }, |
| 667 | { "getTotalMatrix", lcanvas_getTotalMatrix }, |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 668 | { "save", lcanvas_save }, |
reed | 86217d8 | 2014-10-25 20:44:40 -0700 | [diff] [blame] | 669 | { "saveLayer", lcanvas_saveLayer }, |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 670 | { "restore", lcanvas_restore }, |
mike@reedtribe.org | 1d32cc6 | 2013-06-13 01:28:56 +0000 | [diff] [blame] | 671 | { "scale", lcanvas_scale }, |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 672 | { "translate", lcanvas_translate }, |
mike@reedtribe.org | 1d32cc6 | 2013-06-13 01:28:56 +0000 | [diff] [blame] | 673 | { "rotate", lcanvas_rotate }, |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 674 | { "concat", lcanvas_concat }, |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 675 | |
| 676 | { "newSurface", lcanvas_newSurface }, |
| 677 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 678 | { "__gc", lcanvas_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 679 | { nullptr, nullptr } |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | /////////////////////////////////////////////////////////////////////////////// |
| 683 | |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 684 | static int ldocument_beginPage(lua_State* L) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 685 | const SkRect* contentPtr = nullptr; |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 686 | push_ptr(L, get_obj<DocHolder>(L, 1)->fDoc->beginPage(lua2scalar(L, 2), |
| 687 | lua2scalar(L, 3), |
| 688 | contentPtr)); |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 689 | return 1; |
| 690 | } |
| 691 | |
| 692 | static int ldocument_endPage(lua_State* L) { |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 693 | get_obj<DocHolder>(L, 1)->fDoc->endPage(); |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | static int ldocument_close(lua_State* L) { |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 698 | get_obj<DocHolder>(L, 1)->fDoc->close(); |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | static int ldocument_gc(lua_State* L) { |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 703 | get_obj<DocHolder>(L, 1)->~DocHolder(); |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 707 | static const struct luaL_Reg gDocHolder_Methods[] = { |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 708 | { "beginPage", ldocument_beginPage }, |
| 709 | { "endPage", ldocument_endPage }, |
| 710 | { "close", ldocument_close }, |
| 711 | { "__gc", ldocument_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 712 | { nullptr, nullptr } |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 713 | }; |
| 714 | |
| 715 | /////////////////////////////////////////////////////////////////////////////// |
| 716 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 717 | static int lpaint_isAntiAlias(lua_State* L) { |
| 718 | lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isAntiAlias()); |
| 719 | return 1; |
| 720 | } |
| 721 | |
| 722 | static int lpaint_setAntiAlias(lua_State* L) { |
reed@google.com | 88c9ec9 | 2013-05-22 15:43:21 +0000 | [diff] [blame] | 723 | get_obj<SkPaint>(L, 1)->setAntiAlias(lua2bool(L, 2)); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 724 | return 0; |
| 725 | } |
| 726 | |
commit-bot@chromium.org | 1cd71fb | 2013-12-18 18:28:07 +0000 | [diff] [blame] | 727 | static int lpaint_isDither(lua_State* L) { |
| 728 | lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isDither()); |
| 729 | return 1; |
| 730 | } |
| 731 | |
reed | bb8a0ab | 2014-11-03 22:32:07 -0800 | [diff] [blame] | 732 | static int lpaint_setDither(lua_State* L) { |
| 733 | get_obj<SkPaint>(L, 1)->setDither(lua2bool(L, 2)); |
| 734 | return 0; |
| 735 | } |
| 736 | |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 737 | static int lpaint_getAlpha(lua_State* L) { |
| 738 | SkLua(L).pushScalar(byte2unit(get_obj<SkPaint>(L, 1)->getAlpha())); |
| 739 | return 1; |
| 740 | } |
| 741 | |
| 742 | static int lpaint_setAlpha(lua_State* L) { |
| 743 | get_obj<SkPaint>(L, 1)->setAlpha(unit2byte(lua2scalar(L, 2))); |
| 744 | return 0; |
| 745 | } |
| 746 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 747 | static int lpaint_getColor(lua_State* L) { |
| 748 | SkLua(L).pushColor(get_obj<SkPaint>(L, 1)->getColor()); |
| 749 | return 1; |
| 750 | } |
| 751 | |
| 752 | static int lpaint_setColor(lua_State* L) { |
| 753 | get_obj<SkPaint>(L, 1)->setColor(lua2color(L, 2)); |
| 754 | return 0; |
| 755 | } |
| 756 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 757 | static int lpaint_getFilterQuality(lua_State* L) { |
| 758 | SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getFilterQuality()); |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 759 | return 1; |
| 760 | } |
| 761 | |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 762 | static int lpaint_setFilterQuality(lua_State* L) { |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 763 | int level = lua2int_def(L, 2, -1); |
| 764 | if (level >= 0 && level <= 3) { |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 765 | get_obj<SkPaint>(L, 1)->setFilterQuality((SkFilterQuality)level); |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 766 | } |
| 767 | return 0; |
| 768 | } |
| 769 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 770 | static int lpaint_getStroke(lua_State* L) { |
| 771 | lua_pushboolean(L, SkPaint::kStroke_Style == get_obj<SkPaint>(L, 1)->getStyle()); |
| 772 | return 1; |
| 773 | } |
| 774 | |
| 775 | static int lpaint_setStroke(lua_State* L) { |
| 776 | SkPaint::Style style; |
skia.committer@gmail.com | 370c534 | 2013-06-09 07:01:05 +0000 | [diff] [blame] | 777 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 778 | if (lua_toboolean(L, 2)) { |
| 779 | style = SkPaint::kStroke_Style; |
| 780 | } else { |
| 781 | style = SkPaint::kFill_Style; |
| 782 | } |
| 783 | get_obj<SkPaint>(L, 1)->setStyle(style); |
| 784 | return 0; |
| 785 | } |
| 786 | |
commit-bot@chromium.org | 1cd71fb | 2013-12-18 18:28:07 +0000 | [diff] [blame] | 787 | static int lpaint_getStrokeCap(lua_State* L) { |
| 788 | SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getStrokeCap()); |
| 789 | return 1; |
| 790 | } |
| 791 | |
| 792 | static int lpaint_getStrokeJoin(lua_State* L) { |
| 793 | SkLua(L).pushU32(get_obj<SkPaint>(L, 1)->getStrokeJoin()); |
| 794 | return 1; |
| 795 | } |
| 796 | |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 797 | static int lpaint_getStrokeWidth(lua_State* L) { |
| 798 | SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getStrokeWidth()); |
| 799 | return 1; |
| 800 | } |
| 801 | |
| 802 | static int lpaint_setStrokeWidth(lua_State* L) { |
| 803 | get_obj<SkPaint>(L, 1)->setStrokeWidth(lua2scalar(L, 2)); |
| 804 | return 0; |
| 805 | } |
| 806 | |
commit-bot@chromium.org | 1cd71fb | 2013-12-18 18:28:07 +0000 | [diff] [blame] | 807 | static int lpaint_getStrokeMiter(lua_State* L) { |
| 808 | SkLua(L).pushScalar(get_obj<SkPaint>(L, 1)->getStrokeMiter()); |
| 809 | return 1; |
| 810 | } |
| 811 | |
reed@google.com | 2956387 | 2013-07-10 21:23:49 +0000 | [diff] [blame] | 812 | static int lpaint_getEffects(lua_State* L) { |
| 813 | const SkPaint* paint = get_obj<SkPaint>(L, 1); |
skia.committer@gmail.com | de2e4e8 | 2013-07-11 07:01:01 +0000 | [diff] [blame] | 814 | |
reed@google.com | 2956387 | 2013-07-10 21:23:49 +0000 | [diff] [blame] | 815 | lua_newtable(L); |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 816 | setfield_bool_if(L, "pathEffect", !!paint->getPathEffect()); |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 817 | setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter()); |
| 818 | setfield_bool_if(L, "shader", !!paint->getShader()); |
reed@google.com | 2956387 | 2013-07-10 21:23:49 +0000 | [diff] [blame] | 819 | setfield_bool_if(L, "colorFilter", !!paint->getColorFilter()); |
| 820 | setfield_bool_if(L, "imageFilter", !!paint->getImageFilter()); |
reed@google.com | 2956387 | 2013-07-10 21:23:49 +0000 | [diff] [blame] | 821 | return 1; |
| 822 | } |
| 823 | |
reed | 22a517f | 2015-12-04 20:45:59 -0800 | [diff] [blame] | 824 | static int lpaint_getColorFilter(lua_State* L) { |
| 825 | const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 826 | SkColorFilter* cf = paint->getColorFilter(); |
| 827 | if (cf) { |
| 828 | push_ref(L, cf); |
| 829 | return 1; |
| 830 | } |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | static int lpaint_setColorFilter(lua_State* L) { |
| 835 | SkPaint* paint = get_obj<SkPaint>(L, 1); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 836 | paint->setColorFilter(sk_ref_sp(get_ref<SkColorFilter>(L, 2))); |
reed | 22a517f | 2015-12-04 20:45:59 -0800 | [diff] [blame] | 837 | return 0; |
| 838 | } |
| 839 | |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 840 | static int lpaint_getImageFilter(lua_State* L) { |
| 841 | const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 842 | SkImageFilter* imf = paint->getImageFilter(); |
| 843 | if (imf) { |
| 844 | push_ref(L, imf); |
| 845 | return 1; |
| 846 | } |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | static int lpaint_setImageFilter(lua_State* L) { |
| 851 | SkPaint* paint = get_obj<SkPaint>(L, 1); |
Mike Reed | 5e25717 | 2016-11-01 11:22:05 -0400 | [diff] [blame] | 852 | paint->setImageFilter(sk_ref_sp(get_ref<SkImageFilter>(L, 2))); |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 853 | return 0; |
| 854 | } |
| 855 | |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 856 | static int lpaint_getShader(lua_State* L) { |
| 857 | const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 858 | SkShader* shader = paint->getShader(); |
| 859 | if (shader) { |
| 860 | push_ref(L, shader); |
| 861 | return 1; |
| 862 | } |
| 863 | return 0; |
| 864 | } |
| 865 | |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 866 | static int lpaint_setShader(lua_State* L) { |
| 867 | SkPaint* paint = get_obj<SkPaint>(L, 1); |
reed | fe63045 | 2016-03-25 09:08:00 -0700 | [diff] [blame] | 868 | paint->setShader(sk_ref_sp(get_ref<SkShader>(L, 2))); |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 872 | static int lpaint_getPathEffect(lua_State* L) { |
| 873 | const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 874 | SkPathEffect* pe = paint->getPathEffect(); |
| 875 | if (pe) { |
| 876 | push_ref(L, pe); |
| 877 | return 1; |
| 878 | } |
| 879 | return 0; |
| 880 | } |
| 881 | |
hstern | 0b401ce | 2016-08-02 09:17:59 -0700 | [diff] [blame] | 882 | static int lpaint_getFillPath(lua_State* L) { |
| 883 | const SkPaint* paint = get_obj<SkPaint>(L, 1); |
| 884 | const SkPath* path = get_obj<SkPath>(L, 2); |
| 885 | |
| 886 | SkPath fillpath; |
| 887 | paint->getFillPath(*path, &fillpath); |
| 888 | |
| 889 | SkLua lua(L); |
| 890 | lua.pushPath(fillpath); |
| 891 | |
| 892 | return 1; |
| 893 | } |
| 894 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 895 | static int lpaint_gc(lua_State* L) { |
| 896 | get_obj<SkPaint>(L, 1)->~SkPaint(); |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static const struct luaL_Reg gSkPaint_Methods[] = { |
| 901 | { "isAntiAlias", lpaint_isAntiAlias }, |
| 902 | { "setAntiAlias", lpaint_setAntiAlias }, |
commit-bot@chromium.org | 1cd71fb | 2013-12-18 18:28:07 +0000 | [diff] [blame] | 903 | { "isDither", lpaint_isDither }, |
reed | bb8a0ab | 2014-11-03 22:32:07 -0800 | [diff] [blame] | 904 | { "setDither", lpaint_setDither }, |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 905 | { "getFilterQuality", lpaint_getFilterQuality }, |
| 906 | { "setFilterQuality", lpaint_setFilterQuality }, |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 907 | { "getAlpha", lpaint_getAlpha }, |
| 908 | { "setAlpha", lpaint_setAlpha }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 909 | { "getColor", lpaint_getColor }, |
| 910 | { "setColor", lpaint_setColor }, |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 911 | { "getStroke", lpaint_getStroke }, |
| 912 | { "setStroke", lpaint_setStroke }, |
commit-bot@chromium.org | 1cd71fb | 2013-12-18 18:28:07 +0000 | [diff] [blame] | 913 | { "getStrokeCap", lpaint_getStrokeCap }, |
| 914 | { "getStrokeJoin", lpaint_getStrokeJoin }, |
mike@reedtribe.org | 73d9f1c | 2013-06-09 01:54:56 +0000 | [diff] [blame] | 915 | { "getStrokeWidth", lpaint_getStrokeWidth }, |
| 916 | { "setStrokeWidth", lpaint_setStrokeWidth }, |
commit-bot@chromium.org | 1cd71fb | 2013-12-18 18:28:07 +0000 | [diff] [blame] | 917 | { "getStrokeMiter", lpaint_getStrokeMiter }, |
reed@google.com | 2956387 | 2013-07-10 21:23:49 +0000 | [diff] [blame] | 918 | { "getEffects", lpaint_getEffects }, |
reed | 22a517f | 2015-12-04 20:45:59 -0800 | [diff] [blame] | 919 | { "getColorFilter", lpaint_getColorFilter }, |
| 920 | { "setColorFilter", lpaint_setColorFilter }, |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 921 | { "getImageFilter", lpaint_getImageFilter }, |
| 922 | { "setImageFilter", lpaint_setImageFilter }, |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 923 | { "getShader", lpaint_getShader }, |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 924 | { "setShader", lpaint_setShader }, |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 925 | { "getPathEffect", lpaint_getPathEffect }, |
hstern | 0b401ce | 2016-08-02 09:17:59 -0700 | [diff] [blame] | 926 | { "getFillPath", lpaint_getFillPath }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 927 | { "__gc", lpaint_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 928 | { nullptr, nullptr } |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
| 931 | /////////////////////////////////////////////////////////////////////////////// |
| 932 | |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 933 | static int lfont_getSize(lua_State* L) { |
| 934 | SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getSize()); |
| 935 | return 1; |
| 936 | } |
| 937 | |
| 938 | static int lfont_getScaleX(lua_State* L) { |
| 939 | SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getScaleX()); |
| 940 | return 1; |
| 941 | } |
| 942 | |
| 943 | static int lfont_getSkewX(lua_State* L) { |
| 944 | SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->getSkewX()); |
| 945 | return 1; |
| 946 | } |
| 947 | |
| 948 | static int lfont_setSize(lua_State* L) { |
| 949 | get_obj<SkFont>(L, 1)->setSize(lua2scalar(L, 2)); |
| 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | static int lfont_getTypeface(lua_State* L) { |
Herb Derby | 087fad7 | 2019-01-22 14:45:16 -0500 | [diff] [blame] | 954 | push_ref(L, get_obj<SkFont>(L, 1)->getTypefaceOrDefault()); |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 955 | return 1; |
| 956 | } |
| 957 | |
| 958 | static int lfont_setTypeface(lua_State* L) { |
| 959 | get_obj<SkFont>(L, 1)->setTypeface(sk_ref_sp(get_ref<SkTypeface>(L, 2))); |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static int lfont_getHinting(lua_State* L) { |
| 964 | SkLua(L).pushU32((unsigned)get_obj<SkFont>(L, 1)->getHinting()); |
| 965 | return 1; |
| 966 | } |
| 967 | |
| 968 | static int lfont_getFontID(lua_State* L) { |
Herb Derby | 087fad7 | 2019-01-22 14:45:16 -0500 | [diff] [blame] | 969 | SkTypeface* face = get_obj<SkFont>(L, 1)->getTypefaceOrDefault(); |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 970 | SkLua(L).pushU32(SkTypeface::UniqueID(face)); |
| 971 | return 1; |
| 972 | } |
| 973 | |
| 974 | static int lfont_measureText(lua_State* L) { |
| 975 | if (lua_isstring(L, 2)) { |
| 976 | size_t len; |
| 977 | const char* text = lua_tolstring(L, 2, &len); |
Ben Wagner | 51e15a6 | 2019-05-07 15:38:46 -0400 | [diff] [blame] | 978 | SkLua(L).pushScalar(get_obj<SkFont>(L, 1)->measureText(text, len, SkTextEncoding::kUTF8)); |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 979 | return 1; |
| 980 | } |
| 981 | return 0; |
| 982 | } |
| 983 | |
| 984 | static int lfont_getMetrics(lua_State* L) { |
| 985 | SkFontMetrics fm; |
| 986 | SkScalar height = get_obj<SkFont>(L, 1)->getMetrics(&fm); |
| 987 | |
| 988 | lua_newtable(L); |
| 989 | setfield_scalar(L, "top", fm.fTop); |
| 990 | setfield_scalar(L, "ascent", fm.fAscent); |
| 991 | setfield_scalar(L, "descent", fm.fDescent); |
| 992 | setfield_scalar(L, "bottom", fm.fBottom); |
| 993 | setfield_scalar(L, "leading", fm.fLeading); |
| 994 | SkLua(L).pushScalar(height); |
| 995 | return 2; |
| 996 | } |
| 997 | |
| 998 | static int lfont_gc(lua_State* L) { |
| 999 | get_obj<SkFont>(L, 1)->~SkFont(); |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
| 1003 | static const struct luaL_Reg gSkFont_Methods[] = { |
| 1004 | { "getSize", lfont_getSize }, |
| 1005 | { "setSize", lfont_setSize }, |
| 1006 | { "getScaleX", lfont_getScaleX }, |
| 1007 | { "getSkewX", lfont_getSkewX }, |
| 1008 | { "getTypeface", lfont_getTypeface }, |
| 1009 | { "setTypeface", lfont_setTypeface }, |
| 1010 | { "getHinting", lfont_getHinting }, |
| 1011 | { "getFontID", lfont_getFontID }, |
| 1012 | { "measureText", lfont_measureText }, |
| 1013 | { "getMetrics", lfont_getMetrics }, |
| 1014 | { "__gc", lfont_gc }, |
| 1015 | { nullptr, nullptr } |
| 1016 | }; |
| 1017 | |
| 1018 | /////////////////////////////////////////////////////////////////////////////// |
| 1019 | |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 1020 | static const char* mode2string(SkTileMode mode) { |
| 1021 | static const char* gNames[] = { "clamp", "repeat", "mirror", "decal" }; |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1022 | SkASSERT((unsigned)mode < SK_ARRAY_COUNT(gNames)); |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 1023 | return gNames[static_cast<int>(mode)]; |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static const char* gradtype2string(SkShader::GradientType t) { |
| 1027 | static const char* gNames[] = { |
| 1028 | "none", "color", "linear", "radial", "radial2", "sweep", "conical" |
| 1029 | }; |
| 1030 | SkASSERT((unsigned)t < SK_ARRAY_COUNT(gNames)); |
| 1031 | return gNames[t]; |
| 1032 | } |
| 1033 | |
| 1034 | static int lshader_isOpaque(lua_State* L) { |
| 1035 | SkShader* shader = get_ref<SkShader>(L, 1); |
| 1036 | return shader && shader->isOpaque(); |
| 1037 | } |
| 1038 | |
Mike Reed | 627778d | 2016-09-28 17:13:38 -0400 | [diff] [blame] | 1039 | static int lshader_isAImage(lua_State* L) { |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1040 | SkShader* shader = get_ref<SkShader>(L, 1); |
| 1041 | if (shader) { |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1042 | SkMatrix matrix; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 1043 | SkTileMode modes[2]; |
Mike Reed | 627778d | 2016-09-28 17:13:38 -0400 | [diff] [blame] | 1044 | if (SkImage* image = shader->isAImage(&matrix, modes)) { |
reed | f582282 | 2015-08-19 11:46:38 -0700 | [diff] [blame] | 1045 | lua_newtable(L); |
Mike Reed | 627778d | 2016-09-28 17:13:38 -0400 | [diff] [blame] | 1046 | setfield_number(L, "id", image->uniqueID()); |
| 1047 | setfield_number(L, "width", image->width()); |
| 1048 | setfield_number(L, "height", image->height()); |
reed | f582282 | 2015-08-19 11:46:38 -0700 | [diff] [blame] | 1049 | setfield_string(L, "tileX", mode2string(modes[0])); |
| 1050 | setfield_string(L, "tileY", mode2string(modes[1])); |
| 1051 | return 1; |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | static int lshader_asAGradient(lua_State* L) { |
| 1058 | SkShader* shader = get_ref<SkShader>(L, 1); |
| 1059 | if (shader) { |
| 1060 | SkShader::GradientInfo info; |
| 1061 | sk_bzero(&info, sizeof(info)); |
commit-bot@chromium.org | 74f96b9 | 2013-08-01 17:32:56 +0000 | [diff] [blame] | 1062 | |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1063 | SkShader::GradientType t = shader->asAGradient(&info); |
commit-bot@chromium.org | 74f96b9 | 2013-08-01 17:32:56 +0000 | [diff] [blame] | 1064 | |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1065 | if (SkShader::kNone_GradientType != t) { |
fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 1066 | SkAutoTArray<SkScalar> pos(info.fColorCount); |
| 1067 | info.fColorOffsets = pos.get(); |
| 1068 | shader->asAGradient(&info); |
commit-bot@chromium.org | 74f96b9 | 2013-08-01 17:32:56 +0000 | [diff] [blame] | 1069 | |
fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 1070 | lua_newtable(L); |
fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 1071 | setfield_string(L, "type", gradtype2string(t)); |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 1072 | setfield_string(L, "tile", mode2string((SkTileMode)info.fTileMode)); |
fmenozzi | 7f2c85e | 2016-07-12 09:17:39 -0700 | [diff] [blame] | 1073 | setfield_number(L, "colorCount", info.fColorCount); |
fmenozzi | b4f254e | 2016-06-28 14:03:03 -0700 | [diff] [blame] | 1074 | |
| 1075 | lua_newtable(L); |
| 1076 | for (int i = 0; i < info.fColorCount; i++) { |
| 1077 | // Lua uses 1-based indexing |
| 1078 | setarray_scalar(L, i+1, pos[i]); |
| 1079 | } |
| 1080 | lua_setfield(L, -2, "positions"); |
| 1081 | |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1082 | return 1; |
| 1083 | } |
| 1084 | } |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
| 1088 | static int lshader_gc(lua_State* L) { |
| 1089 | get_ref<SkShader>(L, 1)->unref(); |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | static const struct luaL_Reg gSkShader_Methods[] = { |
| 1094 | { "isOpaque", lshader_isOpaque }, |
Mike Reed | 627778d | 2016-09-28 17:13:38 -0400 | [diff] [blame] | 1095 | { "isAImage", lshader_isAImage }, |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1096 | { "asAGradient", lshader_asAGradient }, |
| 1097 | { "__gc", lshader_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1098 | { nullptr, nullptr } |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1099 | }; |
| 1100 | |
| 1101 | /////////////////////////////////////////////////////////////////////////////// |
| 1102 | |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 1103 | static int lpatheffect_asADash(lua_State* L) { |
| 1104 | SkPathEffect* pe = get_ref<SkPathEffect>(L, 1); |
| 1105 | if (pe) { |
| 1106 | SkPathEffect::DashInfo info; |
| 1107 | SkPathEffect::DashType dashType = pe->asADash(&info); |
| 1108 | if (SkPathEffect::kDash_DashType == dashType) { |
| 1109 | SkAutoTArray<SkScalar> intervals(info.fCount); |
| 1110 | info.fIntervals = intervals.get(); |
| 1111 | pe->asADash(&info); |
| 1112 | SkLua(L).pushDash(info); |
| 1113 | return 1; |
| 1114 | } |
| 1115 | } |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 1119 | static int lpatheffect_gc(lua_State* L) { |
| 1120 | get_ref<SkPathEffect>(L, 1)->unref(); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | static const struct luaL_Reg gSkPathEffect_Methods[] = { |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 1125 | { "asADash", lpatheffect_asADash }, |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 1126 | { "__gc", lpatheffect_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1127 | { nullptr, nullptr } |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 1128 | }; |
| 1129 | |
| 1130 | /////////////////////////////////////////////////////////////////////////////// |
| 1131 | |
reed | 22a517f | 2015-12-04 20:45:59 -0800 | [diff] [blame] | 1132 | static int lpcolorfilter_gc(lua_State* L) { |
| 1133 | get_ref<SkColorFilter>(L, 1)->unref(); |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | static const struct luaL_Reg gSkColorFilter_Methods[] = { |
| 1138 | { "__gc", lpcolorfilter_gc }, |
| 1139 | { nullptr, nullptr } |
| 1140 | }; |
| 1141 | |
| 1142 | /////////////////////////////////////////////////////////////////////////////// |
| 1143 | |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1144 | static int lpimagefilter_gc(lua_State* L) { |
| 1145 | get_ref<SkImageFilter>(L, 1)->unref(); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | static const struct luaL_Reg gSkImageFilter_Methods[] = { |
| 1150 | { "__gc", lpimagefilter_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1151 | { nullptr, nullptr } |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | /////////////////////////////////////////////////////////////////////////////// |
| 1155 | |
humper@google.com | 2815c19 | 2013-07-10 22:42:30 +0000 | [diff] [blame] | 1156 | static int lmatrix_getType(lua_State* L) { |
| 1157 | SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType(); |
skia.committer@gmail.com | de2e4e8 | 2013-07-11 07:01:01 +0000 | [diff] [blame] | 1158 | |
humper@google.com | 2815c19 | 2013-07-10 22:42:30 +0000 | [diff] [blame] | 1159 | lua_newtable(L); |
| 1160 | setfield_boolean(L, "translate", SkToBool(mask & SkMatrix::kTranslate_Mask)); |
| 1161 | setfield_boolean(L, "scale", SkToBool(mask & SkMatrix::kScale_Mask)); |
| 1162 | setfield_boolean(L, "affine", SkToBool(mask & SkMatrix::kAffine_Mask)); |
| 1163 | setfield_boolean(L, "perspective", SkToBool(mask & SkMatrix::kPerspective_Mask)); |
| 1164 | return 1; |
| 1165 | } |
| 1166 | |
humper@google.com | 0f48ee0 | 2013-07-26 15:23:43 +0000 | [diff] [blame] | 1167 | static int lmatrix_getScaleX(lua_State* L) { |
| 1168 | lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getScaleX()); |
| 1169 | return 1; |
| 1170 | } |
| 1171 | |
| 1172 | static int lmatrix_getScaleY(lua_State* L) { |
| 1173 | lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getScaleY()); |
| 1174 | return 1; |
| 1175 | } |
| 1176 | |
| 1177 | static int lmatrix_getTranslateX(lua_State* L) { |
| 1178 | lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateX()); |
| 1179 | return 1; |
| 1180 | } |
| 1181 | |
| 1182 | static int lmatrix_getTranslateY(lua_State* L) { |
| 1183 | lua_pushnumber(L, get_obj<SkMatrix>(L,1)->getTranslateY()); |
| 1184 | return 1; |
| 1185 | } |
| 1186 | |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 1187 | static int lmatrix_invert(lua_State* L) { |
| 1188 | lua_pushboolean(L, get_obj<SkMatrix>(L, 1)->invert(get_obj<SkMatrix>(L, 2))); |
| 1189 | return 1; |
| 1190 | } |
| 1191 | |
| 1192 | static int lmatrix_mapXY(lua_State* L) { |
| 1193 | SkPoint pt = { lua2scalar(L, 2), lua2scalar(L, 3) }; |
| 1194 | get_obj<SkMatrix>(L, 1)->mapPoints(&pt, &pt, 1); |
| 1195 | lua_pushnumber(L, pt.x()); |
| 1196 | lua_pushnumber(L, pt.y()); |
| 1197 | return 2; |
| 1198 | } |
| 1199 | |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 1200 | static int lmatrix_setRectToRect(lua_State* L) { |
| 1201 | SkMatrix* matrix = get_obj<SkMatrix>(L, 1); |
| 1202 | SkRect srcR, dstR; |
| 1203 | lua2rect(L, 2, &srcR); |
| 1204 | lua2rect(L, 3, &dstR); |
| 1205 | const char* scaleToFitStr = lua_tostring(L, 4); |
| 1206 | SkMatrix::ScaleToFit scaleToFit = SkMatrix::kFill_ScaleToFit; |
| 1207 | |
| 1208 | if (scaleToFitStr) { |
| 1209 | const struct { |
| 1210 | const char* fName; |
| 1211 | SkMatrix::ScaleToFit fScaleToFit; |
| 1212 | } rec[] = { |
| 1213 | { "fill", SkMatrix::kFill_ScaleToFit }, |
| 1214 | { "start", SkMatrix::kStart_ScaleToFit }, |
| 1215 | { "center", SkMatrix::kCenter_ScaleToFit }, |
| 1216 | { "end", SkMatrix::kEnd_ScaleToFit }, |
| 1217 | }; |
| 1218 | |
| 1219 | for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { |
| 1220 | if (strcmp(rec[i].fName, scaleToFitStr) == 0) { |
| 1221 | scaleToFit = rec[i].fScaleToFit; |
| 1222 | break; |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | matrix->setRectToRect(srcR, dstR, scaleToFit); |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
humper@google.com | 2815c19 | 2013-07-10 22:42:30 +0000 | [diff] [blame] | 1231 | static const struct luaL_Reg gSkMatrix_Methods[] = { |
| 1232 | { "getType", lmatrix_getType }, |
humper@google.com | 0f48ee0 | 2013-07-26 15:23:43 +0000 | [diff] [blame] | 1233 | { "getScaleX", lmatrix_getScaleX }, |
| 1234 | { "getScaleY", lmatrix_getScaleY }, |
| 1235 | { "getTranslateX", lmatrix_getTranslateX }, |
| 1236 | { "getTranslateY", lmatrix_getTranslateY }, |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 1237 | { "setRectToRect", lmatrix_setRectToRect }, |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 1238 | { "invert", lmatrix_invert }, |
| 1239 | { "mapXY", lmatrix_mapXY }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1240 | { nullptr, nullptr } |
humper@google.com | 2815c19 | 2013-07-10 22:42:30 +0000 | [diff] [blame] | 1241 | }; |
| 1242 | |
| 1243 | /////////////////////////////////////////////////////////////////////////////// |
| 1244 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1245 | static int lpath_getBounds(lua_State* L) { |
| 1246 | SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); |
| 1247 | return 1; |
| 1248 | } |
| 1249 | |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1250 | static const char* fill_type_to_str(SkPathFillType fill) { |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1251 | switch (fill) { |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1252 | case SkPathFillType::kEvenOdd: |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1253 | return "even-odd"; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1254 | case SkPathFillType::kWinding: |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1255 | return "winding"; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1256 | case SkPathFillType::kInverseEvenOdd: |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1257 | return "inverse-even-odd"; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 1258 | case SkPathFillType::kInverseWinding: |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1259 | return "inverse-winding"; |
| 1260 | } |
| 1261 | return "unknown"; |
| 1262 | } |
| 1263 | |
| 1264 | static int lpath_getFillType(lua_State* L) { |
Mike Reed | cf0e3c6 | 2019-12-03 16:26:15 -0500 | [diff] [blame] | 1265 | SkPathFillType fill = get_obj<SkPath>(L, 1)->getFillType(); |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1266 | SkLua(L).pushString(fill_type_to_str(fill)); |
| 1267 | return 1; |
| 1268 | } |
| 1269 | |
| 1270 | static SkString segment_masks_to_str(uint32_t segmentMasks) { |
| 1271 | SkString result; |
| 1272 | bool first = true; |
| 1273 | if (SkPath::kLine_SegmentMask & segmentMasks) { |
| 1274 | result.append("line"); |
| 1275 | first = false; |
| 1276 | SkDEBUGCODE(segmentMasks &= ~SkPath::kLine_SegmentMask;) |
| 1277 | } |
| 1278 | if (SkPath::kQuad_SegmentMask & segmentMasks) { |
| 1279 | if (!first) { |
| 1280 | result.append(" "); |
| 1281 | } |
| 1282 | result.append("quad"); |
| 1283 | first = false; |
| 1284 | SkDEBUGCODE(segmentMasks &= ~SkPath::kQuad_SegmentMask;) |
| 1285 | } |
| 1286 | if (SkPath::kConic_SegmentMask & segmentMasks) { |
| 1287 | if (!first) { |
| 1288 | result.append(" "); |
| 1289 | } |
| 1290 | result.append("conic"); |
| 1291 | first = false; |
| 1292 | SkDEBUGCODE(segmentMasks &= ~SkPath::kConic_SegmentMask;) |
| 1293 | } |
| 1294 | if (SkPath::kCubic_SegmentMask & segmentMasks) { |
| 1295 | if (!first) { |
| 1296 | result.append(" "); |
| 1297 | } |
| 1298 | result.append("cubic"); |
| 1299 | SkDEBUGCODE(segmentMasks &= ~SkPath::kCubic_SegmentMask;) |
| 1300 | } |
| 1301 | SkASSERT(0 == segmentMasks); |
| 1302 | return result; |
| 1303 | } |
| 1304 | |
krajcevski | 95498ed | 2014-08-18 08:02:33 -0700 | [diff] [blame] | 1305 | static int lpath_getSegmentTypes(lua_State* L) { |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1306 | uint32_t segMasks = get_obj<SkPath>(L, 1)->getSegmentMasks(); |
| 1307 | SkLua(L).pushString(segment_masks_to_str(segMasks)); |
| 1308 | return 1; |
| 1309 | } |
| 1310 | |
| 1311 | static int lpath_isConvex(lua_State* L) { |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 1312 | bool isConvex = get_obj<SkPath>(L, 1)->isConvex(); |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1313 | SkLua(L).pushBool(isConvex); |
| 1314 | return 1; |
| 1315 | } |
| 1316 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1317 | static int lpath_isEmpty(lua_State* L) { |
| 1318 | lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty()); |
| 1319 | return 1; |
| 1320 | } |
| 1321 | |
| 1322 | static int lpath_isRect(lua_State* L) { |
| 1323 | SkRect r; |
| 1324 | bool pred = get_obj<SkPath>(L, 1)->isRect(&r); |
| 1325 | int ret_count = 1; |
| 1326 | lua_pushboolean(L, pred); |
| 1327 | if (pred) { |
| 1328 | SkLua(L).pushRect(r); |
| 1329 | ret_count += 1; |
| 1330 | } |
| 1331 | return ret_count; |
| 1332 | } |
| 1333 | |
commit-bot@chromium.org | c530208 | 2014-02-26 21:38:47 +0000 | [diff] [blame] | 1334 | static int lpath_countPoints(lua_State* L) { |
| 1335 | lua_pushinteger(L, get_obj<SkPath>(L, 1)->countPoints()); |
| 1336 | return 1; |
| 1337 | } |
| 1338 | |
hstern | 0b401ce | 2016-08-02 09:17:59 -0700 | [diff] [blame] | 1339 | static int lpath_getVerbs(lua_State* L) { |
| 1340 | const SkPath* path = get_obj<SkPath>(L, 1); |
| 1341 | SkPath::Iter iter(*path, false); |
| 1342 | SkPoint pts[4]; |
| 1343 | |
| 1344 | lua_newtable(L); |
| 1345 | |
| 1346 | bool done = false; |
| 1347 | int i = 0; |
| 1348 | do { |
Mike Reed | ba7e9a6 | 2019-08-16 13:30:34 -0400 | [diff] [blame] | 1349 | switch (iter.next(pts)) { |
hstern | 0b401ce | 2016-08-02 09:17:59 -0700 | [diff] [blame] | 1350 | case SkPath::kMove_Verb: |
| 1351 | setarray_string(L, ++i, "move"); |
| 1352 | break; |
| 1353 | case SkPath::kClose_Verb: |
| 1354 | setarray_string(L, ++i, "close"); |
| 1355 | break; |
| 1356 | case SkPath::kLine_Verb: |
| 1357 | setarray_string(L, ++i, "line"); |
| 1358 | break; |
| 1359 | case SkPath::kQuad_Verb: |
| 1360 | setarray_string(L, ++i, "quad"); |
| 1361 | break; |
| 1362 | case SkPath::kConic_Verb: |
| 1363 | setarray_string(L, ++i, "conic"); |
| 1364 | break; |
| 1365 | case SkPath::kCubic_Verb: |
| 1366 | setarray_string(L, ++i, "cubic"); |
| 1367 | break; |
| 1368 | case SkPath::kDone_Verb: |
| 1369 | setarray_string(L, ++i, "done"); |
| 1370 | done = true; |
| 1371 | break; |
| 1372 | } |
| 1373 | } while (!done); |
| 1374 | |
| 1375 | return 1; |
| 1376 | } |
| 1377 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1378 | static int lpath_reset(lua_State* L) { |
| 1379 | get_obj<SkPath>(L, 1)->reset(); |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | static int lpath_moveTo(lua_State* L) { |
| 1384 | get_obj<SkPath>(L, 1)->moveTo(lua2scalar(L, 2), lua2scalar(L, 3)); |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
| 1388 | static int lpath_lineTo(lua_State* L) { |
| 1389 | get_obj<SkPath>(L, 1)->lineTo(lua2scalar(L, 2), lua2scalar(L, 3)); |
| 1390 | return 0; |
| 1391 | } |
| 1392 | |
| 1393 | static int lpath_quadTo(lua_State* L) { |
| 1394 | get_obj<SkPath>(L, 1)->quadTo(lua2scalar(L, 2), lua2scalar(L, 3), |
| 1395 | lua2scalar(L, 4), lua2scalar(L, 5)); |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
| 1399 | static int lpath_cubicTo(lua_State* L) { |
| 1400 | get_obj<SkPath>(L, 1)->cubicTo(lua2scalar(L, 2), lua2scalar(L, 3), |
| 1401 | lua2scalar(L, 4), lua2scalar(L, 5), |
| 1402 | lua2scalar(L, 6), lua2scalar(L, 7)); |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | static int lpath_close(lua_State* L) { |
| 1407 | get_obj<SkPath>(L, 1)->close(); |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
| 1411 | static int lpath_gc(lua_State* L) { |
| 1412 | get_obj<SkPath>(L, 1)->~SkPath(); |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | static const struct luaL_Reg gSkPath_Methods[] = { |
| 1417 | { "getBounds", lpath_getBounds }, |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1418 | { "getFillType", lpath_getFillType }, |
krajcevski | 95498ed | 2014-08-18 08:02:33 -0700 | [diff] [blame] | 1419 | { "getSegmentTypes", lpath_getSegmentTypes }, |
hstern | 0b401ce | 2016-08-02 09:17:59 -0700 | [diff] [blame] | 1420 | { "getVerbs", lpath_getVerbs }, |
commit-bot@chromium.org | d85b822 | 2014-02-24 21:59:29 +0000 | [diff] [blame] | 1421 | { "isConvex", lpath_isConvex }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1422 | { "isEmpty", lpath_isEmpty }, |
| 1423 | { "isRect", lpath_isRect }, |
commit-bot@chromium.org | c530208 | 2014-02-26 21:38:47 +0000 | [diff] [blame] | 1424 | { "countPoints", lpath_countPoints }, |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1425 | { "reset", lpath_reset }, |
| 1426 | { "moveTo", lpath_moveTo }, |
| 1427 | { "lineTo", lpath_lineTo }, |
| 1428 | { "quadTo", lpath_quadTo }, |
| 1429 | { "cubicTo", lpath_cubicTo }, |
| 1430 | { "close", lpath_close }, |
| 1431 | { "__gc", lpath_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1432 | { nullptr, nullptr } |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1433 | }; |
| 1434 | |
| 1435 | /////////////////////////////////////////////////////////////////////////////// |
| 1436 | |
| 1437 | static const char* rrect_type(const SkRRect& rr) { |
| 1438 | switch (rr.getType()) { |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1439 | case SkRRect::kEmpty_Type: return "empty"; |
| 1440 | case SkRRect::kRect_Type: return "rect"; |
| 1441 | case SkRRect::kOval_Type: return "oval"; |
| 1442 | case SkRRect::kSimple_Type: return "simple"; |
commit-bot@chromium.org | f338d7c | 2014-03-17 21:17:30 +0000 | [diff] [blame] | 1443 | case SkRRect::kNinePatch_Type: return "nine-patch"; |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1444 | case SkRRect::kComplex_Type: return "complex"; |
| 1445 | } |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1446 | SkDEBUGFAIL("never get here"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1447 | return ""; |
| 1448 | } |
| 1449 | |
| 1450 | static int lrrect_rect(lua_State* L) { |
| 1451 | SkLua(L).pushRect(get_obj<SkRRect>(L, 1)->rect()); |
| 1452 | return 1; |
| 1453 | } |
| 1454 | |
| 1455 | static int lrrect_type(lua_State* L) { |
| 1456 | lua_pushstring(L, rrect_type(*get_obj<SkRRect>(L, 1))); |
| 1457 | return 1; |
| 1458 | } |
| 1459 | |
| 1460 | static int lrrect_radii(lua_State* L) { |
reed@google.com | 7fa2a65 | 2014-01-27 13:42:58 +0000 | [diff] [blame] | 1461 | int corner = SkToInt(lua_tointeger(L, 2)); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1462 | SkVector v; |
| 1463 | if (corner < 0 || corner > 3) { |
| 1464 | SkDebugf("bad corner index %d", corner); |
| 1465 | v.set(0, 0); |
| 1466 | } else { |
| 1467 | v = get_obj<SkRRect>(L, 1)->radii((SkRRect::Corner)corner); |
| 1468 | } |
| 1469 | lua_pushnumber(L, v.fX); |
| 1470 | lua_pushnumber(L, v.fY); |
| 1471 | return 2; |
| 1472 | } |
| 1473 | |
| 1474 | static int lrrect_gc(lua_State* L) { |
| 1475 | get_obj<SkRRect>(L, 1)->~SkRRect(); |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
| 1479 | static const struct luaL_Reg gSkRRect_Methods[] = { |
| 1480 | { "rect", lrrect_rect }, |
| 1481 | { "type", lrrect_type }, |
| 1482 | { "radii", lrrect_radii }, |
| 1483 | { "__gc", lrrect_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1484 | { nullptr, nullptr } |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1485 | }; |
| 1486 | |
| 1487 | /////////////////////////////////////////////////////////////////////////////// |
| 1488 | |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1489 | static int limage_width(lua_State* L) { |
| 1490 | lua_pushinteger(L, get_ref<SkImage>(L, 1)->width()); |
| 1491 | return 1; |
| 1492 | } |
| 1493 | |
| 1494 | static int limage_height(lua_State* L) { |
| 1495 | lua_pushinteger(L, get_ref<SkImage>(L, 1)->height()); |
| 1496 | return 1; |
| 1497 | } |
| 1498 | |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 1499 | static int limage_newShader(lua_State* L) { |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 1500 | SkTileMode tmode = SkTileMode::kClamp; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1501 | const SkMatrix* localM = nullptr; |
reed | 5671c5b | 2016-03-09 14:47:34 -0800 | [diff] [blame] | 1502 | push_ref(L, get_ref<SkImage>(L, 1)->makeShader(tmode, tmode, localM)); |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 1503 | return 1; |
| 1504 | } |
| 1505 | |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1506 | static int limage_gc(lua_State* L) { |
| 1507 | get_ref<SkImage>(L, 1)->unref(); |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | static const struct luaL_Reg gSkImage_Methods[] = { |
| 1512 | { "width", limage_width }, |
| 1513 | { "height", limage_height }, |
reed | 7a72c67 | 2014-11-07 10:23:55 -0800 | [diff] [blame] | 1514 | { "newShader", limage_newShader }, |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1515 | { "__gc", limage_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1516 | { nullptr, nullptr } |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1517 | }; |
| 1518 | |
| 1519 | /////////////////////////////////////////////////////////////////////////////// |
| 1520 | |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1521 | static int lsurface_width(lua_State* L) { |
| 1522 | lua_pushinteger(L, get_ref<SkSurface>(L, 1)->width()); |
| 1523 | return 1; |
| 1524 | } |
| 1525 | |
| 1526 | static int lsurface_height(lua_State* L) { |
| 1527 | lua_pushinteger(L, get_ref<SkSurface>(L, 1)->height()); |
| 1528 | return 1; |
| 1529 | } |
| 1530 | |
| 1531 | static int lsurface_getCanvas(lua_State* L) { |
| 1532 | SkCanvas* canvas = get_ref<SkSurface>(L, 1)->getCanvas(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1533 | if (nullptr == canvas) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1534 | lua_pushnil(L); |
| 1535 | } else { |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 1536 | push_ptr(L, canvas); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1537 | // note: we don't unref canvas, since getCanvas did not ref it. |
| 1538 | // warning: this is weird: now Lua owns a ref on this canvas, but what if they let |
| 1539 | // the real owner (the surface) go away, but still hold onto the canvas? |
| 1540 | // *really* we want to sort of ref the surface again, but have the native object |
| 1541 | // know that it is supposed to be treated as a canvas... |
| 1542 | } |
| 1543 | return 1; |
| 1544 | } |
| 1545 | |
| 1546 | static int lsurface_newImageSnapshot(lua_State* L) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 1547 | sk_sp<SkImage> image = get_ref<SkSurface>(L, 1)->makeImageSnapshot(); |
| 1548 | if (!image) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1549 | lua_pushnil(L); |
| 1550 | } else { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 1551 | push_ref(L, image); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1552 | } |
| 1553 | return 1; |
| 1554 | } |
| 1555 | |
| 1556 | static int lsurface_newSurface(lua_State* L) { |
| 1557 | int width = lua2int_def(L, 2, 0); |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1558 | int height = lua2int_def(L, 3, 0); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1559 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1560 | auto surface = get_ref<SkSurface>(L, 1)->makeSurface(info); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1561 | if (nullptr == surface) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1562 | lua_pushnil(L); |
| 1563 | } else { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1564 | push_ref(L, surface); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1565 | } |
| 1566 | return 1; |
| 1567 | } |
| 1568 | |
| 1569 | static int lsurface_gc(lua_State* L) { |
| 1570 | get_ref<SkSurface>(L, 1)->unref(); |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
| 1574 | static const struct luaL_Reg gSkSurface_Methods[] = { |
| 1575 | { "width", lsurface_width }, |
| 1576 | { "height", lsurface_height }, |
| 1577 | { "getCanvas", lsurface_getCanvas }, |
| 1578 | { "newImageSnapshot", lsurface_newImageSnapshot }, |
| 1579 | { "newSurface", lsurface_newSurface }, |
| 1580 | { "__gc", lsurface_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1581 | { nullptr, nullptr } |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1582 | }; |
| 1583 | |
| 1584 | /////////////////////////////////////////////////////////////////////////////// |
| 1585 | |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1586 | static int lpicturerecorder_beginRecording(lua_State* L) { |
| 1587 | const SkScalar w = lua2scalar_def(L, 2, -1); |
| 1588 | const SkScalar h = lua2scalar_def(L, 3, -1); |
| 1589 | if (w <= 0 || h <= 0) { |
| 1590 | lua_pushnil(L); |
| 1591 | return 1; |
| 1592 | } |
| 1593 | |
| 1594 | SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->beginRecording(w, h); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1595 | if (nullptr == canvas) { |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1596 | lua_pushnil(L); |
| 1597 | return 1; |
| 1598 | } |
| 1599 | |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 1600 | push_ptr(L, canvas); |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1601 | return 1; |
| 1602 | } |
| 1603 | |
| 1604 | static int lpicturerecorder_getCanvas(lua_State* L) { |
| 1605 | SkCanvas* canvas = get_obj<SkPictureRecorder>(L, 1)->getRecordingCanvas(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1606 | if (nullptr == canvas) { |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1607 | lua_pushnil(L); |
| 1608 | return 1; |
| 1609 | } |
Mike Reed | 5df4934 | 2016-11-12 08:06:55 -0600 | [diff] [blame] | 1610 | push_ptr(L, canvas); |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1611 | return 1; |
| 1612 | } |
| 1613 | |
| 1614 | static int lpicturerecorder_endRecording(lua_State* L) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1615 | sk_sp<SkPicture> pic = get_obj<SkPictureRecorder>(L, 1)->finishRecordingAsPicture(); |
| 1616 | if (!pic) { |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1617 | lua_pushnil(L); |
| 1618 | return 1; |
| 1619 | } |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 1620 | push_ref(L, std::move(pic)); |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1621 | return 1; |
| 1622 | } |
| 1623 | |
| 1624 | static int lpicturerecorder_gc(lua_State* L) { |
| 1625 | get_obj<SkPictureRecorder>(L, 1)->~SkPictureRecorder(); |
| 1626 | return 0; |
| 1627 | } |
| 1628 | |
| 1629 | static const struct luaL_Reg gSkPictureRecorder_Methods[] = { |
| 1630 | { "beginRecording", lpicturerecorder_beginRecording }, |
| 1631 | { "getCanvas", lpicturerecorder_getCanvas }, |
| 1632 | { "endRecording", lpicturerecorder_endRecording }, |
| 1633 | { "__gc", lpicturerecorder_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1634 | { nullptr, nullptr } |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1635 | }; |
| 1636 | |
| 1637 | /////////////////////////////////////////////////////////////////////////////// |
| 1638 | |
| 1639 | static int lpicture_width(lua_State* L) { |
| 1640 | lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().width()); |
| 1641 | return 1; |
| 1642 | } |
| 1643 | |
| 1644 | static int lpicture_height(lua_State* L) { |
| 1645 | lua_pushnumber(L, get_ref<SkPicture>(L, 1)->cullRect().height()); |
| 1646 | return 1; |
| 1647 | } |
| 1648 | |
| 1649 | static int lpicture_gc(lua_State* L) { |
| 1650 | get_ref<SkPicture>(L, 1)->unref(); |
| 1651 | return 0; |
| 1652 | } |
| 1653 | |
| 1654 | static const struct luaL_Reg gSkPicture_Methods[] = { |
| 1655 | { "width", lpicture_width }, |
| 1656 | { "height", lpicture_height }, |
| 1657 | { "__gc", lpicture_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1658 | { nullptr, nullptr } |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1659 | }; |
| 1660 | |
| 1661 | /////////////////////////////////////////////////////////////////////////////// |
| 1662 | |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1663 | static int ltextblob_bounds(lua_State* L) { |
| 1664 | SkLua(L).pushRect(get_ref<SkTextBlob>(L, 1)->bounds()); |
| 1665 | return 1; |
| 1666 | } |
| 1667 | |
| 1668 | static int ltextblob_gc(lua_State* L) { |
| 1669 | SkSafeUnref(get_ref<SkTextBlob>(L, 1)); |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
| 1673 | static const struct luaL_Reg gSkTextBlob_Methods[] = { |
| 1674 | { "bounds", ltextblob_bounds }, |
| 1675 | { "__gc", ltextblob_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1676 | { nullptr, nullptr } |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1677 | }; |
| 1678 | |
| 1679 | /////////////////////////////////////////////////////////////////////////////// |
| 1680 | |
reed | 36c9c11 | 2014-11-04 10:58:42 -0800 | [diff] [blame] | 1681 | static int ltypeface_getFamilyName(lua_State* L) { |
| 1682 | SkString str; |
| 1683 | get_ref<SkTypeface>(L, 1)->getFamilyName(&str); |
| 1684 | lua_pushstring(L, str.c_str()); |
| 1685 | return 1; |
| 1686 | } |
| 1687 | |
| 1688 | static int ltypeface_getStyle(lua_State* L) { |
Ben Wagner | 26308e1 | 2017-08-08 15:23:47 -0400 | [diff] [blame] | 1689 | push_obj(L, get_ref<SkTypeface>(L, 1)->fontStyle()); |
reed | 36c9c11 | 2014-11-04 10:58:42 -0800 | [diff] [blame] | 1690 | return 1; |
| 1691 | } |
| 1692 | |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1693 | static int ltypeface_gc(lua_State* L) { |
commit-bot@chromium.org | 77887af | 2013-12-17 14:28:19 +0000 | [diff] [blame] | 1694 | SkSafeUnref(get_ref<SkTypeface>(L, 1)); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1695 | return 0; |
| 1696 | } |
| 1697 | |
| 1698 | static const struct luaL_Reg gSkTypeface_Methods[] = { |
reed | 36c9c11 | 2014-11-04 10:58:42 -0800 | [diff] [blame] | 1699 | { "getFamilyName", ltypeface_getFamilyName }, |
| 1700 | { "getStyle", ltypeface_getStyle }, |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1701 | { "__gc", ltypeface_gc }, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1702 | { nullptr, nullptr } |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1703 | }; |
| 1704 | |
| 1705 | /////////////////////////////////////////////////////////////////////////////// |
| 1706 | |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1707 | static int lfontstyle_weight(lua_State* L) { |
| 1708 | lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->weight()); |
| 1709 | return 1; |
| 1710 | } |
| 1711 | |
| 1712 | static int lfontstyle_width(lua_State* L) { |
| 1713 | lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->width()); |
| 1714 | return 1; |
| 1715 | } |
| 1716 | |
| 1717 | static int lfontstyle_slant(lua_State* L) { |
| 1718 | lua_pushnumber(L, get_ref<SkFontStyle>(L, 1)->slant()); |
| 1719 | return 1; |
| 1720 | } |
| 1721 | |
| 1722 | static int lfontstyle_gc(lua_State* L) { |
| 1723 | get_obj<SkFontStyle>(L, 1)->~SkFontStyle(); |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
| 1727 | static const struct luaL_Reg gSkFontStyle_Methods[] = { |
| 1728 | { "weight", lfontstyle_weight }, |
| 1729 | { "width", lfontstyle_width }, |
| 1730 | { "slant", lfontstyle_slant }, |
| 1731 | { "__gc", lfontstyle_gc }, |
| 1732 | { nullptr, nullptr } |
| 1733 | }; |
| 1734 | |
| 1735 | /////////////////////////////////////////////////////////////////////////////// |
| 1736 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1737 | class AutoCallLua { |
| 1738 | public: |
| 1739 | AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) { |
| 1740 | lua_getglobal(L, func); |
| 1741 | if (!lua_isfunction(L, -1)) { |
| 1742 | int t = lua_type(L, -1); |
| 1743 | SkDebugf("--- expected function %d\n", t); |
| 1744 | } |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 1745 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1746 | lua_newtable(L); |
| 1747 | setfield_string(L, "verb", verb); |
| 1748 | } |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 1749 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1750 | ~AutoCallLua() { |
| 1751 | if (lua_pcall(fL, 1, 0, 0) != LUA_OK) { |
| 1752 | SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); |
| 1753 | } |
| 1754 | lua_settop(fL, -1); |
| 1755 | } |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 1756 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1757 | private: |
| 1758 | lua_State* fL; |
| 1759 | }; |
| 1760 | |
| 1761 | #define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb) |
| 1762 | |
| 1763 | /////////////////////////////////////////////////////////////////////////////// |
| 1764 | |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1765 | static int lsk_newDocumentPDF(lua_State* L) { |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 1766 | const char* filename = nullptr; |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1767 | if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 1768 | filename = lua_tolstring(L, 1, nullptr); |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1769 | } |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 1770 | if (!filename) { |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1771 | return 0; |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1772 | } |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 1773 | auto file = std::make_unique<SkFILEWStream>(filename); |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 1774 | if (!file->isValid()) { |
| 1775 | return 0; |
| 1776 | } |
Hal Canary | 3026d4b | 2019-01-07 10:00:48 -0500 | [diff] [blame] | 1777 | auto doc = SkPDF::MakeDocument(file.get()); |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 1778 | if (!doc) { |
| 1779 | return 0; |
| 1780 | } |
| 1781 | push_ptr(L, new DocHolder{std::move(doc), std::move(file)}); |
| 1782 | return 1; |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1785 | static int lsk_newBlurImageFilter(lua_State* L) { |
| 1786 | SkScalar sigmaX = lua2scalar_def(L, 1, 0); |
| 1787 | SkScalar sigmaY = lua2scalar_def(L, 2, 0); |
Michael Ludwig | 06eacf4 | 2019-08-01 16:02:27 -0400 | [diff] [blame] | 1788 | sk_sp<SkImageFilter> imf(SkImageFilters::Blur(sigmaX, sigmaY, nullptr)); |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1789 | if (!imf) { |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1790 | lua_pushnil(L); |
| 1791 | } else { |
robertphillips | 6e7025a | 2016-04-04 04:31:25 -0700 | [diff] [blame] | 1792 | push_ref(L, std::move(imf)); |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 1793 | } |
| 1794 | return 1; |
| 1795 | } |
| 1796 | |
| 1797 | static int lsk_newLinearGradient(lua_State* L) { |
| 1798 | SkScalar x0 = lua2scalar_def(L, 1, 0); |
| 1799 | SkScalar y0 = lua2scalar_def(L, 2, 0); |
| 1800 | SkColor c0 = lua2color(L, 3); |
| 1801 | SkScalar x1 = lua2scalar_def(L, 4, 0); |
| 1802 | SkScalar y1 = lua2scalar_def(L, 5, 0); |
| 1803 | SkColor c1 = lua2color(L, 6); |
| 1804 | |
| 1805 | SkPoint pts[] = { { x0, y0 }, { x1, y1 } }; |
| 1806 | SkColor colors[] = { c0, c1 }; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 1807 | sk_sp<SkShader> s(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp)); |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 1808 | if (!s) { |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 1809 | lua_pushnil(L); |
| 1810 | } else { |
reed | 2ad1aa6 | 2016-03-09 09:50:50 -0800 | [diff] [blame] | 1811 | push_ref(L, std::move(s)); |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1812 | } |
| 1813 | return 1; |
| 1814 | } |
| 1815 | |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 1816 | static int lsk_newMatrix(lua_State* L) { |
| 1817 | push_new<SkMatrix>(L)->reset(); |
| 1818 | return 1; |
| 1819 | } |
| 1820 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1821 | static int lsk_newPaint(lua_State* L) { |
| 1822 | push_new<SkPaint>(L); |
| 1823 | return 1; |
| 1824 | } |
| 1825 | |
| 1826 | static int lsk_newPath(lua_State* L) { |
| 1827 | push_new<SkPath>(L); |
| 1828 | return 1; |
| 1829 | } |
| 1830 | |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1831 | static int lsk_newPictureRecorder(lua_State* L) { |
| 1832 | push_new<SkPictureRecorder>(L); |
| 1833 | return 1; |
| 1834 | } |
| 1835 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1836 | static int lsk_newRRect(lua_State* L) { |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 1837 | push_new<SkRRect>(L)->setEmpty(); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1838 | return 1; |
| 1839 | } |
| 1840 | |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1841 | // Sk.newTextBlob(text, rect, paint) |
| 1842 | static int lsk_newTextBlob(lua_State* L) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1843 | const char* text = lua_tolstring(L, 1, nullptr); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1844 | SkRect bounds; |
| 1845 | lua2rect(L, 2, &bounds); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1846 | |
Ben Wagner | b059194 | 2019-02-15 14:46:18 -0500 | [diff] [blame] | 1847 | std::unique_ptr<SkShaper> shaper = SkShaper::Make(); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1848 | |
Mike Reed | 5f528e5 | 2019-01-28 10:57:28 -0500 | [diff] [blame] | 1849 | // TODO: restore this logic based on SkFont instead of SkPaint |
| 1850 | #if 0 |
Mike Reed | e5f9cfa | 2019-01-10 13:55:35 -0500 | [diff] [blame] | 1851 | const SkPaint& paint = *get_obj<SkPaint>(L, 3); |
Hal Canary | 2a1848d | 2018-11-26 17:23:24 -0500 | [diff] [blame] | 1852 | SkFont font = SkFont::LEGACY_ExtractFromPaint(paint); |
Mike Reed | e5f9cfa | 2019-01-10 13:55:35 -0500 | [diff] [blame] | 1853 | #else |
| 1854 | SkFont font; |
| 1855 | #endif |
Ben Wagner | 3bdb69c | 2019-04-01 19:01:09 -0400 | [diff] [blame] | 1856 | SkTextBlobBuilderRunHandler builder(text, { bounds.left(), bounds.top() }); |
| 1857 | shaper->shape(text, strlen(text), font, true, bounds.width(), &builder); |
Herb Derby | 1724db1 | 2018-05-22 12:01:50 -0400 | [diff] [blame] | 1858 | |
Florin Malita | 9867f61 | 2018-12-12 10:54:49 -0500 | [diff] [blame] | 1859 | push_ref<SkTextBlob>(L, builder.makeBlob()); |
Ben Wagner | 3bdb69c | 2019-04-01 19:01:09 -0400 | [diff] [blame] | 1860 | SkLua(L).pushScalar(builder.endPoint().fY); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1861 | return 2; |
| 1862 | } |
| 1863 | |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1864 | static int lsk_newTypeface(lua_State* L) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1865 | const char* name = nullptr; |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1866 | SkFontStyle style; |
skia.committer@gmail.com | 6319367 | 2013-06-08 07:01:13 +0000 | [diff] [blame] | 1867 | |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1868 | int count = lua_gettop(L); |
| 1869 | if (count > 0 && lua_isstring(L, 1)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1870 | name = lua_tolstring(L, 1, nullptr); |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1871 | if (count > 1) { |
| 1872 | SkFontStyle* passedStyle = get_obj<SkFontStyle>(L, 2); |
| 1873 | if (passedStyle) { |
| 1874 | style = *passedStyle; |
| 1875 | } |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1879 | sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, style)); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1880 | // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1881 | if (nullptr == face) { |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 1882 | face = SkTypeface::MakeDefault(); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1883 | } |
bungeman | 13b9c95 | 2016-05-12 10:09:30 -0700 | [diff] [blame] | 1884 | push_ref(L, std::move(face)); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1885 | return 1; |
| 1886 | } |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1887 | |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1888 | static int lsk_newFontStyle(lua_State* L) { |
| 1889 | int count = lua_gettop(L); |
| 1890 | int weight = SkFontStyle::kNormal_Weight; |
| 1891 | int width = SkFontStyle::kNormal_Width; |
| 1892 | SkFontStyle::Slant slant = SkFontStyle::kUpright_Slant; |
| 1893 | if (count >= 1 && lua_isnumber(L, 1)) { |
| 1894 | weight = lua_tointegerx(L, 1, nullptr); |
| 1895 | } |
| 1896 | if (count >= 2 && lua_isnumber(L, 2)) { |
| 1897 | width = lua_tointegerx(L, 2, nullptr); |
| 1898 | } |
| 1899 | if (count >= 3 && lua_isnumber(L, 3)) { |
| 1900 | slant = static_cast<SkFontStyle::Slant>(lua_tointegerx(L, 3, nullptr)); |
| 1901 | } |
| 1902 | push_new<SkFontStyle>(L, weight, width, slant); |
| 1903 | return 1; |
| 1904 | } |
| 1905 | |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1906 | static int lsk_newRasterSurface(lua_State* L) { |
reed | 7b86466 | 2014-11-04 13:24:47 -0800 | [diff] [blame] | 1907 | int width = lua2int_def(L, 1, 0); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1908 | int height = lua2int_def(L, 2, 0); |
| 1909 | SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 1910 | SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1911 | auto surface = SkSurface::MakeRaster(info, &props); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1912 | if (nullptr == surface) { |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1913 | lua_pushnil(L); |
| 1914 | } else { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 1915 | push_ref(L, surface); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1916 | } |
| 1917 | return 1; |
| 1918 | } |
| 1919 | |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1920 | static int lsk_loadImage(lua_State* L) { |
| 1921 | if (lua_gettop(L) > 0 && lua_isstring(L, 1)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1922 | const char* name = lua_tolstring(L, 1, nullptr); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 1923 | sk_sp<SkData> data(SkData::MakeFromFileName(name)); |
| 1924 | if (data) { |
| 1925 | auto image = SkImage::MakeFromEncoded(std::move(data)); |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1926 | if (image) { |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 1927 | push_ref(L, std::move(image)); |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1928 | return 1; |
| 1929 | } |
| 1930 | } |
| 1931 | } |
| 1932 | return 0; |
| 1933 | } |
| 1934 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1935 | static void register_Sk(lua_State* L) { |
| 1936 | lua_newtable(L); |
| 1937 | lua_pushvalue(L, -1); |
| 1938 | lua_setglobal(L, "Sk"); |
| 1939 | // the Sk table is still on top |
| 1940 | |
mike@reedtribe.org | fb85824 | 2013-06-08 16:39:44 +0000 | [diff] [blame] | 1941 | setfield_function(L, "newDocumentPDF", lsk_newDocumentPDF); |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1942 | setfield_function(L, "loadImage", lsk_loadImage); |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1943 | setfield_function(L, "newBlurImageFilter", lsk_newBlurImageFilter); |
reed | 9fbc3f3 | 2014-10-21 07:12:58 -0700 | [diff] [blame] | 1944 | setfield_function(L, "newLinearGradient", lsk_newLinearGradient); |
reed | bdc49ae | 2014-10-14 09:34:52 -0700 | [diff] [blame] | 1945 | setfield_function(L, "newMatrix", lsk_newMatrix); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1946 | setfield_function(L, "newPaint", lsk_newPaint); |
| 1947 | setfield_function(L, "newPath", lsk_newPath); |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1948 | setfield_function(L, "newPictureRecorder", lsk_newPictureRecorder); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1949 | setfield_function(L, "newRRect", lsk_newRRect); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1950 | setfield_function(L, "newRasterSurface", lsk_newRasterSurface); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1951 | setfield_function(L, "newTextBlob", lsk_newTextBlob); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1952 | setfield_function(L, "newTypeface", lsk_newTypeface); |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1953 | setfield_function(L, "newFontStyle", lsk_newFontStyle); |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1954 | lua_pop(L, 1); // pop off the Sk table |
| 1955 | } |
| 1956 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1957 | #define REG_CLASS(L, C) \ |
| 1958 | do { \ |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1959 | luaL_newmetatable(L, get_mtname<C>()); \ |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1960 | lua_pushvalue(L, -1); \ |
| 1961 | lua_setfield(L, -2, "__index"); \ |
| 1962 | luaL_setfuncs(L, g##C##_Methods, 0); \ |
| 1963 | lua_pop(L, 1); /* pop off the meta-table */ \ |
| 1964 | } while (0) |
| 1965 | |
| 1966 | void SkLua::Load(lua_State* L) { |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 1967 | register_Sk(L); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1968 | REG_CLASS(L, SkCanvas); |
reed | 22a517f | 2015-12-04 20:45:59 -0800 | [diff] [blame] | 1969 | REG_CLASS(L, SkColorFilter); |
Mike Reed | 7ff6ca5 | 2018-01-08 14:45:31 -0500 | [diff] [blame] | 1970 | REG_CLASS(L, DocHolder); |
Mike Reed | 9191913 | 2019-01-02 12:21:01 -0500 | [diff] [blame] | 1971 | REG_CLASS(L, SkFont); |
mike@reedtribe.org | 792bbd1 | 2013-06-11 02:20:28 +0000 | [diff] [blame] | 1972 | REG_CLASS(L, SkImage); |
reed | 468b181 | 2014-10-19 11:42:54 -0700 | [diff] [blame] | 1973 | REG_CLASS(L, SkImageFilter); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1974 | REG_CLASS(L, SkMatrix); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1975 | REG_CLASS(L, SkPaint); |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 1976 | REG_CLASS(L, SkPath); |
| 1977 | REG_CLASS(L, SkPathEffect); |
reed | 96affcd | 2014-10-13 12:38:04 -0700 | [diff] [blame] | 1978 | REG_CLASS(L, SkPicture); |
| 1979 | REG_CLASS(L, SkPictureRecorder); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1980 | REG_CLASS(L, SkRRect); |
reed@google.com | 5fdc983 | 2013-07-24 15:47:52 +0000 | [diff] [blame] | 1981 | REG_CLASS(L, SkShader); |
reed | 485557f | 2014-10-12 10:36:47 -0700 | [diff] [blame] | 1982 | REG_CLASS(L, SkSurface); |
reed | 1b6ab44 | 2014-11-03 19:55:41 -0800 | [diff] [blame] | 1983 | REG_CLASS(L, SkTextBlob); |
mike@reedtribe.org | e6469f1 | 2013-06-08 03:15:47 +0000 | [diff] [blame] | 1984 | REG_CLASS(L, SkTypeface); |
Ben Wagner | c6c10b4 | 2017-08-07 09:56:21 -0400 | [diff] [blame] | 1985 | REG_CLASS(L, SkFontStyle); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1986 | } |
zachr@google.com | 28c27c8 | 2013-06-20 17:15:05 +0000 | [diff] [blame] | 1987 | |
reed@google.com | 7bce998 | 2013-06-20 17:40:21 +0000 | [diff] [blame] | 1988 | extern "C" int luaopen_skia(lua_State* L); |
zachr@google.com | 28c27c8 | 2013-06-20 17:15:05 +0000 | [diff] [blame] | 1989 | extern "C" int luaopen_skia(lua_State* L) { |
| 1990 | SkLua::Load(L); |
| 1991 | return 0; |
| 1992 | } |