diff options
author | 2013-07-10 22:42:30 +0000 | |
---|---|---|
committer | 2013-07-10 22:42:30 +0000 | |
commit | 2815c19c4d52f0fb522e21d1938d63e01c039124 (patch) | |
tree | 56192917aac1df3866f41499b68bd390a020351e | |
parent | cdad30b35ac0c0b2fa0e1105021f880b49b0ac38 (diff) |
add matrix objects to the lua bindings, as well as a lua script to find the proportion of image draw commands with different kinds of matrices
git-svn-id: http://skia.googlecode.com/svn/trunk@9986 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/utils/SkLua.cpp | 24 | ||||
-rw-r--r-- | tools/lua/find_rotated_bitmaps.lua | 71 | ||||
-rw-r--r-- | tools/lua/skia.lua | 9 |
3 files changed, 104 insertions, 0 deletions
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 04dfbb1ecc..658b43ba5a 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -128,6 +128,11 @@ static void setfield_number(lua_State* L, const char key[], double value) { lua_setfield(L, -2, key); } +static void setfield_boolean(lua_State* L, const char key[], bool value) { + lua_pushboolean(L, value); + lua_setfield(L, -2, key); +} + static void setfield_scalar(lua_State* L, const char key[], SkScalar value) { setfield_number(L, key, SkScalarToLua(value)); } @@ -648,6 +653,24 @@ static const struct luaL_Reg gSkPaint_Methods[] = { /////////////////////////////////////////////////////////////////////////////// +static int lmatrix_getType(lua_State* L) { + SkMatrix::TypeMask mask = get_obj<SkMatrix>(L, 1)->getType(); + + lua_newtable(L); + setfield_boolean(L, "translate", SkToBool(mask & SkMatrix::kTranslate_Mask)); + setfield_boolean(L, "scale", SkToBool(mask & SkMatrix::kScale_Mask)); + setfield_boolean(L, "affine", SkToBool(mask & SkMatrix::kAffine_Mask)); + setfield_boolean(L, "perspective", SkToBool(mask & SkMatrix::kPerspective_Mask)); + return 1; +} + +static const struct luaL_Reg gSkMatrix_Methods[] = { + { "getType", lmatrix_getType }, + { NULL, NULL } +}; + +/////////////////////////////////////////////////////////////////////////////// + static int lpath_getBounds(lua_State* L) { SkLua(L).pushRect(get_obj<SkPath>(L, 1)->getBounds()); return 1; @@ -971,6 +994,7 @@ void SkLua::Load(lua_State* L) { REG_CLASS(L, SkPaint); REG_CLASS(L, SkRRect); REG_CLASS(L, SkTypeface); + REG_CLASS(L, SkMatrix); } extern "C" int luaopen_skia(lua_State* L); diff --git a/tools/lua/find_rotated_bitmaps.lua b/tools/lua/find_rotated_bitmaps.lua new file mode 100644 index 0000000000..9886e21308 --- /dev/null +++ b/tools/lua/find_rotated_bitmaps.lua @@ -0,0 +1,71 @@ +function string.startsWith(String,Start) + return string.sub(String,1,string.len(Start))==Start +end + +function string.endsWith(String,End) + return End=='' or string.sub(String,-string.len(End))==End +end + +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 + +local canvas = nil +local num_perspective_bitmaps = 0 +local num_affine_bitmaps = 0 +local num_scaled_bitmaps = 0 +local num_translated_bitmaps = 0 +local num_identity_bitmaps = 0 + +function sk_scrape_startcanvas(c, fileName) + canvas = c +end + +function sk_scrape_endcanvas(c, fileName) + canvas = nil +end + +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() + if (string.startsWith(t.verb,"drawBitmap")) then + matrix = canvas:getTotalMatrix() + matrixType = matrix:getType() + if matrixType.perspective then + num_perspective_bitmaps = num_perspective_bitmaps + 1 + elseif matrixType.affine then + num_affine_bitmaps = num_affine_bitmaps + 1 + elseif matrixType.scale then + num_scaled_bitmaps = num_scaled_bitmaps + 1 + elseif matrixType.translate then + num_translated_bitmaps = num_translated_bitmaps + 1 + else + num_identity_bitmaps = num_identity_bitmaps + 1 + end + end +end + +function sk_scrape_summarize() + io.write( "identity = ", num_identity_bitmaps, + ", translated = ", num_translated_bitmaps, + ", scaled = ", num_scaled_bitmaps, + ", affine = ", num_affine_bitmaps, + ", perspective = ", num_perspective_bitmaps) +end + diff --git a/tools/lua/skia.lua b/tools/lua/skia.lua index fe738d1880..e15e122703 100644 --- a/tools/lua/skia.lua +++ b/tools/lua/skia.lua @@ -1,5 +1,14 @@ -- Experimental helpers for skia -- +function string.startsWith(String,Start) + return string.sub(String,1,string.len(Start))==Start +end + +function string.endsWith(String,End) + return End=='' or string.sub(String,-string.len(End))==End +end + + Sk = {} function Sk.isFinite(x) |