Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: cc/input/main_thread_scrolling_reason.h

Issue 2773593005: Move logic of recording main thread scrolling reasons from cc to blink::ScrollManager (Closed)
Patch Set: Update recording logic Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
bokan 2017/04/06 14:25:24 Nit: the reason isn't added, it's reported.
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 // Returns true if the MainThreadScrollingReason is one of the follow
96 // reasons that prevented a scroller from being composited.
97 static bool NonCompositedScrollReasons(uint32_t reasons) {
98 uint32_t non_composited_reasons =
99 kHasOpacityAndLCDText | kHasTransformAndLCDText |
100 kBackgroundNotOpaqueInRectAndLCDText | kHasBorderRadius |
101 kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer |
102 kUnknownNonCompositedRegion;
103 return reasons &&
104 (non_composited_reasons == (reasons | non_composited_reasons));
105 }
106
87 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { 107 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) {
88 base::trace_event::TracedValue tracedValue; 108 base::trace_event::TracedValue tracedValue;
89 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); 109 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue);
90 std::string result_in_array_foramt = tracedValue.ToString(); 110 std::string result_in_array_foramt = tracedValue.ToString();
91 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. 111 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars.
92 std::string result = 112 std::string result =
93 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); 113 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36);
94 base::Erase(result, '\"'); 114 base::Erase(result, '\"');
95 return result; 115 return result;
96 } 116 }
(...skipping 27 matching lines...) Expand all
124 tracedValue->AppendString( 144 tracedValue->AppendString(
125 "Background is not opaque in rect and LCD text"); 145 "Background is not opaque in rect and LCD text");
126 } 146 }
127 if (reasons & MainThreadScrollingReason::kHasBorderRadius) 147 if (reasons & MainThreadScrollingReason::kHasBorderRadius)
128 tracedValue->AppendString("Has border radius"); 148 tracedValue->AppendString("Has border radius");
129 if (reasons & MainThreadScrollingReason::kHasClipRelatedProperty) 149 if (reasons & MainThreadScrollingReason::kHasClipRelatedProperty)
130 tracedValue->AppendString("Has clip related property"); 150 tracedValue->AppendString("Has clip related property");
131 if (reasons & MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer) 151 if (reasons & MainThreadScrollingReason::kHasBoxShadowFromNonRootLayer)
132 tracedValue->AppendString("Has box shadow from non-root layer"); 152 tracedValue->AppendString("Has box shadow from non-root layer");
133 153
154 // This reason is only used for reporting to UMA that we don't know why
155 // but we ended up on the main thread because of some non-composited
156 // scroller. It should never actually be stored/set on a ScrollableArea
157 // or GraphicsLayer therefore we don't need to trace it.
158 DCHECK(!(reasons & MainThreadScrollingReason::kUnknownNonCompositedRegion));
159
134 // Transient scrolling reasons. 160 // Transient scrolling reasons.
135 if (reasons & MainThreadScrollingReason::kNonFastScrollableRegion) 161 if (reasons & MainThreadScrollingReason::kNonFastScrollableRegion)
136 tracedValue->AppendString("Non fast scrollable region"); 162 tracedValue->AppendString("Non fast scrollable region");
137 if (reasons & MainThreadScrollingReason::kFailedHitTest) 163 if (reasons & MainThreadScrollingReason::kFailedHitTest)
138 tracedValue->AppendString("Failed hit test"); 164 tracedValue->AppendString("Failed hit test");
139 if (reasons & MainThreadScrollingReason::kNoScrollingLayer) 165 if (reasons & MainThreadScrollingReason::kNoScrollingLayer)
140 tracedValue->AppendString("No scrolling layer"); 166 tracedValue->AppendString("No scrolling layer");
141 if (reasons & MainThreadScrollingReason::kNotScrollable) 167 if (reasons & MainThreadScrollingReason::kNotScrollable)
142 tracedValue->AppendString("Not scrollable"); 168 tracedValue->AppendString("Not scrollable");
143 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) 169 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll)
144 tracedValue->AppendString("Continuing main thread scroll"); 170 tracedValue->AppendString("Continuing main thread scroll");
145 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) 171 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform)
146 tracedValue->AppendString("Non-invertible transform"); 172 tracedValue->AppendString("Non-invertible transform");
147 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) 173 if (reasons & MainThreadScrollingReason::kPageBasedScrolling)
148 tracedValue->AppendString("Page-based scrolling"); 174 tracedValue->AppendString("Page-based scrolling");
149 tracedValue->EndArray(); 175 tracedValue->EndArray();
150 } 176 }
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 }; 177 };
166 178
167 } // namespace cc 179 } // namespace cc
168 180
169 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ 181 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698