main_thread_scrolling_reason.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2016 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. #ifndef CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_
  5. #define CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_
  6. #include <memory>
  7. #include <string>
  8. #include "cc/cc_export.h"
  9. namespace base {
  10. namespace trace_event {
  11. class TracedValue;
  12. }
  13. } // namespace base
  14. namespace cc {
  15. // Ensure this stays in sync with the "MainThreadScrollingReason" enum in:
  16. // tools/metrics/histograms/enums.xml
  17. // When adding a new MainThreadScrollingReason, make sure the corresponding
  18. // [MainThread/Compositor]CanSetScrollReasons function is also updated.
  19. //
  20. // More info at: http://bit.ly/mtsr-details
  21. //
  22. struct CC_EXPORT MainThreadScrollingReason {
  23. enum : uint32_t {
  24. kNotScrollingOnMain = 0,
  25. // This is used only to report the histogram of main thread scrolling for
  26. // any reason below. It's a histogram bucket index instead of a bit.
  27. kScrollingOnMainForAnyReason = 1,
  28. // This enum simultaneously defines actual bitmask values and indices into
  29. // the bitmask (which are the numbers after "1 << " below, used as the
  30. // histogram bucket indices), but value 0 and 1 are used as the histogram
  31. // bucket indices for kNotScrollingMain and kScrollingOnMainForAnyReason,
  32. // respectively, so the 0th bit and the 1st bit should never be used.
  33. // See also blink::RecordScrollReasonsMetric().
  34. // Non-transient scrolling reasons. These are set on the ScrollNode.
  35. kHasBackgroundAttachmentFixedObjects = 1 << 2,
  36. kThreadedScrollingDisabled = 1 << 3,
  37. kPopupNoThreadedInput = 1 << 4,
  38. // Style-related scrolling on main reasons. Subpixel (LCD) text rendering
  39. // requires blending glyphs with the background at a specific screen
  40. // position; transparency and transforms break this.
  41. // These are only reported by the main-thread scroll gesture event codepath.
  42. // After scroll unification, we report kNoScrollingLayer instead.
  43. kNotOpaqueForTextAndLCDText = 1 << 5,
  44. kCantPaintScrollingBackgroundAndLCDText = 1 << 6,
  45. // Transient scrolling reasons. These are computed for each scroll gesture.
  46. // When computed inside ScrollBegin, these prevent the InputHandler from
  47. // reporting a status with SCROLL_ON_IMPL_THREAD. In other cases, the
  48. // InputHandler is scrolling "on impl", but we report a transient main
  49. // thread scrolling reason to UMA when we determine that some other aspect
  50. // of handling the scroll has been (or will be) blocked on the main thread.
  51. kScrollbarScrolling = 1 << 7,
  52. kNonFastScrollableRegion = 1 << 8,
  53. kFailedHitTest = 1 << 9,
  54. kNoScrollingLayer = 1 << 10,
  55. kNotScrollable = 1 << 11,
  56. kNonInvertibleTransform = 1 << 12,
  57. kWheelEventHandlerRegion = 1 << 13,
  58. kTouchEventHandlerRegion = 1 << 14,
  59. // For blink::RecordScrollReasonsMetric() to know the number of used bits.
  60. kMainThreadScrollingReasonLast = 14,
  61. };
  62. static const uint32_t kNonCompositedReasons =
  63. kNotOpaqueForTextAndLCDText | kCantPaintScrollingBackgroundAndLCDText;
  64. // Returns true if the given MainThreadScrollingReason can be set by the main
  65. // thread.
  66. static bool MainThreadCanSetScrollReasons(uint32_t reasons) {
  67. constexpr uint32_t reasons_set_by_main_thread =
  68. kHasBackgroundAttachmentFixedObjects | kThreadedScrollingDisabled |
  69. kPopupNoThreadedInput;
  70. return (reasons & reasons_set_by_main_thread) == reasons;
  71. }
  72. // Returns true if the given MainThreadScrollingReason can be set by the
  73. // compositor.
  74. static bool CompositorCanSetScrollReasons(uint32_t reasons) {
  75. constexpr uint32_t reasons_set_by_compositor =
  76. kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer |
  77. kNotScrollable | kNonInvertibleTransform | kWheelEventHandlerRegion |
  78. kTouchEventHandlerRegion;
  79. return (reasons & reasons_set_by_compositor) == reasons;
  80. }
  81. // Returns true if there are any reasons that prevented the scroller
  82. // from being composited.
  83. static bool HasNonCompositedScrollReasons(uint32_t reasons) {
  84. return (reasons & kNonCompositedReasons) != 0;
  85. }
  86. static int BucketIndexForTesting(uint32_t reason);
  87. static std::string AsText(uint32_t reasons);
  88. static void AddToTracedValue(uint32_t reasons,
  89. base::trace_event::TracedValue&);
  90. };
  91. } // namespace cc
  92. #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_