Skip to content

Commit

Permalink
Add main-thread scrolling reasons to "Scrolling performance issues"
Browse files Browse the repository at this point in the history
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/+/1868660
Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: Stefan 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}
  • Loading branch information
progers authored and Commit Bot committed Oct 24, 2019
1 parent ed1477c commit 437e627
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 25 deletions.
11 changes: 11 additions & 0 deletions cc/debug/debug_colors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions cc/debug/debug_colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions cc/debug/layer_tree_debug_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
}

Expand All @@ -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 &&
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cc/debug/layer_tree_debug_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions cc/input/main_thread_scrolling_reason.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

Expand Down
40 changes: 20 additions & 20 deletions cc/input/main_thread_scrolling_reason_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
8 changes: 8 additions & 0 deletions cc/layers/heads_up_display_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions cc/trees/debug_rect_history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
17 changes: 12 additions & 5 deletions cc/trees/debug_rect_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,32 @@ 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,
};

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
Expand Down Expand Up @@ -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_;
};
Expand Down
1 change: 1 addition & 0 deletions content/renderer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 437e627

Please sign in to comment.