add paint:getEffects to return table of bools of a given effect is present on the paint

git-svn-id: http://skia.googlecode.com/svn/trunk@9978 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-07-10 21:23:49 +00:00
parent 7b320703d4
commit 2956387916
2 changed files with 73 additions and 0 deletions

View File

@ -111,6 +111,13 @@ bool SkLua::runCode(const void* code, size_t size) {
#define CHECK_SETFIELD(key) do if (key) lua_setfield(fL, -2, key); while (0)
static void setfield_bool_if(lua_State* L, const char key[], bool pred) {
if (pred) {
lua_pushboolean(L, true);
lua_setfield(L, -2, key);
}
}
static void setfield_string(lua_State* L, const char key[], const char value[]) {
lua_pushstring(L, value);
lua_setfield(L, -2, key);
@ -596,6 +603,21 @@ static int lpaint_getFontMetrics(lua_State* L) {
return 2;
}
static int lpaint_getEffects(lua_State* L) {
const SkPaint* paint = get_obj<SkPaint>(L, 1);
lua_newtable(L);
setfield_bool_if(L, "looper", !!paint->getLooper());
setfield_bool_if(L, "pathEffect", !!paint->getPathEffect());
setfield_bool_if(L, "rasterizer", !!paint->getRasterizer());
setfield_bool_if(L, "maskFilter", !!paint->getMaskFilter());
setfield_bool_if(L, "shader", !!paint->getShader());
setfield_bool_if(L, "colorFilter", !!paint->getColorFilter());
setfield_bool_if(L, "imageFilter", !!paint->getImageFilter());
setfield_bool_if(L, "xfermode", !!paint->getXfermode());
return 1;
}
static int lpaint_gc(lua_State* L) {
get_obj<SkPaint>(L, 1)->~SkPaint();
return 0;
@ -619,6 +641,7 @@ static const struct luaL_Reg gSkPaint_Methods[] = {
{ "setStrokeWidth", lpaint_setStrokeWidth },
{ "measureText", lpaint_measureText },
{ "getFontMetrics", lpaint_getFontMetrics },
{ "getEffects", lpaint_getEffects },
{ "__gc", lpaint_gc },
{ NULL, NULL }
};

View File

@ -0,0 +1,50 @@
function tostr(t)
local str = ""
for k, v in next, t do
if #str > 0 then
str = str .. ", "
end
if type(k) == "number" then
str = str .. "[" .. k .. "] = "
else
str = str .. tostring(k) .. " = "
end
if type(v) == "table" then
str = str .. "{ " .. tostr(v) .. " }"
else
str = str .. tostring(v)
end
end
return str
end
function sk_scrape_startcanvas(c, fileName) end
function sk_scrape_endcanvas(c, fileName) end
local effects = {}
function count_fields(t)
for k, v in next, t do
effects[k] = (effects[k] or 0) + 1
end
end
local total_paints = 0;
function sk_scrape_accumulate(t)
-- dump the params in t, specifically showing the verb first, which we
-- then nil out so it doesn't appear in tostr()
io.write(t.verb, " ")
t.verb = nil
if (t.paint) then
total_paints = total_paints + 1
count_fields(t.paint:getEffects())
end
io.write(tostr(t), "\n")
end
function sk_scrape_summarize()
io.write("total paints ", total_paints, " ", tostr(effects), "\n");
end