blob: 71e8c30d176f1c28e0a4d01c903baa968afe27fe [file] [log] [blame]
fmenozzif023e682016-07-18 08:20:06 -07001filename = ""
2
3function sk_scrape_startcanvas(c, fileName)
4 filename = fileName
5end
6
7function sk_scrape_endcanvas(c, fileName)
8
9end
reed@google.com5fdc9832013-07-24 15:47:52 +000010
fmenozzi90ccfba2016-07-12 14:55:39 -070011LuaDoubleNearlyZero = 1.0 / bit32.lshift(1.0, 12)
fmenozzi7f2c85e2016-07-12 09:17:39 -070012
fmenozzi90ccfba2016-07-12 14:55:39 -070013function LuaDoubleNearlyEqual(a, b)
14 return math.abs(a-b) <= LuaDoubleNearlyZero
fmenozzi7f2c85e2016-07-12 09:17:39 -070015end
16
fmenozzid876a4b2016-07-18 13:33:37 -070017function bounds(rect)
18 local width = rect.right - rect.left
19 local height = rect.bottom - rect.top
20
21 return width, height
22end
23
fmenozzib4f254e2016-06-28 14:03:03 -070024gradients = {}
25
26i = 1
commit-bot@chromium.org74f96b92013-08-01 17:32:56 +000027
reed@google.com5fdc9832013-07-24 15:47:52 +000028function sk_scrape_accumulate(t)
29 local p = t.paint
30 if p then
31 local s = p:getShader()
32 if s then
33 local g = s:asAGradient()
34 if g then
fmenozzib4f254e2016-06-28 14:03:03 -070035 gradients[i] = {}
fmenozzi7f2c85e2016-07-12 09:17:39 -070036
fmenozzif023e682016-07-18 08:20:06 -070037 gradients[i].filename = filename
38
fmenozzid876a4b2016-07-18 13:33:37 -070039 local width, height = -1, -1
40 if t.rect then
41 width, height = bounds(t.rect)
42 elseif t.rrect then
43 width, height = bounds(t.rrect:rect())
44 elseif t.path then
45 width, height = bounds(t.path:getBounds())
46 end
47 gradients[i].boundsWidth = width
48 gradients[i].boundsHeight = height
49
fmenozzi7f2c85e2016-07-12 09:17:39 -070050 gradients[i].colorCount = g.colorCount
51 gradients[i].type = g.type
52 gradients[i].tile = g.tile
53
fmenozzi7f2c85e2016-07-12 09:17:39 -070054 isEvenlySpaced = true
fmenozzi90ccfba2016-07-12 14:55:39 -070055 for j = 1, g.colorCount, 1 do
56 if not LuaDoubleNearlyEqual(g.positions[j], (j-1)/(g.colorCount-1)) then
fmenozzi7f2c85e2016-07-12 09:17:39 -070057 isEvenlySpaced = false
58 end
fmenozzi90ccfba2016-07-12 14:55:39 -070059 end
60 gradients[i].isEvenlySpaced = isEvenlySpaced
fmenozzi7f2c85e2016-07-12 09:17:39 -070061
fmenozzi90ccfba2016-07-12 14:55:39 -070062 numHardStops = 0
63 for j = 2, g.colorCount, 1 do
64 if LuaDoubleNearlyEqual(g.positions[j], g.positions[j-1]) then
fmenozzi7f2c85e2016-07-12 09:17:39 -070065 numHardStops = numHardStops + 1
66 end
67 end
fmenozzi016e51f2016-07-14 07:44:50 -070068 gradients[i].numHardStops = numHardStops
commit-bot@chromium.org74f96b92013-08-01 17:32:56 +000069
fmenozzi016e51f2016-07-14 07:44:50 -070070 gradients[i].verb = t.verb
71
fmenozzib4f254e2016-06-28 14:03:03 -070072 gradients[i].positions = {}
73 for j = 1, g.colorCount, 1 do
74 gradients[i].positions[j] = g.positions[j]
75 end
76
77 i = i + 1
reed@google.com5fdc9832013-07-24 15:47:52 +000078 end
79 end
80 end
81end
82
fmenozzib4f254e2016-06-28 14:03:03 -070083function sk_scrape_summarize()
84 for k, v in pairs(gradients) do
85 local pos = ""
86 for j = 1, v.colorCount , 1 do
87 pos = pos .. v.positions[j]
88 if j ~= v.colorCount then
89 pos = pos .. ","
90 end
91 end
92
fmenozzid876a4b2016-07-18 13:33:37 -070093 io.write(string.format("%s %d %s %s %d %d %s %d %d %s\n",
fmenozzif023e682016-07-18 08:20:06 -070094 v.filename,
fmenozzib4f254e2016-06-28 14:03:03 -070095 v.colorCount,
96 v.type,
97 v.tile,
98 tonumber(v.isEvenlySpaced and 1 or 0),
fmenozzi7f2c85e2016-07-12 09:17:39 -070099 v.numHardStops,
fmenozzi016e51f2016-07-14 07:44:50 -0700100 v.verb,
fmenozzid876a4b2016-07-18 13:33:37 -0700101 v.boundsWidth,
102 v.boundsHeight,
fmenozzib4f254e2016-06-28 14:03:03 -0700103 pos))
104 end
commit-bot@chromium.org74f96b92013-08-01 17:32:56 +0000105end
reed@google.com5fdc9832013-07-24 15:47:52 +0000106