OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ | 5 #ifndef CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ |
6 #define CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ | 6 #define CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // blink::ScrollAnimator is in the middle of running a scroll offset | 30 // blink::ScrollAnimator is in the middle of running a scroll offset |
31 // animation. Note that a scroll handled by the main thread can result in an | 31 // animation. Note that a scroll handled by the main thread can result in an |
32 // animation running on the main thread or on the compositor thread. | 32 // animation running on the main thread or on the compositor thread. |
33 kHandlingScrollFromMainThread = 1 << 13, | 33 kHandlingScrollFromMainThread = 1 << 13, |
34 kCustomScrollbarScrolling = 1 << 15, | 34 kCustomScrollbarScrolling = 1 << 15, |
35 | 35 |
36 // Style-related scrolling on main reasons. | 36 // Style-related scrolling on main reasons. |
37 // These *AndLCDText reasons are due to subpixel text rendering which can | 37 // These *AndLCDText reasons are due to subpixel text rendering which can |
38 // only be applied by blending glyphs with the background at a specific | 38 // only be applied by blending glyphs with the background at a specific |
39 // screen position; transparency and transforms break this. | 39 // screen position; transparency and transforms break this. |
| 40 kNonCompositedReasonsFirst = 16, |
40 kHasOpacityAndLCDText = 1 << 16, | 41 kHasOpacityAndLCDText = 1 << 16, |
41 kHasTransformAndLCDText = 1 << 17, | 42 kHasTransformAndLCDText = 1 << 17, |
42 kBackgroundNotOpaqueInRectAndLCDText = 1 << 18, | 43 kBackgroundNotOpaqueInRectAndLCDText = 1 << 18, |
43 kHasBorderRadius = 1 << 19, | 44 kHasBorderRadius = 1 << 19, |
44 kHasClipRelatedProperty = 1 << 20, | 45 kHasClipRelatedProperty = 1 << 20, |
45 kHasBoxShadowFromNonRootLayer = 1 << 21, | 46 kHasBoxShadowFromNonRootLayer = 1 << 21, |
| 47 kNonCompositedReasonsLast = 21, |
46 | 48 |
47 // Transient scrolling reasons. These are computed for each scroll begin. | 49 // Transient scrolling reasons. These are computed for each scroll begin. |
48 kNonFastScrollableRegion = 1 << 5, | 50 kNonFastScrollableRegion = 1 << 5, |
49 kFailedHitTest = 1 << 7, | 51 kFailedHitTest = 1 << 7, |
50 kNoScrollingLayer = 1 << 8, | 52 kNoScrollingLayer = 1 << 8, |
51 kNotScrollable = 1 << 9, | 53 kNotScrollable = 1 << 9, |
52 kContinuingMainThreadScroll = 1 << 10, | 54 kContinuingMainThreadScroll = 1 << 10, |
53 kNonInvertibleTransform = 1 << 11, | 55 kNonInvertibleTransform = 1 << 11, |
54 kPageBasedScrolling = 1 << 12, | 56 kPageBasedScrolling = 1 << 12, |
55 | 57 |
56 // The maximum number of flags in this struct (excluding itself). | 58 // The maximum number of flags in this struct (excluding itself). |
57 // New flags should increment this number but it should never be decremented | 59 // New flags should increment this number but it should never be decremented |
58 // because the values are used in UMA histograms. It should also be noted | 60 // because the values are used in UMA histograms. It should also be noted |
59 // that it excludes the kNotScrollingOnMain value. | 61 // that it excludes the kNotScrollingOnMain value. |
60 kMainThreadScrollingReasonCount = 22, | 62 kMainThreadScrollingReasonCount = 22, |
61 }; | 63 }; |
62 | 64 |
| 65 static const uint32_t kNonCompositedReasons = |
| 66 kHasOpacityAndLCDText | kHasTransformAndLCDText | |
| 67 kBackgroundNotOpaqueInRectAndLCDText | kHasBorderRadius | |
| 68 kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer; |
| 69 |
63 // Returns true if the given MainThreadScrollingReason can be set by the main | 70 // Returns true if the given MainThreadScrollingReason can be set by the main |
64 // thread. | 71 // thread. |
65 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { | 72 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { |
66 uint32_t reasons_set_by_main_thread = | 73 uint32_t reasons_set_by_main_thread = |
67 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | | 74 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | |
68 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | | 75 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | |
69 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | | 76 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | |
70 kCustomScrollbarScrolling | kHasOpacityAndLCDText | | 77 kCustomScrollbarScrolling; |
71 kHasTransformAndLCDText | kBackgroundNotOpaqueInRectAndLCDText | | |
72 kHasBorderRadius | kHasClipRelatedProperty | | |
73 kHasBoxShadowFromNonRootLayer; | |
74 return (reasons & reasons_set_by_main_thread) == reasons; | 78 return (reasons & reasons_set_by_main_thread) == reasons; |
75 } | 79 } |
76 | 80 |
77 // Returns true if the given MainThreadScrollingReason can be set by the | 81 // Returns true if the given MainThreadScrollingReason can be set by the |
78 // compositor. | 82 // compositor. |
79 static bool CompositorCanSetScrollReasons(uint32_t reasons) { | 83 static bool CompositorCanSetScrollReasons(uint32_t reasons) { |
80 uint32_t reasons_set_by_compositor = | 84 uint32_t reasons_set_by_compositor = |
81 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | | 85 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | |
82 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | | 86 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | |
83 kPageBasedScrolling; | 87 kPageBasedScrolling; |
84 return (reasons & reasons_set_by_compositor) == reasons; | 88 return (reasons & reasons_set_by_compositor) == reasons; |
85 } | 89 } |
86 | 90 |
| 91 // Returns true if there are any reasons that prevented the scroller |
| 92 // from being composited. |
| 93 static bool HasNonCompositedScrollReasons(uint32_t reasons) { |
| 94 return (reasons & kNonCompositedReasons) != 0; |
| 95 } |
| 96 |
87 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { | 97 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { |
88 base::trace_event::TracedValue tracedValue; | 98 base::trace_event::TracedValue tracedValue; |
89 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); | 99 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); |
90 std::string result_in_array_foramt = tracedValue.ToString(); | 100 std::string result_in_array_foramt = tracedValue.ToString(); |
91 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. | 101 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. |
92 std::string result = | 102 std::string result = |
93 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); | 103 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); |
94 base::Erase(result, '\"'); | 104 base::Erase(result, '\"'); |
95 return result; | 105 return result; |
96 } | 106 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (reasons & MainThreadScrollingReason::kNotScrollable) | 151 if (reasons & MainThreadScrollingReason::kNotScrollable) |
142 tracedValue->AppendString("Not scrollable"); | 152 tracedValue->AppendString("Not scrollable"); |
143 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) | 153 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) |
144 tracedValue->AppendString("Continuing main thread scroll"); | 154 tracedValue->AppendString("Continuing main thread scroll"); |
145 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) | 155 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) |
146 tracedValue->AppendString("Non-invertible transform"); | 156 tracedValue->AppendString("Non-invertible transform"); |
147 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) | 157 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) |
148 tracedValue->AppendString("Page-based scrolling"); | 158 tracedValue->AppendString("Page-based scrolling"); |
149 tracedValue->EndArray(); | 159 tracedValue->EndArray(); |
150 } | 160 } |
151 | |
152 // For a given reason, return its index in enum | |
153 static int getReasonIndex(uint32_t reason) { | |
154 // Multiple reasons provided | |
155 if (reason & (reason - 1)) | |
156 return -1; | |
157 | |
158 int index = -1; | |
159 while (reason > 0) { | |
160 reason = reason >> 1; | |
161 ++index; | |
162 } | |
163 return index; | |
164 } | |
165 }; | 161 }; |
166 | 162 |
167 } // namespace cc | 163 } // namespace cc |
168 | 164 |
169 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ | 165 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ |
OLD | NEW |