Skip to content

Commit

Permalink
Cros: Report metrics for the animation of traslucent background
Browse files Browse the repository at this point in the history
This animation happens during transition between hotseat states.

Bug: 1058609
Change-Id: Iff1f81625e6de2bf6dc6dcfee09225c4d16cc53e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088641
Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
Reviewed-by: Manu Cornet <manucornet@chromium.org>
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748806}
  • Loading branch information
Ana Salazar authored and Commit Bot committed Mar 10, 2020
1 parent f6a24e5 commit 64465df
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
70 changes: 63 additions & 7 deletions ash/shelf/hotseat_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,53 @@ class HotseatWindowTargeter : public aura::WindowTargeter {

} // namespace

// Records smoothness of animations for background of the hotseat widget.
class HotseatWidgetBackgroundAnimationMetricsReporter
: public HotseatTransitionAnimator::Observer,
public ui::AnimationMetricsReporter {
public:
explicit HotseatWidgetBackgroundAnimationMetricsReporter(HotseatState state)
: target_state_(state) {}

~HotseatWidgetBackgroundAnimationMetricsReporter() override = default;

void OnHotseatTransitionAnimationWillStart(HotseatState from_state,
HotseatState to_state) override {
target_state_ = to_state;
}

// ui::AnimationMetricsReporter:
void Report(int value) override {
switch (target_state_) {
case HotseatState::kShownClamshell:
case HotseatState::kShownHomeLauncher:
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatWidgetAnimation.TranslucentBackground."
"AnimationSmoothness.TransitionToShownHotseat",
value);
break;
case HotseatState::kExtended:
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatWidgetAnimation.TranslucentBackground."
"AnimationSmoothness.TransitionToExtendedHotseat",
value);
break;
case HotseatState::kHidden:
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatWidgetAnimation.TranslucentBackground."
"AnimationSmoothness.TransitionToHiddenHotseat",
value);
break;
default:
NOTREACHED();
}
}

private:
// The state to which the animation is transitioning.
HotseatState target_state_;
};

class HotseatWidget::DelegateView : public HotseatTransitionAnimator::Observer,
public views::WidgetDelegateView,
public OverviewObserver,
Expand All @@ -100,7 +147,8 @@ class HotseatWidget::DelegateView : public HotseatTransitionAnimator::Observer,

// Initializes the view.
void Init(ScrollableShelfView* scrollable_shelf_view,
ui::Layer* parent_layer);
ui::Layer* parent_layer,
ui::AnimationMetricsReporter* background_metrics_reporter);

// Updates the hotseat background.
void UpdateTranslucentBackground();
Expand Down Expand Up @@ -145,6 +193,8 @@ class HotseatWidget::DelegateView : public HotseatTransitionAnimator::Observer,
ScrollableShelfView* scrollable_shelf_view_ = nullptr; // unowned.
// Blur is disabled during animations to improve performance.
bool blur_lock_ = false;
// Owned by the Hotseat Widget.
ui::AnimationMetricsReporter* background_metrics_reporter_;

