add startcanvas/endcanvas entry-points for the script. rename all "official" entry-points to use "sk_scrape_" prefix

BUG=

Review URL: https://codereview.chromium.org/15511006

git-svn-id: http://skia.googlecode.com/svn/trunk@9216 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-05-21 16:05:53 +00:00
parent 659c8c06cd
commit 2d51677b19
2 changed files with 50 additions and 16 deletions

View File

@ -21,6 +21,11 @@ extern "C" {
#include "lauxlib.h"
}
static const char gStartCanvasFunc[] = "sk_scrape_startcanvas";
static const char gEndCanvasFunc[] = "sk_scrape_endcanvas";
static const char gAccumulateFunc[] = "sk_scrape_accumulate";
static const char gSummarizeFunc[] = "sk_scrape_summarize";
// PictureRenderingFlags.cpp
extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap*);
@ -99,15 +104,17 @@ private:
SkString fTermCode;
};
static void call_setcanvas(lua_State* L, SkLuaCanvas* canvas) {
lua_getglobal(L, "setcanvas");
static void call_canvas(lua_State* L, SkLuaCanvas* canvas,
const char pictureFile[], const char funcName[]) {
lua_getglobal(L, funcName);
if (!lua_isfunction(L, -1)) {
int t = lua_type(L, -1);
SkDebugf("--- expected setcanvas function %d\n", t);
SkDebugf("--- expected %s function %d, ignoring.\n", funcName, t);
lua_settop(L, -2);
} else {
canvas->pushThis();
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
lua_pushstring(L, pictureFile);
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
SkDebugf("lua err: %s\n", lua_tostring(L, -1));
}
}
@ -128,7 +135,7 @@ int tool_main(int argc, char** argv) {
}
SkAutoGraphics ag;
SkAutoLua L("summarize");
SkAutoLua L(gSummarizeFunc);
for (int i = 0; i < FLAGS_luaFile.count(); ++i) {
SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i]));
@ -153,11 +160,14 @@ int tool_main(int argc, char** argv) {
SkAutoTUnref<SkPicture> pic(load_picture(path));
if (pic.get()) {
SkAutoTUnref<SkLuaCanvas> canvas(new SkLuaCanvas(pic->width(), pic->height(), L.get(), "accumulate"));
call_setcanvas(L.get(), canvas.get());
SkAutoTUnref<SkLuaCanvas> canvas(
new SkLuaCanvas(pic->width(), pic->height(),
L.get(), gAccumulateFunc));
call_canvas(L.get(), canvas.get(), inputFilename.c_str(), gStartCanvasFunc);
canvas->drawPicture(*pic);
call_canvas(L.get(), canvas.get(), inputFilename.c_str(), gEndCanvasFunc);
} else {
SkDebugf("failed to load\n");
}

View File

@ -19,14 +19,36 @@ function tostr(t)
return str
end
total = {}
local total = {} -- accumulate() stores its data in here
local canvas -- holds the current canvas (from startcanvas())
function setcanvas(c)
--[[
startcanvas() is called at the start of each picture file, passing the
canvas that we will be drawing into, and the name of the file.
Following this call, there will be some number of calls to accumulate(t)
where t is a table of parameters that were passed to that draw-op.
t.verb is a string holding the name of the draw-op (e.g. "drawRect")
when a given picture is done, we call endcanvas(canvas, fileName)
]]
function sk_scrape_startcanvas(c, fileName)
canvas = c
end
-- called with the parameters to each canvas.draw call
function accumulate(t)
--[[
Called when the current canvas is done drawing.
]]
function sk_scrape_endcanvas(c, fileName)
canvas = nil
end
--[[
Called with the parameters to each canvas.draw call, where canvas is the
current canvas as set by startcanvas()
]]
function sk_scrape_accumulate(t)
local n = total[t.verb] or 0
total[t.verb] = n + 1
@ -45,9 +67,11 @@ function accumulate(t)
end
end
-- lua_pictures will call this function after all of the files have been
-- "accumulated"
function summarize()
io.write("\n", tostr(total), "\n")
--[[
lua_pictures will call this function after all of the pictures have been
"accumulated".
]]
function sk_scrape_summarize()
io.write("\n{ ", tostr(total), " }\n")
end