diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-21 12:20:39 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-05-21 12:20:39 +0000 |
commit | f02fe3d4fec9120da009c941d14af66980911a4e (patch) | |
tree | 632d25cd46eb28bace4c428663caaca87df809e8 /tools/lua | |
parent | 3e50e99fe7e6d5dbc3f3f834c8c312474d3ad057 (diff) |
support SkCanvas as a real lua object
git-svn-id: http://skia.googlecode.com/svn/trunk@9208 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/lua')
-rw-r--r-- | tools/lua/lua_pictures.cpp | 21 | ||||
-rw-r--r-- | tools/lua/scrape.lua | 19 |
2 files changed, 32 insertions, 8 deletions
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp index d0343a4548..36e8c93bf1 100644 --- a/tools/lua/lua_pictures.cpp +++ b/tools/lua/lua_pictures.cpp @@ -99,6 +99,20 @@ private: SkString fTermCode; }; +static void call_setcanvas(lua_State* L, SkLuaCanvas* canvas) { + lua_getglobal(L, "setcanvas"); + if (!lua_isfunction(L, -1)) { + int t = lua_type(L, -1); + SkDebugf("--- expected setcanvas function %d\n", t); + lua_settop(L, -2); + } else { + canvas->pushThis(); + if (lua_pcall(L, 1, 0, 0) != LUA_OK) { + SkDebugf("lua err: %s\n", lua_tostring(L, -1)); + } + } +} + int tool_main(int argc, char** argv); int tool_main(int argc, char** argv) { SkCommandLineFlags::SetUsage("apply lua script to .skp files."); @@ -139,8 +153,11 @@ int tool_main(int argc, char** argv) { SkAutoTUnref<SkPicture> pic(load_picture(path)); if (pic.get()) { - SkLuaCanvas canvas(pic->width(), pic->height(), L.get(), "accumulate"); - canvas.drawPicture(*pic); + SkAutoTUnref<SkLuaCanvas> canvas(new SkLuaCanvas(pic->width(), pic->height(), L.get(), "accumulate")); + + call_setcanvas(L.get(), canvas.get()); + + canvas->drawPicture(*pic); } else { SkDebugf("failed to load\n"); } diff --git a/tools/lua/scrape.lua b/tools/lua/scrape.lua index de0be08ddb..739a2f77ac 100644 --- a/tools/lua/scrape.lua +++ b/tools/lua/scrape.lua @@ -19,14 +19,21 @@ function tostr(t) return str end -canvas = {} -total = 0 +total = {} + +function setcanvas(c) + canvas = c +end -- called with the parameters to each canvas.draw call function accumulate(t) - total = total + 1 - local n = canvas[t.verb] or 0 - canvas[t.verb] = n + 1 + local n = total[t.verb] or 0 + total[t.verb] = n + 1 + + if t.verb == "drawRect" then + local m = canvas:getTotalMatrix() + print("... ", tostr(m), "\n") + end -- enable to dump all of the parameters we were sent if false then @@ -41,6 +48,6 @@ end -- lua_pictures will call this function after all of the files have been -- "accumulated" function summarize() - io.write("total ", total, "\n", tostr(canvas), "\n") + io.write("\n", tostr(total), "\n") end |