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

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: Split unit tests into smaller ones 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,
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
63 // Returns true if the given MainThreadScrollingReason can be set by the main 65 // Returns true if the given MainThreadScrollingReason can be set by the main
64 // thread. 66 // thread.
65 static bool MainThreadCanSetScrollReasons(uint32_t reasons) { 67 static bool MainThreadCanSetScrollReasons(uint32_t reasons) {
66 uint32_t reasons_set_by_main_thread = 68 uint32_t reasons_set_by_main_thread =
67 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects | 69 kNotScrollingOnMain | kHasBackgroundAttachmentFixedObjects |
68 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled | 70 kHasNonLayerViewportConstrainedObjects | kThreadedScrollingDisabled |
69 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread | 71 kScrollbarScrolling | kPageOverlay | kHandlingScrollFromMainThread |
70 kCustomScrollbarScrolling | kHasOpacityAndLCDText | 72 kCustomScrollbarScrolling;
71 kHasTransformAndLCDText | kBackgroundNotOpaqueInRectAndLCDText |
72 kHasBorderRadius | kHasClipRelatedProperty |
73 kHasBoxShadowFromNonRootLayer;
74 return (reasons & reasons_set_by_main_thread) == reasons; 73 return (reasons & reasons_set_by_main_thread) == reasons;
75 } 74 }
76 75
77 // Returns true if the given MainThreadScrollingReason can be set by the 76 // Returns true if the given MainThreadScrollingReason can be set by the
78 // compositor. 77 // compositor.
79 static bool CompositorCanSetScrollReasons(uint32_t reasons) { 78 static bool CompositorCanSetScrollReasons(uint32_t reasons) {
80 uint32_t reasons_set_by_compositor = 79 uint32_t reasons_set_by_compositor =
81 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer | 80 kNonFastScrollableRegion | kFailedHitTest | kNoScrollingLayer |
82 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform | 81 kNotScrollable | kContinuingMainThreadScroll | kNonInvertibleTransform |
83 kPageBasedScrolling; 82 kPageBasedScrolling;
84 return (reasons & reasons_set_by_compositor) == reasons; 83 return (reasons & reasons_set_by_compositor) == reasons;
85 } 84 }
86 85
86 // Returns true if we have any NonCompostedScrollReasons.
bokan 2017/04/07 21:05:56 Rename the function HasNonCompositedScrollReasons.
yigu 2017/04/10 20:39:04 Done.
87 static bool NonCompositedScrollReasons(uint32_t reasons) {
88 uint32_t non_composited_reasons =
89 kHasOpacityAndLCDText | kHasTransformAndLCDText |
90 kBackgroundNotOpaqueInRectAndLCDText | kHasBorderRadius |
91 kHasClipRelatedProperty | kHasBoxShadowFromNonRootLayer;
92 return (reasons & non_composited_reasons);
93 }
94
87 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) { 95 static std::string mainThreadScrollingReasonsAsText(uint32_t reasons) {
88 base::trace_event::TracedValue tracedValue; 96 base::trace_event::TracedValue tracedValue;
89 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue); 97 mainThreadScrollingReasonsAsTracedValue(reasons, &tracedValue);
90 std::string result_in_array_foramt = tracedValue.ToString(); 98 std::string result_in_array_foramt = tracedValue.ToString();
91 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars. 99 // Remove '{main_thread_scrolling_reasons:[', ']}', and any '"' chars.
92 std::string result = 100 std::string result =
93 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36); 101 result_in_array_foramt.substr(34, result_in_array_foramt.length() - 36);
94 base::Erase(result, '\"'); 102 base::Erase(result, '\"');
95 return result; 103 return result;
96 } 104 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (reasons & MainThreadScrollingReason::kNotScrollable) 149 if (reasons & MainThreadScrollingReason::kNotScrollable)
142 tracedValue->AppendString("Not scrollable"); 150 tracedValue->AppendString("Not scrollable");
143 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll) 151 if (reasons & MainThreadScrollingReason::kContinuingMainThreadScroll)
144 tracedValue->AppendString("Continuing main thread scroll"); 152 tracedValue->AppendString("Continuing main thread scroll");
145 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform) 153 if (reasons & MainThreadScrollingReason::kNonInvertibleTransform)
146 tracedValue->AppendString("Non-invertible transform"); 154 tracedValue->AppendString("Non-invertible transform");
147 if (reasons & MainThreadScrollingReason::kPageBasedScrolling) 155 if (reasons & MainThreadScrollingReason::kPageBasedScrolling)
148 tracedValue->AppendString("Page-based scrolling"); 156 tracedValue->AppendString("Page-based scrolling");
149 tracedValue->EndArray(); 157 tracedValue->EndArray();
150 } 158 }
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 }; 159 };
166 160
167 } // namespace cc 161 } // namespace cc
168 162
169 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_ 163 #endif // CC_INPUT_MAIN_THREAD_SCROLLING_REASON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698