| 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 | |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 40 | static void setfield_rect(lua_State* L, const char key[], 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 | lua_setfield(L, -2, key); |
| 47 | } |
| 48 | |
| reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 49 | static const char* rrect_type(const SkRRect& rr) { |
| 50 | switch (rr.getType()) { |
| 51 | case SkRRect::kUnknown_Type: return "unknown"; |
| 52 | case SkRRect::kEmpty_Type: return "empty"; |
| 53 | case SkRRect::kRect_Type: return "rect"; |
| 54 | case SkRRect::kOval_Type: return "oval"; |
| 55 | case SkRRect::kSimple_Type: return "simple"; |
| 56 | case SkRRect::kComplex_Type: return "complex"; |
| 57 | } |
| 58 | SkASSERT(!"never get here"); |
| 59 | return ""; |
| 60 | } |
| 61 | |
| 62 | static void setfield_rrect(lua_State* L, const char key[], const SkRRect& rr) { |
| 63 | lua_newtable(L); |
| 64 | setfield_rect(L, "rect", rr.getBounds()); |
| 65 | setfield_string(L, "type", rrect_type(rr)); |
| 66 | |
| 67 | SkVector rad[4] = { |
| 68 | rr.radii(SkRRect::kUpperLeft_Corner), |
| 69 | rr.radii(SkRRect::kUpperRight_Corner), |
| 70 | rr.radii(SkRRect::kLowerRight_Corner), |
| 71 | rr.radii(SkRRect::kLowerLeft_Corner), |
| 72 | }; |
| 73 | setfield_arrayf(L, &rad[0].fX, 8); |
| 74 | lua_setfield(L, -2, key); |
| 75 | } |
| 76 | |
| mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame^] | 77 | static void push_matrix(lua_State* L, const SkMatrix& mat) { |
| 78 | SkScalar m[9]; |
| 79 | for (int i = 0; i < 9; ++i) { |
| 80 | m[i] = mat[i]; |
| 81 | } |
| 82 | lua_newtable(L); |
| 83 | setfield_arrayf(L, m, 9); |
| 84 | } |
| 85 | |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 86 | enum PaintUsage { |
| 87 | kText_PaintUsage, |
| 88 | kImage_PaintUsage, |
| 89 | kGeometry_PaintUsage |
| 90 | }; |
| 91 | |
| 92 | static const char* color2string(SkColor c, SkString* str) { |
| 93 | str->printf("0x%08X", c); |
| 94 | return str->c_str(); |
| 95 | } |
| 96 | |
| 97 | static void setfield_paint(lua_State* L, const SkPaint& p, |
| 98 | PaintUsage pu = kGeometry_PaintUsage) { |
| 99 | SkString str; |
| 100 | |
| 101 | lua_newtable(L); |
| 102 | setfield_bool(L, "aa", p.isAntiAlias()); |
| 103 | setfield_string(L, "color", color2string(p.getColor(), &str)); |
| 104 | |
| 105 | if (kGeometry_PaintUsage == pu) { |
| 106 | if (SkPaint::kFill_Style != p.getStyle()) { |
| 107 | setfield_number(L, "stroke-width", p.getStrokeWidth()); |
| 108 | } |
| 109 | } |
| 110 | lua_setfield(L, -2, "paint"); |
| 111 | } |
| 112 | |
| 113 | class AutoCallLua { |
| 114 | public: |
| 115 | AutoCallLua(lua_State* L, const char func[], const char verb[]) : fL(L) { |
| 116 | lua_getglobal(L, func); |
| 117 | if (!lua_isfunction(L, -1)) { |
| 118 | int t = lua_type(L, -1); |
| 119 | SkDebugf("--- expected function %d\n", t); |
| 120 | } |
| skia.committer@gmail.com | 539f364 | 2013-05-16 07:01:00 +0000 | [diff] [blame] | 121 | |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 122 | lua_newtable(L); |
| 123 | setfield_string(L, "verb", verb); |
| 124 | } |
| 125 | |
| 126 | ~AutoCallLua() { |
| 127 | if (lua_pcall(fL, 1, 0, 0) != LUA_OK) { |
| 128 | SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); |
| 129 | } |
| 130 | lua_settop(fL, -1); |
| 131 | } |
| 132 | |
| 133 | private: |
| 134 | lua_State* fL; |
| 135 | }; |
| 136 | |
| 137 | #define AUTO_LUA(verb) AutoCallLua acl(fL, fFunc.c_str(), verb) |
| 138 | |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 139 | /////////////////////////////////////////////////////////////////////////////// |
| 140 | |
| mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame^] | 141 | static const char gCanvasMetaTableName[] = "SkCanvas_MetaTable"; |
| 142 | |
| 143 | static int lcanvas_getSaveCount(lua_State* L) { |
| 144 | SkCanvas* c = *(SkCanvas**)luaL_checkudata(L, 1, gCanvasMetaTableName); |
| 145 | lua_pushnumber(L, (double)c->getSaveCount()); |
| 146 | return 1; |
| 147 | } |
| 148 | |
| 149 | static int lcanvas_getTotalMatrix(lua_State* L) { |
| 150 | SkCanvas* c = *(SkCanvas**)luaL_checkudata(L, 1, gCanvasMetaTableName); |
| 151 | push_matrix(L, c->getTotalMatrix()); |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | static int lcanvas_gc(lua_State* L) { |
| 156 | SkCanvas** cptr = (SkCanvas**)luaL_checkudata(L, 1, gCanvasMetaTableName); |
| 157 | SkSafeUnref(*cptr); |
| 158 | *cptr = NULL; |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static const struct luaL_Reg gLuaCanvasMethods[] = { |
| 163 | { "getSaveCount", lcanvas_getSaveCount }, |
| 164 | { "getTotalMatrix", lcanvas_getTotalMatrix }, |
| 165 | { "__gc", lcanvas_gc }, |
| 166 | { NULL, NULL } |
| 167 | }; |
| 168 | |
| 169 | static void ensure_canvas_metatable(lua_State* L) { |
| 170 | static bool gOnce; |
| 171 | if (gOnce) { |
| 172 | return; |
| 173 | } |
| 174 | gOnce = true; |
| 175 | |
| 176 | luaL_newmetatable(L, gCanvasMetaTableName); |
| 177 | lua_pushvalue(L, -1); |
| 178 | lua_setfield(L, -2, "__index"); |
| 179 | |
| 180 | luaL_setfuncs(L, gLuaCanvasMethods, 0); |
| 181 | lua_settop(L, -2); // pop off the meta-table |
| 182 | } |
| 183 | |
| 184 | void SkLuaCanvas::pushThis() { |
| 185 | ensure_canvas_metatable(fL); |
| 186 | |
| 187 | SkCanvas** canvasPtr = (SkCanvas**)lua_newuserdata(fL, sizeof(SkCanvas*)); |
| 188 | luaL_getmetatable(fL, gCanvasMetaTableName); |
| 189 | lua_setmetatable(fL, -2); |
| 190 | |
| 191 | this->ref(); |
| 192 | *canvasPtr = this; |
| 193 | } |
| 194 | |
| 195 | /////////////////////////////////////////////////////////////////////////////// |
| 196 | |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 197 | static SkBitmap make_bm(int width, int height) { |
| 198 | SkBitmap bm; |
| 199 | bm.setConfig(SkBitmap::kNo_Config, width, height); |
| 200 | return bm; |
| 201 | } |
| 202 | |
| 203 | SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[]) |
| 204 | : INHERITED(make_bm(width, height)) |
| 205 | , fL(L) |
| 206 | , fFunc(func) { |
| 207 | } |
| 208 | |
| 209 | SkLuaCanvas::~SkLuaCanvas() {} |
| 210 | |
| 211 | int SkLuaCanvas::save(SaveFlags flags) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 212 | AUTO_LUA("save"); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 213 | return this->INHERITED::save(flags); |
| 214 | } |
| 215 | |
| 216 | int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 217 | SaveFlags flags) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 218 | AUTO_LUA("saveLayer"); |
| 219 | if (bounds) { |
| 220 | setfield_rect(fL, "bounds", *bounds); |
| 221 | } |
| 222 | if (paint) { |
| 223 | setfield_paint(fL, *paint); |
| 224 | } |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 225 | return this->INHERITED::save(flags); |
| 226 | } |
| 227 | |
| 228 | void SkLuaCanvas::restore() { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 229 | AUTO_LUA("restore"); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 230 | this->INHERITED::restore(); |
| 231 | } |
| 232 | |
| 233 | bool SkLuaCanvas::translate(SkScalar dx, SkScalar dy) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 234 | AUTO_LUA("translate"); |
| 235 | setfield_number(fL, "dx", dx); |
| 236 | setfield_number(fL, "dy", dy); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 237 | return this->INHERITED::translate(dx, dy); |
| 238 | } |
| 239 | |
| 240 | bool SkLuaCanvas::scale(SkScalar sx, SkScalar sy) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 241 | AUTO_LUA("scale"); |
| 242 | setfield_number(fL, "sx", sx); |
| 243 | setfield_number(fL, "sy", sy); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 244 | return this->INHERITED::scale(sx, sy); |
| 245 | } |
| 246 | |
| 247 | bool SkLuaCanvas::rotate(SkScalar degrees) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 248 | AUTO_LUA("rotate"); |
| 249 | setfield_number(fL, "degrees", degrees); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 250 | return this->INHERITED::rotate(degrees); |
| 251 | } |
| 252 | |
| 253 | bool SkLuaCanvas::skew(SkScalar sx, SkScalar sy) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 254 | AUTO_LUA("skew"); |
| 255 | setfield_number(fL, "sx", sx); |
| 256 | setfield_number(fL, "sy", sy); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 257 | return this->INHERITED::skew(sx, sy); |
| 258 | } |
| 259 | |
| 260 | bool SkLuaCanvas::concat(const SkMatrix& matrix) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 261 | AUTO_LUA("concat"); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 262 | return this->INHERITED::concat(matrix); |
| 263 | } |
| 264 | |
| 265 | void SkLuaCanvas::setMatrix(const SkMatrix& matrix) { |
| 266 | this->INHERITED::setMatrix(matrix); |
| 267 | } |
| 268 | |
| 269 | bool SkLuaCanvas::clipRect(const SkRect& r, SkRegion::Op op, bool doAA) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 270 | AUTO_LUA("clipRect"); |
| 271 | setfield_rect(fL, "rect", r); |
| 272 | setfield_bool(fL, "aa", doAA); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 273 | return this->INHERITED::clipRect(r, op, doAA); |
| 274 | } |
| 275 | |
| 276 | bool SkLuaCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 277 | AUTO_LUA("clipRRect"); |
| reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 278 | setfield_rrect(fL, "rrect", rrect); |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 279 | setfield_bool(fL, "aa", doAA); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 280 | return this->INHERITED::clipRRect(rrect, op, doAA); |
| 281 | } |
| 282 | |
| 283 | bool SkLuaCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 284 | AUTO_LUA("clipPath"); |
| 285 | setfield_bool(fL, "aa", doAA); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 286 | return this->INHERITED::clipPath(path, op, doAA); |
| 287 | } |
| 288 | |
| 289 | bool SkLuaCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 290 | AUTO_LUA("clipRegion"); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 291 | return this->INHERITED::clipRegion(deviceRgn, op); |
| 292 | } |
| 293 | |
| 294 | void SkLuaCanvas::drawPaint(const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 295 | AUTO_LUA("drawPaint"); |
| 296 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | void SkLuaCanvas::drawPoints(PointMode mode, size_t count, |
| 300 | const SkPoint pts[], const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 301 | AUTO_LUA("drawPoints"); |
| 302 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void SkLuaCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 306 | AUTO_LUA("drawOval"); |
| reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 307 | setfield_rect(fL, "oval", rect); |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 308 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void SkLuaCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 312 | AUTO_LUA("drawRect"); |
| 313 | setfield_rect(fL, "rect", rect); |
| 314 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void SkLuaCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 318 | AUTO_LUA("drawRRect"); |
| reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 319 | setfield_rrect(fL, "rrect", rrect); |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 320 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void SkLuaCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 324 | AUTO_LUA("drawPath"); |
| 325 | setfield_rect(fL, "bounds", path.getBounds()); |
| reed@google.com | 57de5cf | 2013-05-16 13:51:07 +0000 | [diff] [blame] | 326 | setfield_bool(fL, "isRect", path.isRect(NULL)); |
| 327 | setfield_bool(fL, "isOval", path.isOval(NULL)); |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 328 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | void SkLuaCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 332 | const SkPaint* paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 333 | AUTO_LUA("drawBitmap"); |
| 334 | if (paint) { |
| 335 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 336 | } |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void SkLuaCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
| 340 | const SkRect& dst, const SkPaint* paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 341 | AUTO_LUA("drawBitmapRectToRect"); |
| 342 | if (paint) { |
| 343 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 344 | } |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void SkLuaCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
| 348 | const SkPaint* paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 349 | AUTO_LUA("drawBitmapMatrix"); |
| 350 | if (paint) { |
| 351 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 352 | } |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void SkLuaCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
| 356 | const SkPaint* paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 357 | AUTO_LUA("drawSprite"); |
| 358 | if (paint) { |
| 359 | setfield_paint(fL, *paint, kImage_PaintUsage); |
| 360 | } |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | void SkLuaCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 364 | SkScalar y, const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 365 | AUTO_LUA("drawText"); |
| 366 | setfield_paint(fL, paint, kText_PaintUsage); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void SkLuaCanvas::drawPosText(const void* text, size_t byteLength, |
| 370 | const SkPoint pos[], const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 371 | AUTO_LUA("drawPosText"); |
| 372 | setfield_paint(fL, paint, kText_PaintUsage); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void SkLuaCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 376 | const SkScalar xpos[], SkScalar constY, |
| 377 | const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 378 | AUTO_LUA("drawPosTextH"); |
| 379 | setfield_paint(fL, paint, kText_PaintUsage); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void SkLuaCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 383 | const SkPath& path, const SkMatrix* matrix, |
| 384 | const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 385 | AUTO_LUA("drawTextOnPath"); |
| 386 | setfield_paint(fL, paint, kText_PaintUsage); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void SkLuaCanvas::drawPicture(SkPicture& picture) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 390 | AUTO_LUA("drawPicture"); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 391 | // call through so we can see the nested picture ops |
| 392 | this->INHERITED::drawPicture(picture); |
| 393 | } |
| 394 | |
| 395 | void SkLuaCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 396 | const SkPoint vertices[], const SkPoint texs[], |
| 397 | const SkColor colors[], SkXfermode* xmode, |
| 398 | const uint16_t indices[], int indexCount, |
| 399 | const SkPaint& paint) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 400 | AUTO_LUA("drawVertices"); |
| 401 | setfield_paint(fL, paint); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void SkLuaCanvas::drawData(const void* data, size_t length) { |
| mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 405 | AUTO_LUA("drawData"); |
| reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 406 | } |