• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2014 Google Inc.
3--
4-- Use of this source code is governed by a BSD-style license that can be
5-- found in the LICENSE file.
6--
7
8-- Path scraping script.
9-- This script is designed to count the number of times we fall back to software
10-- rendering for a path in a given SKP. However, this script does not count an exact
11-- number of uploads, since there is some overlap with clipping: e.g. two clipped paths
12-- may cause three uploads to the GPU (set clip 1, set clip 2, unset clip 2/reset clip 1),
13-- but these cases are rare.
14
15draws = 0
16drawPaths = 0
17drawPathsAnti = 0
18drawPathsConvexAnti = 0
19
20clips = 0
21clipPaths = 0
22clipPathsAnti = 0
23clipPathsConvexAnti = 0
24
25usedPath = false
26usedSWPath = false
27
28skpsTotal = 0
29skpsWithPath = 0
30skpsWithSWPath = 0
31
32function sk_scrape_startcanvas(c, fileName)
33   usedPath = false
34   usedSWPath = false
35end
36
37function sk_scrape_endcanvas(c, fileName)
38   skpsTotal = skpsTotal + 1
39   if usedPath then
40      skpsWithPath = skpsWithPath + 1
41      if usedSWPath then
42         skpsWithSWPath = skpsWithSWPath + 1
43      end
44   end
45end
46
47function string.starts(String,Start)
48   return string.sub(String,1,string.len(Start))==Start
49end
50
51function isPathValid(path)
52   if not path then
53      return false
54   end
55
56   if path:isEmpty() then
57      return false
58   end
59
60   if path:isRect() then
61      return false
62   end
63
64   return true
65end
66
67function sk_scrape_accumulate(t)
68   if (string.starts(t.verb, "draw")) then
69      draws = draws + 1
70   end
71
72   if (string.starts(t.verb, "clip")) then
73      clips = clips + 1
74   end
75
76   if t.verb == "clipPath" then
77      local path = t.path
78      if isPathValid(path) then
79         clipPaths = clipPaths + 1
80         usedPath = true
81         if t.aa then
82            clipPathsAnti = clipPathsAnti + 1
83            if path:isConvex() then
84               clipPathsConvexAnti = clipPathsConvexAnti + 1
85            else
86               usedSWPath = true
87            end
88         end
89      end
90   end
91
92   if t.verb == "drawPath" then
93      local path = t.path
94      local paint = t.paint
95      if paint and isPathValid(path) then
96         drawPaths = drawPaths + 1
97         usedPath = true
98         if paint:isAntiAlias() then
99            drawPathsAnti = drawPathsAnti + 1
100            if path:isConvex() then
101               drawPathsConvexAnti = drawPathsConvexAnti + 1
102            else
103               usedSWPath = true
104            end
105         end
106      end
107   end
108end
109
110function sk_scrape_summarize()
111   local swDrawPaths = drawPathsAnti - drawPathsConvexAnti
112   local swClipPaths = clipPathsAnti - clipPathsConvexAnti
113
114   io.write("clips = clips + ", clips, "\n");
115   io.write("draws = draws + ", draws, "\n");
116   io.write("clipPaths = clipPaths + ", clipPaths, "\n");
117   io.write("drawPaths = drawPaths + ", drawPaths, "\n");
118   io.write("swClipPaths = swClipPaths + ", swClipPaths, "\n");
119   io.write("swDrawPaths = swDrawPaths + ", swDrawPaths, "\n");
120
121   io.write("skpsTotal = skpsTotal + ", skpsTotal, "\n");
122   io.write("skpsWithPath = skpsWithPath + ", skpsWithPath, "\n");
123   io.write("skpsWithSWPath = skpsWithSWPath + ", skpsWithSWPath, "\n");
124end
125