Commit 437e6278 authored by Philip Rogers's avatar Philip Rogers Committed by Commit Bot

Add main-thread scrolling reasons to "Scrolling performance issues"

The inspector has a feature for "Scrolling performance issues" under the
bottom console's "Rendering" tab which shows reasons for non-fast
scrolling. This feature did not include main-thread scrolling reasons
such as background-attachment: fixed. This patch adds main-thread
scrolling reasons to the scrolling performance issues visualization.

Bug: 1015918
Change-Id: I46039b4fc8ba3400cab1c2633da31e427865ce3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868660Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Auto-Submit: Philip Rogers <pdr@chromium.org>
Commit-Queue: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709113}
parent ed1477cd
......@@ -276,6 +276,17 @@ SkColor DebugColors::NonFastScrollableRectFillColor() {
return SkColorSetARGB(30, 238, 163, 59);
}
// Main-thread scrolling reason rects in yellow-orange.
SkColor DebugColors::MainThreadScrollingReasonRectBorderColor() {
return SkColorSetARGB(255, 200, 100, 0);
}
int DebugColors::MainThreadScrollingReasonRectBorderWidth() {
return 2;
}
SkColor DebugColors::MainThreadScrollingReasonRectFillColor() {
return SkColorSetARGB(30, 200, 100, 0);
}
// Animation bounds are lime-green.
SkColor DebugColors::LayerAnimationBoundsBorderColor() {
return SkColorSetARGB(255, 112, 229, 0);
......
......@@ -104,6 +104,10 @@ class CC_DEBUG_EXPORT DebugColors {
static int NonFastScrollableRectBorderWidth();
static SkColor NonFastScrollableRectFillColor();
static SkColor MainThreadScrollingReasonRectBorderColor();
static int MainThreadScrollingReasonRectBorderWidth();
static SkColor MainThreadScrollingReasonRectFillColor();
static SkColor LayerAnimationBoundsBorderColor();
static int LayerAnimationBoundsBorderWidth();
static SkColor LayerAnimationBoundsFillColor();
......
......@@ -21,6 +21,7 @@ LayerTreeDebugState::LayerTreeDebugState()
show_wheel_event_handler_rects(false),
show_scroll_event_handler_rects(false),
show_non_fast_scrollable_rects(false),
show_main_thread_scrolling_reason_rects(false),
show_layer_animation_bounds_rects(false),
slow_down_raster_scale_factor(0),
rasterize_only_visible_content(false),
......@@ -50,6 +51,7 @@ bool LayerTreeDebugState::ShowHudRects() const {
show_surface_damage_rects || show_screen_space_rects ||
show_touch_event_handler_rects || show_wheel_event_handler_rects ||
show_scroll_event_handler_rects || show_non_fast_scrollable_rects ||
show_main_thread_scrolling_reason_rects ||
show_layer_animation_bounds_rects || show_layout_shift_regions;
}
......@@ -71,6 +73,8 @@ bool LayerTreeDebugState::Equal(const LayerTreeDebugState& a,
a.show_wheel_event_handler_rects == b.show_wheel_event_handler_rects &&
a.show_scroll_event_handler_rects == b.show_scroll_event_handler_rects &&
a.show_non_fast_scrollable_rects == b.show_non_fast_scrollable_rects &&
a.show_main_thread_scrolling_reason_rects ==
b.show_main_thread_scrolling_reason_rects &&
a.show_layer_animation_bounds_rects ==
b.show_layer_animation_bounds_rects &&
a.slow_down_raster_scale_factor == b.slow_down_raster_scale_factor &&
......@@ -96,6 +100,8 @@ LayerTreeDebugState LayerTreeDebugState::Unite(const LayerTreeDebugState& a,
r.show_wheel_event_handler_rects |= b.show_wheel_event_handler_rects;
r.show_scroll_event_handler_rects |= b.show_scroll_event_handler_rects;
r.show_non_fast_scrollable_rects |= b.show_non_fast_scrollable_rects;
r.show_main_thread_scrolling_reason_rects |=
b.show_main_thread_scrolling_reason_rects;
r.show_layer_animation_bounds_rects |= b.show_layer_animation_bounds_rects;
if (b.slow_down_raster_scale_factor)
......
......@@ -41,6 +41,7 @@ class CC_DEBUG_EXPORT LayerTreeDebugState {
bool show_wheel_event_handler_rects;
bool show_scroll_event_handler_rects;
bool show_non_fast_scrollable_rects;
bool show_main_thread_scrolling_reason_rects;
bool show_layer_animation_bounds_rects;
int slow_down_raster_scale_factor;
......
......@@ -5,6 +5,7 @@
#include "cc/input/main_thread_scrolling_reason.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/trace_event/traced_value.h"
namespace cc {
......@@ -19,6 +20,8 @@ std::string MainThreadScrollingReason::AsText(uint32_t reasons) {
result =
result.substr(array_start_pos + 1, array_end_pos - array_start_pos - 1);
base::Erase(result, '\"');
// Add spaces after all commas.
base::ReplaceChars(result, ",", ", ", &result);
return result;
}
......
......@@ -13,26 +13,26 @@ using MainThreadScrollingReasonTest = testing::Test;
TEST_F(MainThreadScrollingReasonTest, AsText) {
EXPECT_EQ("", MainThreadScrollingReason::AsText(0));
EXPECT_EQ(
"Has background-attachment:fixed,"
"Has non-layer viewport-constrained objects,"
"Threaded scrolling is disabled,"
"Scrollbar scrolling,"
"Frame overlay,"
"Handling scroll from main thread,"
"Has opacity and LCD text,"
"Has transform and LCD text,"
"Background is not opaque in rect and LCD text,"
"Has clip related property,"
"Has box shadow from non-root layer,"
"Is not stacking context and LCD text,"
"Non fast scrollable region,"
"Failed hit test,"
"No scrolling layer,"
"Not scrollable,"
"Continuing main thread scroll,"
"Non-invertible transform,"
"Page-based scrolling,"
"Wheel event handler region,"
"Has background-attachment:fixed, "
"Has non-layer viewport-constrained objects, "
"Threaded scrolling is disabled, "
"Scrollbar scrolling, "
"Frame overlay, "
"Handling scroll from main thread, "
"Has opacity and LCD text, "
"Has transform and LCD text, "
"Background is not opaque in rect and LCD text, "
"Has clip related property, "
"Has box shadow from non-root layer, "
"Is not stacking context and LCD text, "
"Non fast scrollable region, "
"Failed hit test, "
"No scrolling layer, "
"Not scrollable, "
"Continuing main thread scroll, "
"Non-invertible transform, "
"Page-based scrolling, "
"Wheel event handler region, "
"Touch event handler region",
MainThreadScrollingReason::AsText(0xffffffffu));
}
......
......@@ -1031,6 +1031,14 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects(
stroke_width = DebugColors::NonFastScrollableRectBorderWidth();
label_text = "repaints on scroll";
break;
case MAIN_THREAD_SCROLLING_REASON_RECT_TYPE:
stroke_color = DebugColors::MainThreadScrollingReasonRectBorderColor();
fill_color = DebugColors::MainThreadScrollingReasonRectFillColor();
stroke_width = DebugColors::MainThreadScrollingReasonRectBorderWidth();
label_text = "main thread scrolling: ";
label_text.append(base::ToLowerASCII(MainThreadScrollingReason::AsText(
debug_rects[i].main_thread_scrolling_reasons)));
break;
case ANIMATION_BOUNDS_RECT_TYPE:
stroke_color = DebugColors::LayerAnimationBoundsBorderColor();
fill_color = DebugColors::LayerAnimationBoundsFillColor();
......
......@@ -50,6 +50,9 @@ void DebugRectHistory::SaveDebugRectsForCurrentFrame(
if (debug_state.show_non_fast_scrollable_rects)
SaveNonFastScrollableRects(tree_impl);
if (debug_state.show_main_thread_scrolling_reason_rects)
SaveMainThreadScrollingReasonRects(tree_impl);
if (debug_state.show_layout_shift_regions)
SaveLayoutShiftRects(hud_layer);
......@@ -205,4 +208,23 @@ void DebugRectHistory::SaveNonFastScrollableRectsCallback(LayerImpl* layer) {
}
}
void DebugRectHistory::SaveMainThreadScrollingReasonRects(
LayerTreeImpl* tree_impl) {
const auto& scroll_tree = tree_impl->property_trees()->scroll_tree;
for (auto* layer : *tree_impl) {
if (layer->scrollable()) {
if (const auto* scroll_node =
scroll_tree.Node(layer->scroll_tree_index())) {
if (auto reasons = scroll_node->main_thread_scrolling_reasons) {
debug_rects_.push_back(DebugRect(
MAIN_THREAD_SCROLLING_REASON_RECT_TYPE,
MathUtil::MapEnclosingClippedRect(layer->ScreenSpaceTransform(),
gfx::Rect(layer->bounds())),
kTouchActionNone, reasons));
}
}
}
}
}
} // namespace cc
......@@ -46,6 +46,7 @@ enum DebugRectType {
WHEEL_EVENT_HANDLER_RECT_TYPE,
SCROLL_EVENT_HANDLER_RECT_TYPE,
NON_FAST_SCROLLABLE_RECT_TYPE,
MAIN_THREAD_SCROLLING_REASON_RECT_TYPE,
ANIMATION_BOUNDS_RECT_TYPE,
LAYOUT_SHIFT_RECT_TYPE,
};
......@@ -53,19 +54,24 @@ enum DebugRectType {
struct DebugRect {
DebugRect(DebugRectType new_type,
const gfx::Rect& new_rect,
TouchAction new_touch_action)
: type(new_type), rect(new_rect), touch_action(new_touch_action) {
TouchAction new_touch_action = kTouchActionNone,
uint32_t main_thread_scrolling_reasons = 0)
: type(new_type),
rect(new_rect),
touch_action(new_touch_action),
main_thread_scrolling_reasons(main_thread_scrolling_reasons) {
if (type != TOUCH_EVENT_HANDLER_RECT_TYPE)
DCHECK_EQ(touch_action, kTouchActionNone);
if (type != MAIN_THREAD_SCROLLING_REASON_RECT_TYPE)
DCHECK(!main_thread_scrolling_reasons);
}
DebugRect(DebugRectType new_type, const gfx::Rect& new_rect)
: DebugRect(new_type, new_rect, kTouchActionNone) {}
DebugRectType type;
gfx::Rect rect;
// Valid when |type| is |TOUCH_EVENT_HANDLER_RECT_TYPE|, otherwise default to
// |kTouchActionNone|.
TouchAction touch_action;
// Valid when |type| is |MAIN_THREAD_SCROLLING_REASON_RECT_TYPE|, otherwise 0.
uint32_t main_thread_scrolling_reasons;
};
// This class maintains a history of rects of various types that can be used
......@@ -105,6 +111,7 @@ class DebugRectHistory {
void SaveScrollEventHandlerRectsCallback(LayerImpl* layer);
void SaveNonFastScrollableRects(LayerTreeImpl* layer);
void SaveNonFastScrollableRectsCallback(LayerImpl* layer);
void SaveMainThreadScrollingReasonRects(LayerTreeImpl*);
std::vector<DebugRect> debug_rects_;
};
......
......@@ -1422,6 +1422,7 @@ void RenderWidget::SetShowScrollBottleneckRects(bool show) {
debug_state.show_touch_event_handler_rects = show;
debug_state.show_wheel_event_handler_rects = show;
debug_state.show_non_fast_scrollable_rects = show;
debug_state.show_main_thread_scrolling_reason_rects = show;
layer_tree_host_->SetDebugState(debug_state);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment