reed@google.com | dff7e11 | 2013-05-15 19:34:20 +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 | |
| 8 | #include "SkLuaCanvas.h" |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 9 | #include "SkRRect.h" |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 10 | |
| 11 | extern "C" { |
| 12 | #include "lua.h" |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 13 | #include "lauxlib.h" |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 14 | } |
| 15 | |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 16 | static void setfield_string(lua_State* L, const char key[], const char value[]) { |
| 17 | lua_pushstring(L, value); |
| 18 | lua_setfield(L, -2, key); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 19 | } |
| 20 | |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 21 | static void setfield_number(lua_State* L, const char key[], double value) { |
| 22 | lua_pushnumber(L, value); |
| 23 | lua_setfield(L, -2, key); |
| 24 | } |
| 25 | |
| 26 | static void setfield_bool(lua_State* L, const char key[], bool value) { |
| 27 | lua_pushboolean(L, value); |
| 28 | lua_setfield(L, -2, key); |
| 29 | } |
| 30 | |
reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 31 | // sets [1]...[count] in the table on the top of the stack |
| 32 | static void setfield_arrayf(lua_State* L, const SkScalar array[], int count) { |
| 33 | for (int i = 0; i < count; ++i) { |
| 34 | lua_pushnumber(L, SkScalarToDouble(i + 1)); // key |
| 35 | lua_pushnumber(L, SkScalarToDouble(array[i])); // value |
| 36 | lua_settable(L, -3); |
| 37 | } |
| 38 | } |
| 39 | |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 40 | static void push_rect(lua_State* L, const SkRect& r) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 41 | lua_newtable(L); |
| 42 | setfield_number(L, "left", r.fLeft); |
| 43 | setfield_number(L, "top", r.fTop); |
| 44 | setfield_number(L, "right", r.fRight); |
| 45 | setfield_number(L, "bottom", r.fBottom); |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 46 | } |
| 47 | |
| 48 | static void setfield_rect(lua_State* L, const char key[], const SkRect& r) { |
| 49 | push_rect(L, r); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 50 | lua_setfield(L, -2, key); |
| 51 | } |
| 52 | |
reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 53 | static const char* rrect_type(const SkRRect& rr) { |
| 54 | switch (rr.getType()) { |
| 55 | case SkRRect::kUnknown_Type: return "unknown"; |
| 56 | case SkRRect::kEmpty_Type: return "empty"; |
| 57 | case SkRRect::kRect_Type: return "rect"; |
| 58 | case SkRRect::kOval_Type: return "oval"; |
| 59 | case SkRRect::kSimple_Type: return "simple"; |
| 60 | case SkRRect::kComplex_Type: return "complex"; |
| 61 | } |
| 62 | SkASSERT(!"never get here"); |
| 63 | return ""; |
| 64 | } |
| 65 | |
| 66 | static void setfield_rrect(lua_State* L, const char key[], const SkRRect& rr) { |
| 67 | lua_newtable(L); |
| 68 | setfield_rect(L, "rect", rr.getBounds()); |
| 69 | setfield_string(L, "type", rrect_type(rr)); |
| 70 | |
| 71 | SkVector rad[4] = { |
| 72 | rr.radii(SkRRect::kUpperLeft_Corner), |
| 73 | rr.radii(SkRRect::kUpperRight_Corner), |
| 74 | rr.radii(SkRRect::kLowerRight_Corner), |
| 75 | rr.radii(SkRRect::kLowerLeft_Corner), |
| 76 | }; |
| 77 | setfield_arrayf(L, &rad[0].fX, 8); |
| 78 | lua_setfield(L, -2, key); |
| 79 | } |
| 80 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 81 | static void push_matrix(lua_State* L, const SkMatrix& mat) { |
| 82 | SkScalar m[9]; |
| 83 | for (int i = 0; i < 9; ++i) { |
| 84 | m[i] = mat[i]; |
| 85 | } |
| 86 | lua_newtable(L); |
| 87 | setfield_arrayf(L, m, 9); |
| 88 | } |
| 89 | |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 90 | enum PaintUsage { |
| 91 | kText_PaintUsage, |
| 92 | kImage_PaintUsage, |
| 93 | kGeometry_PaintUsage |
| 94 | }; |
| 95 | |
| 96 | static const char* color2string(SkColor c, SkString* str) { |
| 97 | str->printf("0x%08X", c); |
| 98 | return str->c_str(); |
| 99 | } |
| 100 | |
| 101 | static void setfield_paint(lua_State* L, const SkPaint& p, |
| 102 | PaintUsage pu = kGeometry_PaintUsage) { |
| 103 | SkString str; |
| 104 | |
| 105 | lua_newtable(L); |
| 106 | setfield_bool(L, "aa", p.isAntiAlias()); |
| 107 | setfield_string(L, "color", color2string(p.getColor(), &str)); |
| 108 | |
| 109 | if (kGeometry_PaintUsage == pu) { |
| 110 | if (SkPaint::kFill_Style != p.getStyle()) { |
| 111 | setfield_number(L, "stroke-width", p.getStrokeWidth()); |
| 112 | } |
| 113 | } |
| 114 | lua_setfield(L, -2, "paint"); |
| 115 | } |
| 116 | |
| 117 | class AutoCallLua { |
| 118 | public: |
| 119 | AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) { |
| 120 | lua_getglobal(L, func); |
| 121 | if (!lua_isfunction(L, -1)) { |
| 122 | int t = lua_type(L, -1); |
| 123 | SkDebugf("--- expected function %d\n", t); |
| 124 | } |
skia.committer@gmail.com | 539f364 | 2013-05-16 07:01:00 +0000 | [diff] [blame] | 125 | |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 126 | lua_newtable(L); |
| 127 | setfield_string(L, "verb", verb); |
| 128 | } |
| 129 | |
| 130 | ~AutoCallLua() { |
| 131 | if (lua_pcall(fL, 1, 0, 0) != LUA_OK) { |
| 132 | SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); |
| 133 | } |
| 134 | lua_settop(fL, -1); |
| 135 | } |
| 136 | |
| 137 | private: |
| 138 | lua_State* fL; |
| 139 | }; |
| 140 | |
| 141 | #define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb) |
| 142 | |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 143 | /////////////////////////////////////////////////////////////////////////////// |
| 144 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 145 | static const char gCanvasMetaTableName[] = "SkCanvas_MetaTable"; |
| 146 | |
| 147 | static int lcanvas_getSaveCount(lua_State* L) { |
| 148 | SkCanvas* c = *(SkCanvas**)luaL_checkudata(L, 1, gCanvasMetaTableName); |
| 149 | lua_pushnumber(L, (double)c->getSaveCount()); |
| 150 | return 1; |
| 151 | } |
| 152 | |
| 153 | static int lcanvas_getTotalMatrix(lua_State* L) { |
| 154 | SkCanvas* c = *(SkCanvas**)luaL_checkudata(L, 1, gCanvasMetaTableName); |
| 155 | push_matrix(L, c->getTotalMatrix()); |
| 156 | return 1; |
| 157 | } |
| 158 | |
| 159 | static int lcanvas_gc(lua_State* L) { |
| 160 | SkCanvas** cptr = (SkCanvas**)luaL_checkudata(L, 1, gCanvasMetaTableName); |
| 161 | SkSafeUnref(*cptr); |
| 162 | *cptr = NULL; |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static const struct luaL_Reg gLuaCanvasMethods[] = { |
| 167 | { "getSaveCount", lcanvas_getSaveCount }, |
| 168 | { "getTotalMatrix", lcanvas_getTotalMatrix }, |
| 169 | { "__gc", lcanvas_gc }, |
| 170 | { NULL, NULL } |
| 171 | }; |
| 172 | |
| 173 | static void ensure_canvas_metatable(lua_State* L) { |
| 174 | static bool gOnce; |
| 175 | if (gOnce) { |
| 176 | return; |
| 177 | } |
| 178 | gOnce = true; |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 179 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 180 | luaL_newmetatable(L, gCanvasMetaTableName); |
| 181 | lua_pushvalue(L, -1); |
| 182 | lua_setfield(L, -2, "__index"); |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 183 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 184 | luaL_setfuncs(L, gLuaCanvasMethods, 0); |
| 185 | lua_settop(L, -2); // pop off the meta-table |
| 186 | } |
| 187 | |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 188 | /////////////////////////////////////////////////////////////////////////////// |
| 189 | |
| 190 | static const char gPathMetaTableName[] = "SkPath_MetaTable"; |
| 191 | |
| 192 | static int lpath_getBounds(lua_State* L) { |
| 193 | SkPath* p = (SkPath*)luaL_checkudata(L, 1, gPathMetaTableName); |
| 194 | push_rect(L, p->getBounds()); |
| 195 | return 1; |
| 196 | } |
| 197 | |
| 198 | static int lpath_isEmpty(lua_State* L) { |
| 199 | SkPath* p = (SkPath*)luaL_checkudata(L, 1, gPathMetaTableName); |
| 200 | lua_pushboolean(L, p->isEmpty()); |
| 201 | return 1; |
| 202 | } |
| 203 | |
| 204 | static int lpath_isRect(lua_State* L) { |
| 205 | SkPath* p = (SkPath*)luaL_checkudata(L, 1, gPathMetaTableName); |
| 206 | SkRect r; |
| 207 | bool pred = p->isRect(&r); |
| 208 | int ret_count = 1; |
| 209 | lua_pushboolean(L, pred); |
| 210 | if (pred) { |
| 211 | push_rect(L, r); |
| 212 | ret_count += 1; |
| 213 | } |
| 214 | return ret_count; |
| 215 | } |
| 216 | |
| 217 | static const char* dir2string(SkPath::Direction dir) { |
| 218 | static const char* gStr[] = { |
| 219 | "unknown", "cw", "ccw" |
| 220 | }; |
| 221 | SkASSERT((unsigned)dir < SK_ARRAY_COUNT(gStr)); |
| 222 | return gStr[dir]; |
| 223 | } |
| 224 | |
| 225 | static int lpath_isNestedRects(lua_State* L) { |
| 226 | SkPath* p = (SkPath*)luaL_checkudata(L, 1, gPathMetaTableName); |
| 227 | SkRect rects[2]; |
| 228 | SkPath::Direction dirs[2]; |
| 229 | bool pred = p->isNestedRects(rects, dirs); |
| 230 | int ret_count = 1; |
| 231 | lua_pushboolean(L, pred); |
| 232 | if (pred) { |
| 233 | push_rect(L, rects[0]); |
| 234 | push_rect(L, rects[1]); |
| 235 | lua_pushstring(L, dir2string(dirs[0])); |
| 236 | lua_pushstring(L, dir2string(dirs[0])); |
| 237 | ret_count += 4; |
| 238 | } |
| 239 | return ret_count; |
| 240 | return 1; |
| 241 | } |
| 242 | |
| 243 | static int lpath_gc(lua_State* L) { |
| 244 | SkPath* p = (SkPath*)luaL_checkudata(L, 1, gPathMetaTableName); |
| 245 | p->~SkPath(); |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static const struct luaL_Reg gLuaPathMethods[] = { |
| 250 | { "getBounds", lpath_getBounds }, |
| 251 | { "isEmpty", lpath_isEmpty }, |
| 252 | { "isRect", lpath_isRect }, |
| 253 | { "isNestedRects", lpath_isNestedRects }, |
| 254 | { "__gc", lpath_gc }, |
| 255 | { NULL, NULL } |
| 256 | }; |
| 257 | |
| 258 | static void ensure_path_metatable(lua_State* L) { |
| 259 | static bool gOnce; |
| 260 | if (gOnce) { |
| 261 | return; |
| 262 | } |
| 263 | gOnce = true; |
| 264 | |
| 265 | luaL_newmetatable(L, gPathMetaTableName); |
| 266 | lua_pushvalue(L, -1); |
| 267 | lua_setfield(L, -2, "__index"); |
| 268 | |
| 269 | luaL_setfuncs(L, gLuaPathMethods, 0); |
| 270 | lua_settop(L, -2); // pop off the meta-table |
| 271 | } |
| 272 | |
| 273 | static void push_path(lua_State* L, const SkPath& src) { |
| 274 | ensure_path_metatable(L); |
| 275 | |
| 276 | SkPath* path = (SkPath*)lua_newuserdata(L, sizeof(SkPath)); |
| 277 | new (path) SkPath(src); |
| 278 | |
| 279 | luaL_getmetatable(L, gPathMetaTableName); |
| 280 | lua_setmetatable(L, -2); |
| 281 | } |
| 282 | |
| 283 | static void setfield_path(lua_State* L, const char key[], const SkPath& path) { |
| 284 | push_path(L, path); |
| 285 | lua_setfield(L, -2, key); |
| 286 | } |
| 287 | |
| 288 | /////////////////////////////////////////////////////////////////////////////// |
| 289 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 290 | void SkLuaCanvas::pushThis() { |
| 291 | ensure_canvas_metatable(fL); |
| 292 | |
| 293 | SkCanvas** canvasPtr = (SkCanvas**)lua_newuserdata(fL, sizeof(SkCanvas*)); |
| 294 | luaL_getmetatable(fL, gCanvasMetaTableName); |
| 295 | lua_setmetatable(fL, -2); |
| 296 | |
| 297 | this->ref(); |
| 298 | *canvasPtr = this; |
| 299 | } |
| 300 | |
| 301 | /////////////////////////////////////////////////////////////////////////////// |
| 302 | |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 303 | static SkBitmap make_bm(int width, int height) { |
| 304 | SkBitmap bm; |
| 305 | bm.setConfig(SkBitmap::kNo_Config, width, height); |
| 306 | return bm; |
| 307 | } |
| 308 | |
| 309 | SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[]) |
| 310 | : INHERITED(make_bm(width, height)) |
| 311 | , fL(L) |
| 312 | , fFunc(func) { |
| 313 | } |
| 314 | |
| 315 | SkLuaCanvas::~SkLuaCanvas() {} |
| 316 | |
| 317 | int SkLuaCanvas::save(SaveFlags flags) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 318 | AUTO_LUA("save"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 319 | return this->INHERITED::save(flags); |
| 320 | } |
| 321 | |
| 322 | int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 323 | SaveFlags flags) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 324 | AUTO_LUA("saveLayer"); |
| 325 | if (bounds) { |
| 326 | setfield_rect(fL, "bounds", *bounds); |
| 327 | } |
| 328 | if (paint) { |
| 329 | setfield_paint(fL, *paint); |
| 330 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 331 | return this->INHERITED::save(flags); |
| 332 | } |
| 333 | |
| 334 | void SkLuaCanvas::restore() { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 335 | AUTO_LUA("restore"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 336 | this->INHERITED::restore(); |
| 337 | } |
| 338 | |
| 339 | bool SkLuaCanvas::translate(SkScalar dx, SkScalar dy) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 340 | AUTO_LUA("translate"); |
| 341 | setfield_number(fL, "dx", dx); |
| 342 | setfield_number(fL, "dy", dy); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 343 | return this->INHERITED::translate(dx, dy); |
| 344 | } |
| 345 | |
| 346 | bool SkLuaCanvas::scale(SkScalar sx, SkScalar sy) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 347 | AUTO_LUA("scale"); |
| 348 | setfield_number(fL, "sx", sx); |
| 349 | setfield_number(fL, "sy", sy); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 350 | return this->INHERITED::scale(sx, sy); |
| 351 | } |
| 352 | |
| 353 | bool SkLuaCanvas::rotate(SkScalar degrees) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 354 | AUTO_LUA("rotate"); |
| 355 | setfield_number(fL, "degrees", degrees); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 356 | return this->INHERITED::rotate(degrees); |
| 357 | } |
| 358 | |
| 359 | bool SkLuaCanvas::skew(SkScalar sx, SkScalar sy) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 360 | AUTO_LUA("skew"); |
| 361 | setfield_number(fL, "sx", sx); |
| 362 | setfield_number(fL, "sy", sy); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 363 | return this->INHERITED::skew(sx, sy); |
| 364 | } |
| 365 | |
| 366 | bool SkLuaCanvas::concat(const SkMatrix& matrix) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 367 | AUTO_LUA("concat"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 368 | return this->INHERITED::concat(matrix); |
| 369 | } |
| 370 | |
| 371 | void SkLuaCanvas::setMatrix(const SkMatrix& matrix) { |
| 372 | this->INHERITED::setMatrix(matrix); |
| 373 | } |
| 374 | |
| 375 | bool SkLuaCanvas::clipRect(const SkRect& r, SkRegion::Op op, bool doAA) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 376 | AUTO_LUA("clipRect"); |
| 377 | setfield_rect(fL, "rect", r); |
| 378 | setfield_bool(fL, "aa", doAA); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 379 | return this->INHERITED::clipRect(r, op, doAA); |
| 380 | } |
| 381 | |
| 382 | bool SkLuaCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 383 | AUTO_LUA("clipRRect"); |
reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 384 | setfield_rrect(fL, "rrect", rrect); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 385 | setfield_bool(fL, "aa", doAA); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 386 | return this->INHERITED::clipRRect(rrect, op, doAA); |
| 387 | } |
| 388 | |
| 389 | bool SkLuaCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 390 | AUTO_LUA("clipPath"); |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 391 | setfield_path(fL, "path", path); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 392 | setfield_bool(fL, "aa", doAA); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 393 | return this->INHERITED::clipPath(path, op, doAA); |
| 394 | } |
| 395 | |
| 396 | bool SkLuaCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 397 | AUTO_LUA("clipRegion"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 398 | return this->INHERITED::clipRegion(deviceRgn, op); |
| 399 | } |
| 400 | |
| 401 | void SkLuaCanvas::drawPaint(const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 402 | AUTO_LUA("drawPaint"); |
| 403 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void SkLuaCanvas::drawPoints(PointMode mode, size_t count, |
| 407 | const SkPoint pts[], const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 408 | AUTO_LUA("drawPoints"); |
| 409 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | void SkLuaCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 413 | AUTO_LUA("drawOval"); |
reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 414 | setfield_rect(fL, "oval", rect); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 415 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | void SkLuaCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 419 | AUTO_LUA("drawRect"); |
| 420 | setfield_rect(fL, "rect", rect); |
| 421 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void SkLuaCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 425 | AUTO_LUA("drawRRect"); |
reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 426 | setfield_rrect(fL, "rrect", rrect); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 427 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void SkLuaCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 431 | AUTO_LUA("drawPath"); |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 432 | setfield_path(fL, "path", path); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 433 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | void SkLuaCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 437 | const SkPaint* paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 438 | AUTO_LUA("drawBitmap"); |
| 439 | if (paint) { |
| 440 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 441 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | void SkLuaCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
| 445 | const SkRect& dst, const SkPaint* paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 446 | AUTO_LUA("drawBitmapRectToRect"); |
| 447 | if (paint) { |
| 448 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 449 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | void SkLuaCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
| 453 | const SkPaint* paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 454 | AUTO_LUA("drawBitmapMatrix"); |
| 455 | if (paint) { |
| 456 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 457 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void SkLuaCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
| 461 | const SkPaint* paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 462 | AUTO_LUA("drawSprite"); |
| 463 | if (paint) { |
| 464 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 465 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void SkLuaCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 469 | SkScalar y, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 470 | AUTO_LUA("drawText"); |
| 471 | setfield_paint(fL, paint, kText_PaintUsage); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void SkLuaCanvas::drawPosText(const void* text, size_t byteLength, |
| 475 | const SkPoint pos[], const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 476 | AUTO_LUA("drawPosText"); |
| 477 | setfield_paint(fL, paint, kText_PaintUsage); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void SkLuaCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 481 | const SkScalar xpos[], SkScalar constY, |
| 482 | const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 483 | AUTO_LUA("drawPosTextH"); |
| 484 | setfield_paint(fL, paint, kText_PaintUsage); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | void SkLuaCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 488 | const SkPath& path, const SkMatrix* matrix, |
| 489 | const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 490 | AUTO_LUA("drawTextOnPath"); |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame^] | 491 | setfield_path(fL, "path", path); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 492 | setfield_paint(fL, paint, kText_PaintUsage); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void SkLuaCanvas::drawPicture(SkPicture& picture) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 496 | AUTO_LUA("drawPicture"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 497 | // call through so we can see the nested picture ops |
| 498 | this->INHERITED::drawPicture(picture); |
| 499 | } |
| 500 | |
| 501 | void SkLuaCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 502 | const SkPoint vertices[], const SkPoint texs[], |
| 503 | const SkColor colors[], SkXfermode* xmode, |
| 504 | const uint16_t indices[], int indexCount, |
| 505 | const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 506 | AUTO_LUA("drawVertices"); |
| 507 | setfield_paint(fL, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void SkLuaCanvas::drawData(const void* data, size_t length) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 511 | AUTO_LUA("drawData"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 512 | } |