diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/lua/lua_pictures.cpp | 15 | ||||
-rw-r--r-- | tools/lua/scrape.lua | 45 | ||||
-rw-r--r-- | tools/lua/skia.lua | 81 |
3 files changed, 114 insertions, 27 deletions
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp index 4a805147a6..d0343a4548 100644 --- a/tools/lua/lua_pictures.cpp +++ b/tools/lua/lua_pictures.cpp @@ -109,17 +109,20 @@ int tool_main(int argc, char** argv) { exit(-1); } if (FLAGS_luaFile.isEmpty()) { - SkDebugf("missing luaFile\n"); + SkDebugf("missing luaFile(s)\n"); exit(-1); } - SkAutoDataUnref data(read_into_data(FLAGS_luaFile[0])); - SkAutoGraphics ag; SkAutoLua L("summarize"); - if (!L.load(data->data(), data->size())) { - SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[0]); - exit(-1); + + for (int i = 0; i < FLAGS_luaFile.count(); ++i) { + SkAutoDataUnref data(read_into_data(FLAGS_luaFile[i])); + SkDebugf("loading %s...\n", FLAGS_luaFile[i]); + if (!L.load(data->data(), data->size())) { + SkDebugf("failed to load luaFile %s\n", FLAGS_luaFile[i]); + exit(-1); + } } for (int i = 0; i < FLAGS_skpPath.count(); i ++) { diff --git a/tools/lua/scrape.lua b/tools/lua/scrape.lua index 839d3fe868..de0be08ddb 100644 --- a/tools/lua/scrape.lua +++ b/tools/lua/scrape.lua @@ -1,11 +1,19 @@ +-- just a helper function to dump the parameters, for debugging function tostr(t) local str = "" for k, v in next, t do - str = str .. tostring(k) .. " " + 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) .. "} " + str = str .. "{ " .. tostr(v) .. " }" else - str = str .. tostring(v) .. " " + str = str .. tostring(v) end end return str @@ -14,30 +22,25 @@ end canvas = {} total = 0 +-- called with the parameters to each canvas.draw call function accumulate(t) - local verb = t.verb - t.verb = nil - total = total + 1 - local n = canvas[verb] or 0 - n = n + 1 - canvas[verb] = n + local n = canvas[t.verb] or 0 + canvas[t.verb] = n + 1 - io.write(verb, " ") - io.write(tostr(t), "\n") + -- enable to dump all of the parameters we were sent + if false then + -- 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 + io.write(tostr(t), "\n") + end 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") end ---[[ -function drawsomething() - local s = skia_newsurface(100, 100) - local c = s:getcanvas(); - c:setColor(1, 0, 0, 1) - c:drawRect(10, 10, 50, 50) - s:saveImage("image.png") -end ---]] - diff --git a/tools/lua/skia.lua b/tools/lua/skia.lua new file mode 100644 index 0000000000..88c3223299 --- /dev/null +++ b/tools/lua/skia.lua @@ -0,0 +1,81 @@ +Sk = {} + +function Sk.isFinite(x) + return x * 0 == 0 +end + +------------------------------------------------------------------------------- + +Sk.Rect = { left = 0, top = 0, right = 0, bottom = 0 } +Sk.Rect.__index = Sk.Rect + +function Sk.Rect.new(l, t, r, b) + local rect + if r then + -- 4 arguments + rect = { left = l, top = t, right = r, bottom = b } + elseif l then + -- 2 arguments + rect = { right = l, bottom = t } + else + -- 0 arguments + rect = {} + end + setmetatable(rect, Sk.Rect) + return rect; +end + +function Sk.Rect:width() + return self.right - self.left +end + +function Sk.Rect:height() + return self.bottom - self.top +end + +function Sk.Rect:isEmpty() + return self:width() <= 0 or self:height() <= 0 +end + +function Sk.Rect:isFinite() + local value = self.left * 0 + value = value * self.top + value = value * self.right + value = value * self.bottom + return 0 == value +end + +function Sk.Rect:setEmpty() + self.left = 0 + self.top = 0 + self.right = 0 + self.bottom = 0 +end + +function Sk.Rect:set(l, t, r, b) + self.left = l + self.top = t + self.right = r + self.bottom = b +end + +function Sk.Rect:offset(dx, dy) + dy = dy or dx + + self.left = self.left + dx + self.top = self.top + dy + self.right = self.right + dx + self.bottom = self.bottom + dy +end + +function Sk.Rect:inset(dx, dy) + dy = dy or dx + + self.left = self.left + dx + self.top = self.top + dy + self.right = self.right - dx + self.bottom = self.bottom - dy +end + +------------------------------------------------------------------------------- + |