| 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, | |
| 41 kHasOpacityAndLCDText = 1 << 16, | 40 kHasOpacityAndLCDText = 1 << 16, |
| 42 kHasTransformAndLCDText = 1 << 17, | 41 kHasTransformAndLCDText = 1 << 17, |
| 43 kBackgroundNotOpaqueInRectAndLCDText = 1 << 18, | 42 kBackgroundNotOpaqueInRectAndLCDText = 1 << 18, |
| 44 kHasBorderRadius = 1 << 19, | 43 kHasBorderRadius = 1 << 19, |
| 45 kHasClipRelatedProperty = 1 << 20, | 44 kHasClipRelatedProperty = 1 << 20, |
| 46 kHasBoxShadowFromNonRootLayer = 1 << 21, | 45 kHasBoxShadowFromNonRootLayer = 1 << 21, |
| 47 kNonCompositedReasonsLast = 21, | |
| 48 | 46 |
| 49 // Transient scrolling reasons. These are computed for each scroll begin. | 47 // Transient scrolling reasons. These are computed for each scroll begin. |
| 50 kNonFastScrollableRegion = 1 << 5, | 48 kNonFastScrollableRegion = 1 << 5, |
| 51 kFailedHitTest = 1 << 7, | 49 kFailedHitTest = 1 << 7, |
| 52 kNoScrollingLayer = 1 << 8, | 50 kNoScrollingLayer = 1 << 8, |
| 53 kNotScrollable = 1 << 9, | 51 kNotScrollable = 1 << 9, |
| 54 kContinuingMainThreadScroll = 1 << 10, | 52 kContinuingMainThreadScroll = 1 << 10, |
| 55 kNonInvertibleTransform = 1 << 11, | 53 kNonInvertibleTransform = 1 << 11, |
| 56 kPageBasedScrolling = 1 << 12, | 54 kPageBasedScrolling = 1 << 12, |
| 57 | 55 |
| 58 // The maximum number of flags in this struct (excluding itself). | 56 // The maximum number of flags in this struct (excluding itself). |
| 59 // New flags should increment this number but it should never be decremented | 57 // New flags should increment this number but it should never be decremented |
| 60 // because the values are used in UMA histograms. It should also be noted | 58 // because the values are used in UMA histograms. It should also be noted |
| 61 // that it excludes the kNotScrollingOnMain value. | 59 // that it excludes the kNotScrollingOnMain value. |
| 62 kMainThreadScrollingReasonCount = 22, | 60 kMainThreadScrollingReasonCount = 22, |
| 63 }; | 61 }; |
| 64 | 62 |
| 65 static const uint32_t kNonCompositedReasons = | |
| 66 kHasOpacityAndLCDText | kHasTransformAndLCDText | | |
| 67 kBackgroundNotOpaqueInRectAndLCDText | kHasBorderRadius | | |
| 68 kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer; | |
| 69 | |
| 70 // Returns true if the given MainThreadScrollingReason can be set by the main | 63 // Returns true if the given MainThreadScrollingReason can be set by the main |
| 71 // thread. | 64 // thread. |
| 72 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { | 65 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { |
| 73 uint32_t reasons_set_by_main_thread = | 66 uint32_t reasons_set_by_main_thread = |
| 74 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | | 67 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | |
| 75 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | | 68 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | |
| 76 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | | 69 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | |
| 77 kCustomScrollbarScrolling; | 70 kCustomScrollbarScrolling | kHasOpacityAndLCDText | |
| 71 kHasTransformAndLCDText | kBackgroundNotOpaqueInRectAndLCDText | |
| 72 kHasBorderRadius | kHasClipRelatedProperty | |
| 73 kHasBoxShadowFromNonRootLayer; |
| 78 return (reasons & reasons_set_by_main_thread) == reasons; | 74 return (reasons & reasons_set_by_main_thread) == reasons; |
| 79 } | 75 } |
| 80 | 76 |
| 81 // Returns true if the given MainThreadScrollingReason can be set by the | 77 // Returns true if the given MainThreadScrollingReason can be set by the |
| 82 // compositor. | 78 // compositor. |
| 83 static bool CompositorCanSetScrollReasons(uint32_t reasons) { | 79 static bool CompositorCanSetScrollReasons(uint32_t reasons) { |
| 84 uint32_t reasons_set_by_compositor = | 80 uint32_t reasons_set_by_compositor = |
| 85 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | | 81 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | |
| 86 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | | 82 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | |
| 87 kPageBasedScrolling; | 83 kPageBasedScrolling; |
| 88 return (reasons & reasons_set_by_compositor) == reasons; | 84 return (reasons & reasons_set_by_compositor) == reasons; |
| 89 } | 85 } |
| 90 | 86 |
| 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 | |
| 97 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { | 87 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { |
| 98 base::trace_event::TracedValue tracedValue; | 88 base::trace_event::TracedValue tracedValue; |
| 99 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); | 89 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); |
| 100 std::string result_in_array_foramt = tracedValue.ToString(); | 90 std::string result_in_array_foramt = tracedValue.ToString(); |
| 101 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. | 91 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. |
| 102 std::string result = | 92 std::string result = |
| 103 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); | 93 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); |
| 104 base::Erase(result, '\"'); | 94 base::Erase(result, '\"'); |
| 105 return result; | 95 return result; |
| 106 } | 96 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (reasons & MainThreadScrollingReason::kNotScrollable) | 141 if (reasons & MainThreadScrollingReason::kNotScrollable) |
| 152 tracedValue->AppendString("Not scrollable"); | 142 tracedValue->AppendString("Not scrollable"); |
| 153 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) | 143 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) |
| 154 tracedValue->AppendString("Continuing main thread scroll"); | 144 tracedValue->AppendString("Continuing main thread scroll"); |
| 155 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) | 145 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) |
| 156 tracedValue->AppendString("Non-invertible transform"); | 146 tracedValue->AppendString("Non-invertible transform"); |
| 157 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) | 147 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) |
| 158 tracedValue->AppendString("Page-based scrolling"); | 148 tracedValue->AppendString("Page-based scrolling"); |
| 159 tracedValue->EndArray(); | 149 tracedValue->EndArray(); |
| 160 } | 150 } |
| 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 } |
| 161 }; | 165 }; |
| 162 | 166 |
| 163 } // namespace cc | 167 } // namespace cc |
| 164 | 168 |
| 165 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ | 169 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ |
| OLD | NEW |