// The most recent color that the |translucent_background_| has been animated
// to.
Expand All @@ -156,8 +206,7 @@ class HotseatWidget::DelegateView : public HotseatTransitionAnimator::Observer,
HotseatWidget::DelegateView::~DelegateView() {
WallpaperControllerImpl* wallpaper_controller =
Shell::Get()->wallpaper_controller();
OverviewController* overview_controller =
Shell::Get()->overview_controller();
OverviewController* overview_controller = Shell::Get()->overview_controller();
if (wallpaper_controller)
wallpaper_controller->RemoveObserver(this);
if (overview_controller)
Expand All @@ -166,16 +215,16 @@ HotseatWidget::DelegateView::~DelegateView() {

void HotseatWidget::DelegateView::Init(
ScrollableShelfView* scrollable_shelf_view,
ui::Layer* parent_layer) {
ui::Layer* parent_layer,
ui::AnimationMetricsReporter* background_metrics_reporter) {
SetLayoutManager(std::make_unique<views::FillLayout>());

if (!chromeos::switches::ShouldShowScrollableShelf())
return;

WallpaperControllerImpl* wallpaper_controller =
Shell::Get()->wallpaper_controller();
OverviewController* overview_controller =
Shell::Get()->overview_controller();
OverviewController* overview_controller = Shell::Get()->overview_controller();
if (wallpaper_controller)
wallpaper_controller->AddObserver(this);
if (overview_controller)
Expand All @@ -185,6 +234,7 @@ void HotseatWidget::DelegateView::Init(
DCHECK(scrollable_shelf_view);
scrollable_shelf_view_ = scrollable_shelf_view;
UpdateTranslucentBackground();
background_metrics_reporter_ = background_metrics_reporter;
}

void HotseatWidget::DelegateView::UpdateTranslucentBackground() {
Expand Down Expand Up @@ -219,6 +269,8 @@ void HotseatWidget::DelegateView::SetTranslucentBackground(
animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
if (animate)
animation_setter.SetAnimationMetricsReporter(background_metrics_reporter_);

if (ShelfConfig::Get()->GetDefaultShelfColor() != target_color_) {
target_color_ = ShelfConfig::Get()->GetDefaultShelfColor();
Expand Down Expand Up @@ -335,7 +387,11 @@ void HotseatWidget::Initialize(aura::Window* container, Shelf* shelf) {
/*shelf_button_delegate=*/nullptr));
shelf_view_->Init();
}
delegate_view_->Init(scrollable_shelf_view(), GetLayer());
traslucent_background_metrics_reporter_ =
std::make_unique<HotseatWidgetBackgroundAnimationMetricsReporter>(
state());
delegate_view_->Init(scrollable_shelf_view(), GetLayer(),
traslucent_background_metrics_reporter_.get());
}

void HotseatWidget::OnHotseatTransitionAnimatorCreated(
Expand Down
6 changes: 6 additions & 0 deletions ash/shelf/hotseat_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ScrollableShelfView;
class Shelf;
class ShelfView;
class HotseatTransitionAnimator;
class HotseatWidgetBackgroundAnimationMetricsReporter;

// The hotseat widget is part of the shelf and hosts app shortcuts.
class ASH_EXPORT HotseatWidget : public ShelfComponent,
Expand Down Expand Up @@ -159,6 +160,11 @@ class ASH_EXPORT HotseatWidget : public ShelfComponent,
// during an animation.
std::unique_ptr<aura::ScopedWindowTargeter> hotseat_window_targeter_;

// Metrics reporter for animations of the traslucent background in the
// hotseat.
std::unique_ptr<HotseatWidgetBackgroundAnimationMetricsReporter>
traslucent_background_metrics_reporter_;

DISALLOW_COPY_AND_ASSIGN(HotseatWidget);
};

Expand Down
6 changes: 3 additions & 3 deletions ash/shelf/shelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ class HotseatWidgetAnimationMetricsReporter
case HotseatState::kShownClamshell:
case HotseatState::kShownHomeLauncher:
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatWidgetAnimation.AnimationSmoothness."
"Ash.HotseatWidgetAnimation.Widget.AnimationSmoothness."
"TransitionToShownHotseat",
value);
break;
case HotseatState::kExtended:
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatWidgetAnimation.AnimationSmoothness."
"Ash.HotseatWidgetAnimation.Widget.AnimationSmoothness."
"TransitionToExtendedHotseat",
value);
break;
case HotseatState::kHidden:
UMA_HISTOGRAM_PERCENTAGE(
"Ash.HotseatWidgetAnimation.AnimationSmoothness."
"Ash.HotseatWidgetAnimation.Widget.AnimationSmoothness."
"TransitionToHiddenHotseat",
value);
break;
Expand Down
17 changes: 14 additions & 3 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8799,13 +8799,16 @@ uploading your change for review.
<!-- Name completed by histogram suffixes
name="HotseatTransitionType" -->

<!-- Name completed by histogram suffixes
name="HotseatWidgetElement" -->

<owner>anasalazar@chromium.org</owner>
<owner>newcomer@chromium.org</owner>
<summary>
Tracks the animation smoothness for the bounds animation of the hotseat
widget during transitions of the hotseat to shown, extended, and hidden
hotseat states. Check Ash.HotseatTransition.AnimationSmoothness for
smoothness of the animating background.
widget's elements during transitions of the hotseat to shown, extended, and
hidden hotseat states. Check Ash.HotseatTransition.AnimationSmoothness for
smoothness of the shelf's animating background.
</summary>
</histogram>

Expand Down Expand Up @@ -186833,6 +186836,14 @@ regressions. -->
<affected-histogram name="Ash.NavigationWidget.AnimationSmoothness"/>
</histogram_suffixes>

<histogram_suffixes name="HotseatWidgetElement" separator="."
ordering="prefix,2">
<suffix name="TranslucentBackground"
label="Hotseat widget's translucent background"/>
<suffix name="Widget" label="Hotseat widget"/>
<affected-histogram name="Ash.HotseatWidgetAnimation.AnimationSmoothness"/>
</histogram_suffixes>

<histogram_suffixes name="HstsState" separator=".">
<suffix name="HSTSNotEnabled" label="The HSTS is not enabled."/>
<suffix name="WithHSTSEnabled" label="The HSTS is enabled."/>
Expand Down

0 comments on commit 64465df

Please sign in to comment.