blob: 627018800acb2839f2b6be47dc63c4a1e2391bc7 [file] [log] [blame]
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +00001function tostr(t)
2 local str = ""
3 for k, v in next, t do
mike@reedtribe.org0e59b792013-05-21 03:24:37 +00004 if #str > 0 then
5 str = str .. ", "
6 end
7 if type(k) == "number" then
8 str = str .. "[" .. k .. "] = "
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +00009 else
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000010 str = str .. tostring(k) .. " = "
11 end
12 if type(v) == "table" then
13 str = str .. "{ " .. tostr(v) .. " }"
14 else
15 str = str .. tostring(v)
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000016 end
17 end
18 return str
19end
20
reed@google.com2d516772013-05-21 16:05:53 +000021local total = {} -- accumulate() stores its data in here
22local canvas -- holds the current canvas (from startcanvas())
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000023
reed@google.com2d516772013-05-21 16:05:53 +000024--[[
25 startcanvas() is called at the start of each picture file, passing the
26 canvas that we will be drawing into, and the name of the file.
27
28 Following this call, there will be some number of calls to accumulate(t)
29 where t is a table of parameters that were passed to that draw-op.
30
31 t.verb is a string holding the name of the draw-op (e.g. "drawRect")
32
33 when a given picture is done, we call endcanvas(canvas, fileName)
34]]
35function sk_scrape_startcanvas(c, fileName)
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000036 canvas = c
37end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000038
reed@google.com2d516772013-05-21 16:05:53 +000039--[[
40 Called when the current canvas is done drawing.
41]]
42function sk_scrape_endcanvas(c, fileName)
43 canvas = nil
44end
45
46--[[
47 Called with the parameters to each canvas.draw call, where canvas is the
48 current canvas as set by startcanvas()
49]]
50function sk_scrape_accumulate(t)
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000051 local n = total[t.verb] or 0
52 total[t.verb] = n + 1
53
reed@google.com74ce6f02013-05-22 15:13:18 +000054 if false and t.verb == "drawRect" and t.paint:isAntiAlias() then
55 local r = t.rect;
56 local p = t.paint;
57 local c = p:getColor();
58 print("drawRect ", tostr(r), tostr(c), "\n")
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000059 end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000060
reed@google.com9a731042013-05-21 17:52:33 +000061 if false and t.verb == "drawPath" then
62 local pred, r1, r2, d1, d2 = t.path:isNestedRects()
63
64 if pred then
65 print("drawRect_Nested", tostr(r1), tostr(r2), d1, d2)
66 else
67 print("drawPath", "isEmpty", tostring(t.path:isEmpty()),
68 "isRect", tostring(t.path:isRect()), tostr(t.path:getBounds()))
69 end
70 end
reed@google.comdff7e112013-05-15 19:34:20 +000071end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000072
reed@google.com2d516772013-05-21 16:05:53 +000073--[[
74 lua_pictures will call this function after all of the pictures have been
75 "accumulated".
76]]
77function sk_scrape_summarize()
78 io.write("\n{ ", tostr(total), " }\n")
reed@google.comdff7e112013-05-15 19:34:20 +000079end
80