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