Commit 197fd0a5 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

Replace AnimationMetricsReporter in ShelfView

ui::AnimationMetricsReporter is deprecating. Replace it with
ui::AnimationThroughputReporter for simple layer animations and
ui::ThroughputTracker for complicated ones.

Bug: 11434673
Change-Id: I96425e7626929f9d6381828c81dbe08dd58168e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508793Reviewed-by: default avatarAndrew Xu <andrewxu@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822425}
parent 702bed57
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/metrics/user_metrics_recorder.h" #include "ash/metrics/user_metrics_recorder.h"
#include "ash/public/cpp/ash_constants.h" #include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/metrics_util.h"
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
...@@ -62,6 +63,7 @@ ...@@ -62,6 +63,7 @@
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/compositor/animation_metrics_reporter.h" #include "ui/compositor/animation_metrics_reporter.h"
#include "ui/compositor/animation_throughput_reporter.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h" #include "ui/compositor/layer_animator.h"
...@@ -113,12 +115,6 @@ constexpr char kShelfIconFadeInAnimationHistogram[] = ...@@ -113,12 +115,6 @@ constexpr char kShelfIconFadeInAnimationHistogram[] =
constexpr char kShelfIconFadeOutAnimationHistogram[] = constexpr char kShelfIconFadeOutAnimationHistogram[] =
"Ash.ShelfIcon.AnimationSmoothness.FadeOut"; "Ash.ShelfIcon.AnimationSmoothness.FadeOut";
enum class IconAnimationType {
kMoveAnimation,
kFadeInAnimation,
kFadeOutAnimation
};
// Helper to check if tablet mode is enabled. // Helper to check if tablet mode is enabled.
bool IsTabletModeEnabled() { bool IsTabletModeEnabled() {
return Shell::Get()->tablet_mode_controller() && return Shell::Get()->tablet_mode_controller() &&
...@@ -197,34 +193,20 @@ class ShelfFocusSearch : public views::FocusSearch { ...@@ -197,34 +193,20 @@ class ShelfFocusSearch : public views::FocusSearch {
DISALLOW_COPY_AND_ASSIGN(ShelfFocusSearch); DISALLOW_COPY_AND_ASSIGN(ShelfFocusSearch);
}; };
class IconAnimationMetricsReporter : public ui::AnimationMetricsReporter { void ReportMoveAnimationSmoothness(int smoothness) {
public: base::UmaHistogramPercentageObsoleteDoNotUse(kShelfIconMoveAnimationHistogram,
explicit IconAnimationMetricsReporter(IconAnimationType type) : type_(type) {} smoothness);
IconAnimationMetricsReporter(const IconAnimationMetricsReporter&) = delete; }
IconAnimationMetricsReporter& operator=(const IconAnimationMetricsReporter&) =
delete;
~IconAnimationMetricsReporter() override = default;
private: void ReportFadeInAnimationSmoothness(int smoothness) {
void Report(int value) override {
switch (type_) {
case IconAnimationType::kMoveAnimation:
base::UmaHistogramPercentageObsoleteDoNotUse(
kShelfIconMoveAnimationHistogram, value);
break;
case IconAnimationType::kFadeInAnimation:
base::UmaHistogramPercentageObsoleteDoNotUse(
kShelfIconFadeInAnimationHistogram, value);
break;
case IconAnimationType::kFadeOutAnimation:
base::UmaHistogramPercentageObsoleteDoNotUse( base::UmaHistogramPercentageObsoleteDoNotUse(
kShelfIconFadeOutAnimationHistogram, value); kShelfIconFadeInAnimationHistogram, smoothness);
break; }
}
}
IconAnimationType type_ = IconAnimationType::kMoveAnimation; void ReportFadeOutAnimationSmoothness(int smoothness) {
}; base::UmaHistogramPercentageObsoleteDoNotUse(
kShelfIconFadeOutAnimationHistogram, smoothness);
}
// Returns the id of the display on which |view| is shown. // Returns the id of the display on which |view| is shown.
int64_t GetDisplayIdForView(const View* view) { int64_t GetDisplayIdForView(const View* view) {
...@@ -390,13 +372,6 @@ int ShelfView::GetSizeOfAppButtons(int count, int button_size) { ...@@ -390,13 +372,6 @@ int ShelfView::GetSizeOfAppButtons(int count, int button_size) {
} }
void ShelfView::Init() { void ShelfView::Init() {
move_animation_reporter_ = std::make_unique<IconAnimationMetricsReporter>(
IconAnimationType::kMoveAnimation);
fade_in_animation_reporter_ = std::make_unique<IconAnimationMetricsReporter>(
IconAnimationType::kFadeInAnimation);
fade_out_animation_reporter_ = std::make_unique<IconAnimationMetricsReporter>(
IconAnimationType::kFadeOutAnimation);
separator_ = new views::Separator(); separator_ = new views::Separator();
separator_->SetColor(AshColorProvider::Get()->GetContentLayerColor( separator_->SetColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparatorColor)); AshColorProvider::ContentLayerType::kSeparatorColor));
...@@ -1381,7 +1356,11 @@ void ShelfView::OnTabletModeChanged() { ...@@ -1381,7 +1356,11 @@ void ShelfView::OnTabletModeChanged() {
void ShelfView::AnimateToIdealBounds() { void ShelfView::AnimateToIdealBounds() {
CalculateIdealBounds(); CalculateIdealBounds();
bounds_animator_->SetAnimationMetricsReporter(move_animation_reporter_.get());
move_animation_tracker_.emplace(
GetWidget()->GetCompositor()->RequestNewThroughputTracker());
move_animation_tracker_->Start(metrics_util::ForSmoothness(
base::BindRepeating(&ReportMoveAnimationSmoothness)));
for (int i = 0; i < view_model_->view_size(); ++i) { for (int i = 0; i < view_model_->view_size(); ++i) {
View* view = view_model_->view_at(i); View* view = view_model_->view_at(i);
...@@ -1404,8 +1383,12 @@ void ShelfView::FadeIn(views::View* view) { ...@@ -1404,8 +1383,12 @@ void ShelfView::FadeIn(views::View* view) {
fade_in_animation_settings.SetPreemptionStrategy( fade_in_animation_settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
fade_in_animation_settings.AddObserver(fade_in_animation_delegate_.get()); fade_in_animation_settings.AddObserver(fade_in_animation_delegate_.get());
fade_in_animation_settings.SetAnimationMetricsReporter(
fade_in_animation_reporter_.get()); ui::AnimationThroughputReporter reporter(
fade_in_animation_settings.GetAnimator(),
metrics_util::ForSmoothness(
base::BindRepeating(&ReportFadeInAnimationSmoothness)));
view->layer()->SetOpacity(1.f); view->layer()->SetOpacity(1.f);
} }
...@@ -1808,6 +1791,9 @@ void ShelfView::OnFadeInAnimationEnded() { ...@@ -1808,6 +1791,9 @@ void ShelfView::OnFadeInAnimationEnded() {
} }
void ShelfView::OnFadeOutAnimationEnded() { void ShelfView::OnFadeOutAnimationEnded() {
fade_out_animation_tracker_->Stop();
fade_out_animation_tracker_.reset();
// Call PreferredSizeChanged() to notify container to re-layout at the end // Call PreferredSizeChanged() to notify container to re-layout at the end
// of removal animation. // of removal animation.
PreferredSizeChanged(); PreferredSizeChanged();
...@@ -2023,10 +2009,13 @@ void ShelfView::ShelfItemRemoved(int model_index, const ShelfItem& old_item) { ...@@ -2023,10 +2009,13 @@ void ShelfView::ShelfItemRemoved(int model_index, const ShelfItem& old_item) {
if (view->GetVisible() && view->layer()->opacity() > 0.0f) { if (view->GetVisible() && view->layer()->opacity() > 0.0f) {
UpdateShelfItemViewsVisibility(); UpdateShelfItemViewsVisibility();
fade_out_animation_tracker_.emplace(
GetWidget()->GetCompositor()->RequestNewThroughputTracker());
fade_out_animation_tracker_->Start(metrics_util::ForSmoothness(
base::BindRepeating(&ReportFadeOutAnimationSmoothness)));
// The first animation fades out the view. When done we'll animate the rest // The first animation fades out the view. When done we'll animate the rest
// of the views to their target location. // of the views to their target location.
bounds_animator_->SetAnimationMetricsReporter(
fade_out_animation_reporter_.get());
bounds_animator_->AnimateViewTo(view.get(), view->bounds()); bounds_animator_->AnimateViewTo(view.get(), view->bounds());
bounds_animator_->SetAnimationDelegate( bounds_animator_->SetAnimationDelegate(
view.get(), std::unique_ptr<gfx::AnimationDelegate>( view.get(), std::unique_ptr<gfx::AnimationDelegate>(
...@@ -2339,6 +2328,11 @@ void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { ...@@ -2339,6 +2328,11 @@ void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) {
void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
shelf_->set_is_tablet_mode_animation_running(false); shelf_->set_is_tablet_mode_animation_running(false);
if (move_animation_tracker_) {
move_animation_tracker_->Stop();
move_animation_tracker_.reset();
}
if (snap_back_from_rip_off_view_ && animator == bounds_animator_.get()) { if (snap_back_from_rip_off_view_ && animator == bounds_animator_.get()) {
if (!animator->IsAnimating(snap_back_from_rip_off_view_)) { if (!animator->IsAnimating(snap_back_from_rip_off_view_)) {
// Coming here the animation of the ShelfAppButton is finished and the // Coming here the animation of the ShelfAppButton is finished and the
......
...@@ -24,8 +24,10 @@ ...@@ -24,8 +24,10 @@
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/compositor/throughput_tracker.h"
#include "ui/views/accessibility/view_accessibility.h" #include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/accessible_pane_view.h" #include "ui/views/accessible_pane_view.h"
#include "ui/views/animation/bounds_animator_observer.h" #include "ui/views/animation/bounds_animator_observer.h"
...@@ -694,14 +696,11 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -694,14 +696,11 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
std::unique_ptr<FadeInAnimationDelegate> fade_in_animation_delegate_; std::unique_ptr<FadeInAnimationDelegate> fade_in_animation_delegate_;
// The animation metrics reporter for icon move animation. // Tracks the icon move animation.
std::unique_ptr<ui::AnimationMetricsReporter> move_animation_reporter_; base::Optional<ui::ThroughputTracker> move_animation_tracker_;
// The animation metrics reporter for icon fade-in animation. // Tracks the icon fade-out animation.
std::unique_ptr<ui::AnimationMetricsReporter> fade_in_animation_reporter_; base::Optional<ui::ThroughputTracker> fade_out_animation_tracker_;
// The animation metrics reporter for icon fade-out animation.
std::unique_ptr<ui::AnimationMetricsReporter> fade_out_animation_reporter_;
// Called when showing shelf context menu. // Called when showing shelf context menu.
base::RepeatingClosure context_menu_shown_callback_; base::RepeatingClosure context_menu_shown_callback_;
......
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