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