debug_colors.cc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. // Copyright 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "cc/debug/debug_colors.h"
  5. #include "base/check_op.h"
  6. #include "base/notreached.h"
  7. namespace cc {
  8. static float Scale(float width, float device_scale_factor) {
  9. return width * device_scale_factor;
  10. }
  11. // ======= Layer border colors =======
  12. // Tiled content layers are orange.
  13. SkColor4f DebugColors::TiledContentLayerBorderColor() {
  14. return {1.0f, 0.5f, 0.0f, 0.5f};
  15. }
  16. int DebugColors::TiledContentLayerBorderWidth(float device_scale_factor) {
  17. return Scale(2, device_scale_factor);
  18. }
  19. // Image layers are olive.
  20. SkColor4f DebugColors::ImageLayerBorderColor() {
  21. return {0.5f, 0.5f, 0.0f, 0.5f};
  22. }
  23. int DebugColors::ImageLayerBorderWidth(float device_scale_factor) {
  24. return Scale(2, device_scale_factor);
  25. }
  26. // Non-tiled content layers area green.
  27. SkColor4f DebugColors::ContentLayerBorderColor() {
  28. return {0.0f, 0.5f, 32.0f / 255.0f, 0.5f};
  29. }
  30. int DebugColors::ContentLayerBorderWidth(float device_scale_factor) {
  31. return Scale(2, device_scale_factor);
  32. }
  33. // Other container layers are yellow.
  34. SkColor4f DebugColors::ContainerLayerBorderColor() {
  35. return {1.0f, 1.0f, 0.0f, 0.75f};
  36. }
  37. int DebugColors::ContainerLayerBorderWidth(float device_scale_factor) {
  38. return Scale(2, device_scale_factor);
  39. }
  40. // Surface layers are a blue-ish green.
  41. SkColor4f DebugColors::SurfaceLayerBorderColor() {
  42. return {0.0f, 1.0f, 136.0f / 255.0f, 0.5f};
  43. }
  44. int DebugColors::SurfaceLayerBorderWidth(float device_scale_factor) {
  45. return Scale(2, device_scale_factor);
  46. }
  47. // Render surfaces are blue.
  48. SkColor4f DebugColors::SurfaceBorderColor() {
  49. return {0.0f, 0.0f, 1.0f, 100.0f / 255.0f};
  50. }
  51. int DebugColors::SurfaceBorderWidth(float device_scale_factor) {
  52. return Scale(2, device_scale_factor);
  53. }
  54. // ======= Tile colors =======
  55. // High-res tile borders are cyan.
  56. SkColor4f DebugColors::HighResTileBorderColor() {
  57. return {80.0f / 255.0f, 200.0f / 255.0f, 200.0f / 255.0f, 100.0f / 255.0f};
  58. }
  59. int DebugColors::HighResTileBorderWidth(float device_scale_factor) {
  60. return Scale(1, device_scale_factor);
  61. }
  62. // Low-res tile borders are purple.
  63. SkColor4f DebugColors::LowResTileBorderColor() {
  64. return {212.0f / 255.0f, 83.0f / 255.0f, 0.75f, 100.0f / 255.0f};
  65. }
  66. int DebugColors::LowResTileBorderWidth(float device_scale_factor) {
  67. return Scale(2, device_scale_factor);
  68. }
  69. // Other high-resolution tile borders are yellow.
  70. SkColor4f DebugColors::ExtraHighResTileBorderColor() {
  71. return {239.0f / 255.0f, 231.0f / 255.0f, 20.0f / 255.0f, 100.0f / 255.0f};
  72. }
  73. int DebugColors::ExtraHighResTileBorderWidth(float device_scale_factor) {
  74. return Scale(2, device_scale_factor);
  75. }
  76. // Other low-resolution tile borders are green.
  77. SkColor4f DebugColors::ExtraLowResTileBorderColor() {
  78. return {93.0f / 255.0f, 186.0f / 255.0f, 18.0f / 255.0f, 100.0f / 255.0f};
  79. }
  80. int DebugColors::ExtraLowResTileBorderWidth(float device_scale_factor) {
  81. return Scale(2, device_scale_factor);
  82. }
  83. // Missing tile borders are dark grey.
  84. SkColor4f DebugColors::MissingTileBorderColor() {
  85. return {0.25f, 0.25f, 0.0f, 0.25f};
  86. }
  87. int DebugColors::MissingTileBorderWidth(float device_scale_factor) {
  88. return Scale(1, device_scale_factor);
  89. }
  90. // Solid color tile borders are grey.
  91. SkColor4f DebugColors::SolidColorTileBorderColor() {
  92. return {0.5f, 0.5f, 0.5f, 0.5f};
  93. }
  94. int DebugColors::SolidColorTileBorderWidth(float device_scale_factor) {
  95. return Scale(1, device_scale_factor);
  96. }
  97. // OOM tile borders are red.
  98. SkColor4f DebugColors::OOMTileBorderColor() {
  99. return {1.0f, 0.0f, 0.0f, 100.0f / 255.0f};
  100. }
  101. int DebugColors::OOMTileBorderWidth(float device_scale_factor) {
  102. return Scale(1, device_scale_factor);
  103. }
  104. // Direct picture borders are chartreuse.
  105. SkColor4f DebugColors::DirectPictureBorderColor() {
  106. return {127.0f / 255.0f, 1.0f, 0.0f, 1.0f};
  107. }
  108. int DebugColors::DirectPictureBorderWidth(float device_scale_factor) {
  109. return Scale(1, device_scale_factor);
  110. }
  111. // Returns a color transform that shifts color toward red.
  112. base::span<const float>
  113. DebugColors::TintCompositedContentColorTransformMatrix() {
  114. // The new colors are:
  115. // new_R = R + 0.3 G + 0.3 B
  116. // new_G = 0.7 G
  117. // new_B = 0.7 B
  118. // clang-format off
  119. static constexpr float kColorTransform[] = {1.0f, 0.0f, 0.0f, 0.0f,
  120. 0.3f, 0.7f, 0.0f, 0.0f,
  121. 0.3f, 0.0f, 0.7f, 0.0f,
  122. 0.0f, 0.0f, 0.0f, 1.0f};
  123. // clang-format on
  124. return base::span<const float>(kColorTransform, sizeof(kColorTransform));
  125. }
  126. // Compressed tile borders are blue.
  127. SkColor4f DebugColors::CompressedTileBorderColor() {
  128. return {20.0f / 255.0f, 20.0f / 255.0f, 240.0f / 255.0f, 100.0f / 255.0f};
  129. }
  130. int DebugColors::CompressedTileBorderWidth(float device_scale_factor) {
  131. return Scale(2, device_scale_factor);
  132. }
  133. // ======= Checkerboard colors =======
  134. // Non-debug checkerboards are grey.
  135. SkColor4f DebugColors::DefaultCheckerboardColor() {
  136. return {241.0f / 255.0f, 241.0f / 255.0f, 241.0f / 255.0f, 1.0f};
  137. }
  138. // Invalidated tiles get sky blue checkerboards.
  139. SkColor4f DebugColors::InvalidatedTileCheckerboardColor() {
  140. return {0.5f, 200.0f / 255.0f, 245.0f / 255.0f, 1.0f};
  141. }
  142. // Evicted tiles get pale red checkerboards.
  143. SkColor4f DebugColors::EvictedTileCheckerboardColor() {
  144. return {1.0f, 200.0f / 255.0f, 200.0f / 255.0f, 1.0f};
  145. }
  146. // ======= Debug rect colors =======
  147. static SkColor4f FadedGreen(int initial_value, int step) {
  148. DCHECK_GE(step, 0);
  149. DCHECK_LE(step, DebugColors::kFadeSteps);
  150. int value = step * initial_value / DebugColors::kFadeSteps;
  151. return {0.0f, 195.0f / 255.0f, 0.0f, static_cast<float>(value) / 255.0f};
  152. }
  153. // Paint rects in green.
  154. SkColor4f DebugColors::PaintRectBorderColor(int step) {
  155. return FadedGreen(255, step);
  156. }
  157. int DebugColors::PaintRectBorderWidth() { return 2; }
  158. SkColor4f DebugColors::PaintRectFillColor(int step) {
  159. return FadedGreen(60, step);
  160. }
  161. static SkColor4f FadedBlue(int initial_value, int step) {
  162. DCHECK_GE(step, 0);
  163. DCHECK_LE(step, DebugColors::kFadeSteps);
  164. int value = step * initial_value / DebugColors::kFadeSteps;
  165. return {0.0f, 0.0f, 1.0f, static_cast<float>(value) / 255.0f};
  166. }
  167. /// Layout Shift rects in blue.
  168. SkColor4f DebugColors::LayoutShiftRectBorderColor() {
  169. return {0.0f, 0.0f, 1.0f, 0.0f};
  170. }
  171. int DebugColors::LayoutShiftRectBorderWidth() {
  172. // We don't want any border showing for the layout shift debug rects so we set
  173. // the border width to be equal to 0.
  174. return 0;
  175. }
  176. SkColor4f DebugColors::LayoutShiftRectFillColor(int step) {
  177. return FadedBlue(60, step);
  178. }
  179. // Property-changed rects in blue.
  180. SkColor4f DebugColors::PropertyChangedRectBorderColor() {
  181. return {0.0f, 0.0f, 1.0f, 1.0f};
  182. }
  183. int DebugColors::PropertyChangedRectBorderWidth() { return 2; }
  184. SkColor4f DebugColors::PropertyChangedRectFillColor() {
  185. return {0.0f, 0.0f, 1.0f, 30.0f / 255.0f};
  186. }
  187. // Surface damage rects in yellow-orange.
  188. SkColor4f DebugColors::SurfaceDamageRectBorderColor() {
  189. return {200.0f / 255.0f, 100.0f / 255.0f, 0.0f, 1.0f};
  190. }
  191. int DebugColors::SurfaceDamageRectBorderWidth() { return 2; }
  192. SkColor4f DebugColors::SurfaceDamageRectFillColor() {
  193. return {200.0f / 255.0f, 100.0f / 255.0f, 0.0f, 30.0f / 255.0f};
  194. }
  195. // Surface screen space rects in yellow-green.
  196. SkColor4f DebugColors::ScreenSpaceLayerRectBorderColor() {
  197. return {100.0f / 255.0f, 200.0f / 255.0f, 0.0f, 1.0f};
  198. }
  199. int DebugColors::ScreenSpaceLayerRectBorderWidth() { return 2; }
  200. SkColor4f DebugColors::ScreenSpaceLayerRectFillColor() {
  201. return {100.0f / 255.0f, 200.0f / 255.0f, 0.0f, 30.0f / 255.0f};
  202. }
  203. // Touch-event-handler rects in yellow.
  204. SkColor4f DebugColors::TouchEventHandlerRectBorderColor() {
  205. return {239.0f / 255.0f, 229.0f / 255.0f, 60.0f / 255.0f, 1.0f};
  206. }
  207. int DebugColors::TouchEventHandlerRectBorderWidth() { return 2; }
  208. SkColor4f DebugColors::TouchEventHandlerRectFillColor() {
  209. return {239.0f / 255.0f, 229.0f / 255.0f, 60.0f / 255.0f, 30.0f / 255.0f};
  210. }
  211. // Wheel-event-handler rects in green.
  212. SkColor4f DebugColors::WheelEventHandlerRectBorderColor() {
  213. return {189.0f / 255.0f, 209.0f / 255.0f, 57.0f / 255.0f, 1.0f};
  214. }
  215. int DebugColors::WheelEventHandlerRectBorderWidth() { return 2; }
  216. SkColor4f DebugColors::WheelEventHandlerRectFillColor() {
  217. return {189.0f / 255.0f, 209.0f / 255.0f, 57.0f / 255.0f, 30.0f / 255.0f};
  218. }
  219. // Scroll-event-handler rects in teal.
  220. SkColor4f DebugColors::ScrollEventHandlerRectBorderColor() {
  221. return {24.0f / 255.0f, 167.0f / 255.0f, 181.0f / 255.0f, 1.0f};
  222. }
  223. int DebugColors::ScrollEventHandlerRectBorderWidth() { return 2; }
  224. SkColor4f DebugColors::ScrollEventHandlerRectFillColor() {
  225. return {24.0f / 255.0f, 167.0f / 255.0f, 181.0f / 255.0f, 30.0f / 255.0f};
  226. }
  227. // Non-fast-scrollable rects in orange.
  228. SkColor4f DebugColors::NonFastScrollableRectBorderColor() {
  229. return {238.0f / 255.0f, 163.0f / 255.0f, 59.0f / 255.0f, 1.0f};
  230. }
  231. int DebugColors::NonFastScrollableRectBorderWidth() { return 2; }
  232. SkColor4f DebugColors::NonFastScrollableRectFillColor() {
  233. return {238.0f / 255.0f, 163.0f / 255.0f, 59.0f / 255.0f, 30.0f / 255.0f};
  234. }
  235. // Main-thread scrolling reason rects in yellow-orange.
  236. SkColor4f DebugColors::MainThreadScrollingReasonRectBorderColor() {
  237. return {200.0f / 255.0f, 100.0f / 255.0f, 0.0f, 1.0f};
  238. }
  239. int DebugColors::MainThreadScrollingReasonRectBorderWidth() {
  240. return 2;
  241. }
  242. SkColor4f DebugColors::MainThreadScrollingReasonRectFillColor() {
  243. return {200.0f / 255.0f, 100.0f / 255.0f, 0.0f, 30.0f / 255.0f};
  244. }
  245. // Animation bounds are lime-green.
  246. SkColor4f DebugColors::LayerAnimationBoundsBorderColor() {
  247. return {112.0f / 255.0f, 229.0f / 255.0f, 0.0f, 1.0f};
  248. }
  249. int DebugColors::LayerAnimationBoundsBorderWidth() { return 2; }
  250. SkColor4f DebugColors::LayerAnimationBoundsFillColor() {
  251. return {112.0f / 255.0f, 229.0f / 255.0f, 0.0f, 30.0f / 255.0f};
  252. }
  253. // Picture borders in transparent blue.
  254. SkColor4f DebugColors::PictureBorderColor() {
  255. return {0.0f, 0.0f, 200.0f / 255.0f, 100.0f / 255.0f};
  256. }
  257. // ======= HUD widget colors =======
  258. SkColor4f DebugColors::HUDBackgroundColor() {
  259. return {0.0f, 0.0f, 0.0f, 217.0f / 255.0f};
  260. }
  261. SkColor4f DebugColors::HUDSeparatorLineColor() {
  262. return {0.0f, 1.0f, 0.0f, 0.25f};
  263. }
  264. SkColor4f DebugColors::HUDIndicatorLineColor() {
  265. return SkColors::kYellow;
  266. }
  267. SkColor4f DebugColors::HUDTitleColor() {
  268. return {232.0f / 255.0f, 232.0f / 255.0f, 232.0f / 255.0f, 1.0f};
  269. }
  270. SkColor4f DebugColors::PlatformLayerTreeTextColor() {
  271. return SkColors::kRed;
  272. }
  273. SkColor4f DebugColors::FPSDisplayTextAndGraphColor() {
  274. return SkColors::kGreen;
  275. }
  276. // Color used to represent dropped compositor frames.
  277. SkColor4f DebugColors::FPSDisplayDroppedFrame() {
  278. return {202.0f / 255.0f, 91.0f / 255.0f, 29.0f / 255.0f, 1.0f};
  279. }
  280. // Color used to represent a "partial" frame, i.e. a frame that missed
  281. // its commit deadline.
  282. SkColor4f DebugColors::FPSDisplayMissedFrame() {
  283. return {1.0f, 245.0f / 255.0f, 0.0f, 1.0f};
  284. }
  285. // Color used to represent a frame that successfully rendered.
  286. SkColor4f DebugColors::FPSDisplaySuccessfulFrame() {
  287. return {174.0f / 255.0f, 221.0f / 255.0f, 1.0f, 191.0f / 255.0f};
  288. }
  289. SkColor4f DebugColors::MemoryDisplayTextColor() {
  290. return SkColors::kCyan;
  291. }
  292. // Paint time display in green (similar to paint times in the WebInspector)
  293. SkColor4f DebugColors::PaintTimeDisplayTextAndGraphColor() {
  294. return {75.0f / 255.0f, 155.0f / 255.0f, 55.0f / 255.0f, 1.0f};
  295. }
  296. SkColor4f DebugColors::NonLCDTextHighlightColor(
  297. LCDTextDisallowedReason reason) {
  298. switch (reason) {
  299. case LCDTextDisallowedReason::kNone:
  300. case LCDTextDisallowedReason::kNoText:
  301. return SkColors::kTransparent;
  302. case LCDTextDisallowedReason::kSetting:
  303. return {0.5f, 1.0f, 0.0f, 96.0f / 255.0f};
  304. case LCDTextDisallowedReason::kBackgroundColorNotOpaque:
  305. return {0.5f, 0.5f, 0.0f, 96.0f / 255.0f};
  306. case LCDTextDisallowedReason::kContentsNotOpaque:
  307. return {1.0f, 0.0f, 0.0f, 96.0f / 255.0f};
  308. case LCDTextDisallowedReason::kNonIntegralTranslation:
  309. return {1.0f, 0.5f, 0.0f, 96.0f / 255.0f};
  310. case LCDTextDisallowedReason::kNonIntegralXOffset:
  311. case LCDTextDisallowedReason::kNonIntegralYOffset:
  312. return {1.0f, 0.0f, 0.5f, 96.0f / 255.0f};
  313. case LCDTextDisallowedReason::kWillChangeTransform:
  314. case LCDTextDisallowedReason::kTransformAnimation:
  315. return {0.5f, 0.0f, 1.0f, 96.0f / 255.0f};
  316. case LCDTextDisallowedReason::kPixelOrColorEffect:
  317. return {0.0f, 0.5f, 0.0f, 96.0f / 255.0f};
  318. }
  319. NOTREACHED();
  320. return SkColors::kTransparent;
  321. }
  322. } // namespace cc