blob: 92636121da7405514b9187890d33b4ef00526d07 [file] [log] [blame]
mike@reedtribe.org0e59b792013-05-21 03:24:37 +00001-- just a helper function to dump the parameters, for debugging
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +00002function tostr(t)
3 local str = ""
4 for k, v in next, t do
mike@reedtribe.org0e59b792013-05-21 03:24:37 +00005 if #str > 0 then
6 str = str .. ", "
7 end
8 if type(k) == "number" then
9 str = str .. "[" .. k .. "] = "
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000010 else
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000011 str = str .. tostring(k) .. " = "
12 end
13 if type(v) == "table" then
14 str = str .. "{ " .. tostr(v) .. " }"
15 else
16 str = str .. tostring(v)
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000017 end
18 end
19 return str
20end
21
reed@google.com2d516772013-05-21 16:05:53 +000022local total = {} -- accumulate() stores its data in here
23local canvas -- holds the current canvas (from startcanvas())
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000024
reed@google.com2d516772013-05-21 16:05:53 +000025--[[
26 startcanvas() is called at the start of each picture file, passing the
27 canvas that we will be drawing into, and the name of the file.
28
29 Following this call, there will be some number of calls to accumulate(t)
30 where t is a table of parameters that were passed to that draw-op.
31
32 t.verb is a string holding the name of the draw-op (e.g. "drawRect")
33
34 when a given picture is done, we call endcanvas(canvas, fileName)
35]]
36function sk_scrape_startcanvas(c, fileName)
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000037 canvas = c
38end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000039
reed@google.com2d516772013-05-21 16:05:53 +000040--[[
41 Called when the current canvas is done drawing.
42]]
43function sk_scrape_endcanvas(c, fileName)
44 canvas = nil
45end
46
47--[[
48 Called with the parameters to each canvas.draw call, where canvas is the
49 current canvas as set by startcanvas()
50]]
51function sk_scrape_accumulate(t)
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000052 local n = total[t.verb] or 0
53 total[t.verb] = n + 1
54
reed@google.com14f584b2013-05-21 14:19:53 +000055 if false and t.verb == "drawRect" then
mike@reedtribe.orgf02fe3d2013-05-21 12:20:39 +000056 local m = canvas:getTotalMatrix()
57 print("... ", tostr(m), "\n")
58 end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000059
reed@google.com9a731042013-05-21 17:52:33 +000060 if false and t.verb == "drawPath" then
61 local pred, r1, r2, d1, d2 = t.path:isNestedRects()
62
63 if pred then
64 print("drawRect_Nested", tostr(r1), tostr(r2), d1, d2)
65 else
66 print("drawPath", "isEmpty", tostring(t.path:isEmpty()),
67 "isRect", tostring(t.path:isRect()), tostr(t.path:getBounds()))
68 end
69 end
70
mike@reedtribe.org0e59b792013-05-21 03:24:37 +000071 -- enable to dump all of the parameters we were sent
72 if false then
73 -- dump the params in t, specifically showing the verb first, which we
74 -- then nil out so it doesn't appear in tostr()
75 io.write(t.verb, " ")
76 t.verb = nil
77 io.write(tostr(t), "\n")
78 end
reed@google.comdff7e112013-05-15 19:34:20 +000079end
mike@reedtribe.org1c5a94f2013-05-16 04:20:23 +000080
reed@google.com2d516772013-05-21 16:05:53 +000081--[[
82 lua_pictures will call this function after all of the pictures have been
83 "accumulated".
84]]
85function sk_scrape_summarize()
86 io.write("\n{ ", tostr(total), " }\n")
reed@google.comdff7e112013-05-15 19:34:20 +000087end
88