support SkCanvas as a real lua object
git-svn-id: http://skia.googlecode.com/svn/trunk@9208 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index d0343a4..36e8c93 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -99,6 +99,20 @@
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 @@
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 de0be08..739a2f7 100644
--- a/tools/lua/scrape.lua
+++ b/tools/lua/scrape.lua
@@ -19,14 +19,21 @@
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 @@
-- 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