paths.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. -- Path scraping script.
  8. -- This script is designed to count the number of times we fall back to software
  9. -- rendering for a path in a given SKP. However, this script does not count an exact
  10. -- number of uploads, since there is some overlap with clipping: e.g. two clipped paths
  11. -- may cause three uploads to the GPU (set clip 1, set clip 2, unset clip 2/reset clip 1),
  12. -- but these cases are rare.
  13. draws = 0
  14. drawPaths = 0
  15. drawPathsAnti = 0
  16. drawPathsConvexAnti = 0
  17. clips = 0
  18. clipPaths = 0
  19. clipPathsAnti = 0
  20. clipPathsConvexAnti = 0
  21. usedPath = false
  22. usedSWPath = false
  23. skpsTotal = 0
  24. skpsWithPath = 0
  25. skpsWithSWPath = 0
  26. function sk_scrape_startcanvas(c, fileName)
  27. usedPath = false
  28. usedSWPath = false
  29. end
  30. function sk_scrape_endcanvas(c, fileName)
  31. skpsTotal = skpsTotal + 1
  32. if usedPath then
  33. skpsWithPath = skpsWithPath + 1
  34. if usedSWPath then
  35. skpsWithSWPath = skpsWithSWPath + 1
  36. end
  37. end
  38. end
  39. function string.starts(String,Start)
  40. return string.sub(String,1,string.len(Start))==Start
  41. end
  42. function isPathValid(path)
  43. if not path then
  44. return false
  45. end
  46. if path:isEmpty() then
  47. return false
  48. end
  49. if path:isRect() then
  50. return false
  51. end
  52. return true
  53. end
  54. function sk_scrape_accumulate(t)
  55. if (string.starts(t.verb, "draw")) then
  56. draws = draws + 1
  57. end
  58. if (string.starts(t.verb, "clip")) then
  59. clips = clips + 1
  60. end
  61. if t.verb == "clipPath" then
  62. local path = t.path
  63. if isPathValid(path) then
  64. clipPaths = clipPaths + 1
  65. usedPath = true
  66. if t.aa then
  67. clipPathsAnti = clipPathsAnti + 1
  68. if path:isConvex() then
  69. clipPathsConvexAnti = clipPathsConvexAnti + 1
  70. else
  71. usedSWPath = true
  72. end
  73. end
  74. end
  75. end
  76. if t.verb == "drawPath" then
  77. local path = t.path
  78. local paint = t.paint
  79. if paint and isPathValid(path) then
  80. drawPaths = drawPaths + 1
  81. usedPath = true
  82. if paint:isAntiAlias() then
  83. drawPathsAnti = drawPathsAnti + 1
  84. if path:isConvex() then
  85. drawPathsConvexAnti = drawPathsConvexAnti + 1
  86. else
  87. usedSWPath = true
  88. end
  89. end
  90. end
  91. end
  92. end
  93. function sk_scrape_summarize()
  94. local swDrawPaths = drawPathsAnti - drawPathsConvexAnti
  95. local swClipPaths = clipPathsAnti - clipPathsConvexAnti
  96. io.write("clips = clips + ", clips, "\n");
  97. io.write("draws = draws + ", draws, "\n");
  98. io.write("clipPaths = clipPaths + ", clipPaths, "\n");
  99. io.write("drawPaths = drawPaths + ", drawPaths, "\n");
  100. io.write("swClipPaths = swClipPaths + ", swClipPaths, "\n");
  101. io.write("swDrawPaths = swDrawPaths + ", swDrawPaths, "\n");
  102. io.write("skpsTotal = skpsTotal + ", skpsTotal, "\n");
  103. io.write("skpsWithPath = skpsWithPath + ", skpsWithPath, "\n");
  104. io.write("skpsWithSWPath = skpsWithSWPath + ", skpsWithSWPath, "\n");
  105. end