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, |
46 | 47 |
48 // Scrolling a composited element which is on top of a non-composited | |
49 // one will end up with main thread scrolling because we are scrolling a non | |
50 // fast scrollable region. If all scrollers from the composited element's | |
51 // containing block chain are composited, it must be because of an element | |
52 // not in the chain in which case the following reason is added. | |
53 kUnknownNonCompositedRegion = 1 << 22, | |
54 kNonCompositedReasonsLast = 22, | |
55 | |
47 // Transient scrolling reasons. These are computed for each scroll begin. | 56 // Transient scrolling reasons. These are computed for each scroll begin. |
48 kNonFastScrollableRegion = 1 << 5, | 57 kNonFastScrollableRegion = 1 << 5, |
49 kFailedHitTest = 1 << 7, | 58 kFailedHitTest = 1 << 7, |
50 kNoScrollingLayer = 1 << 8, | 59 kNoScrollingLayer = 1 << 8, |
51 kNotScrollable = 1 << 9, | 60 kNotScrollable = 1 << 9, |
52 kContinuingMainThreadScroll = 1 << 10, | 61 kContinuingMainThreadScroll = 1 << 10, |
53 kNonInvertibleTransform = 1 << 11, | 62 kNonInvertibleTransform = 1 << 11, |
54 kPageBasedScrolling = 1 << 12, | 63 kPageBasedScrolling = 1 << 12, |
55 | 64 |
56 // The maximum number of flags in this struct (excluding itself). | 65 // The maximum number of flags in this struct (excluding itself). |
57 // New flags should increment this number but it should never be decremented | 66 // 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 | 67 // because the values are used in UMA histograms. It should also be noted |
59 // that it excludes the kNotScrollingOnMain value. | 68 // that it excludes the kNotScrollingOnMain value. |
60 kMainThreadScrollingReasonCount = 22, | 69 kMainThreadScrollingReasonCount = 23, |
61 }; | 70 }; |
62 | 71 |
63 // Returns true if the given MainThreadScrollingReason can be set by the main | 72 // Returns true if the given MainThreadScrollingReason can be set by the main |
64 // thread. | 73 // thread. |
65 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { | 74 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { |
66 uint32_t reasons_set_by_main_thread = | 75 uint32_t reasons_set_by_main_thread = |
67 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | | 76 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | |
68 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | | 77 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | |
69 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | | 78 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | |
70 kCustomScrollbarScrolling | kHasOpacityAndLCDText | | 79 kCustomScrollbarScrolling; |
71 kHasTransformAndLCDText | kBackgroundNotOpaqueInRectAndLCDText | | |
72 kHasBorderRadius | kHasClipRelatedProperty | | |
73 kHasBoxShadowFromNonRootLayer; | |
74 return (reasons & reasons_set_by_main_thread) == reasons; | 80 return (reasons & reasons_set_by_main_thread) == reasons; |
75 } | 81 } |
76 | 82 |
77 // Returns true if the given MainThreadScrollingReason can be set by the | 83 // Returns true if the given MainThreadScrollingReason can be set by the |
78 // compositor. | 84 // compositor. |
79 static bool CompositorCanSetScrollReasons(uint32_t reasons) { | 85 static bool CompositorCanSetScrollReasons(uint32_t reasons) { |
80 uint32_t reasons_set_by_compositor = | 86 uint32_t reasons_set_by_compositor = |
81 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | | 87 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | |
82 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | | 88 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | |
83 kPageBasedScrolling; | 89 kPageBasedScrolling; |
84 return (reasons & reasons_set_by_compositor) == reasons; | 90 return (reasons & reasons_set_by_compositor) == reasons; |
85 } | 91 } |
86 | 92 |
93 // Usually a scroller won't be composited with the following reasons | |
94 // unless we force the promotion. e.g. Apply will-change:transform. | |
95 static bool NonCompositedScrollReasons(uint32_t reasons) { | |
96 uint32_t non_composited_reasons = | |
97 kHasOpacityAndLCDText | kHasTransformAndLCDText | | |
98 kBackgroundNotOpaqueInRectAndLCDText | kHasBorderRadius | | |
99 kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer | | |
100 kUnknownNonCompositedRegion; | |
101 return reasons && | |
102 (non_composited_reasons == (reasons | non_composited_reasons)); | |
103 } | |
104 | |
87 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { | 105 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { |
88 base::trace_event::TracedValue tracedValue; | 106 base::trace_event::TracedValue tracedValue; |
89 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); | 107 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); |
90 std::string result_in_array_foramt = tracedValue.ToString(); | 108 std::string result_in_array_foramt = tracedValue.ToString(); |
91 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. | 109 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. |
92 std::string result = | 110 std::string result = |
93 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); | 111 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); |
94 base::Erase(result, '\"'); | 112 base::Erase(result, '\"'); |
95 return result; | 113 return result; |
96 } | 114 } |
(...skipping 27 matching lines...) Expand all Loading... | |
124 tracedValue->AppendString( | 142 tracedValue->AppendString( |
125 "Background is not opaque in rect and LCD text"); | 143 "Background is not opaque in rect and LCD text"); |
126 } | 144 } |
127 if (reasons & MainThreadScrollingReason::kHasBorderRadius) | 145 if (reasons & MainThreadScrollingReason::kHasBorderRadius) |
128 tracedValue->AppendString("Has border radius"); | 146 tracedValue->AppendString("Has border radius"); |
129 if (reasons & MainThreadScrollingReason::kHasClipRelatedProperty) | 147 if (reasons & MainThreadScrollingReason::kHasClipRelatedProperty) |
130 tracedValue->AppendString("Has clip related property"); | 148 tracedValue->AppendString("Has clip related property"); |
131 if (reasons & MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer) | 149 if (reasons & MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer) |
132 tracedValue->AppendString("Has box shadow from non-root layer"); | 150 tracedValue->AppendString("Has box shadow from non-root layer"); |
133 | 151 |
152 DCHECK(!(reasons & MainThreadScrollingReason::kUnknownNonCompositedRegion)); | |
bokan
2017/04/04 18:14:26
Add a comment here as to why we don't have a strin
| |
153 | |
134 // Transient scrolling reasons. | 154 // Transient scrolling reasons. |
135 if (reasons & MainThreadScrollingReason::kNonFastScrollableRegion) | 155 if (reasons & MainThreadScrollingReason::kNonFastScrollableRegion) |
136 tracedValue->AppendString("Non fast scrollable region"); | 156 tracedValue->AppendString("Non fast scrollable region"); |
137 if (reasons & MainThreadScrollingReason::kFailedHitTest) | 157 if (reasons & MainThreadScrollingReason::kFailedHitTest) |
138 tracedValue->AppendString("Failed hit test"); | 158 tracedValue->AppendString("Failed hit test"); |
139 if (reasons & MainThreadScrollingReason::kNoScrollingLayer) | 159 if (reasons & MainThreadScrollingReason::kNoScrollingLayer) |
140 tracedValue->AppendString("No scrolling layer"); | 160 tracedValue->AppendString("No scrolling layer"); |
141 if (reasons & MainThreadScrollingReason::kNotScrollable) | 161 if (reasons & MainThreadScrollingReason::kNotScrollable) |
142 tracedValue->AppendString("Not scrollable"); | 162 tracedValue->AppendString("Not scrollable"); |
143 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) | 163 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) |
144 tracedValue->AppendString("Continuing main thread scroll"); | 164 tracedValue->AppendString("Continuing main thread scroll"); |
145 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) | 165 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) |
146 tracedValue->AppendString("Non-invertible transform"); | 166 tracedValue->AppendString("Non-invertible transform"); |
147 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) | 167 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) |
148 tracedValue->AppendString("Page-based scrolling"); | 168 tracedValue->AppendString("Page-based scrolling"); |
149 tracedValue->EndArray(); | 169 tracedValue->EndArray(); |
150 } | 170 } |
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 }; | 171 }; |
166 | 172 |
167 } // namespace cc | 173 } // namespace cc |
168 | 174 |
169 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ | 175 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ |
OLD | NEW |