Skip to content

Commit

Permalink
Adds UMA for screen rotation animation smoothness.
Browse files Browse the repository at this point in the history
Adding histgram of screen rotation animation smoothness.

BUG=678763
TEST=manual, created histogram locally.

Review-Url: https://codereview.chromium.org/2771713004
Cr-Commit-Position: refs/heads/master@{#459635}
  • Loading branch information
wutao authored and Commit bot committed Mar 25, 2017
1 parent 7844edf commit 3f08f81
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
44 changes: 32 additions & 12 deletions ash/rotator/screen_rotation_animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_element.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/layer_animator.h"
Expand Down Expand Up @@ -143,15 +145,15 @@ LayerCleanupObserver::~LayerCleanupObserver() {
void LayerCleanupObserver::OnLayerAnimationEnded(
ui::LayerAnimationSequence* sequence) {
if (animator_)
animator_->OnLayerAnimationEnded();
animator_->ProcessAnimationQueue();

delete this;
}

void LayerCleanupObserver::OnLayerAnimationAborted(
ui::LayerAnimationSequence* sequence) {
if (animator_)
animator_->OnLayerAnimationAborted();
animator_->ProcessAnimationQueue();

delete this;
}
Expand All @@ -167,6 +169,20 @@ void LayerCleanupObserver::OnDetachedFromSequence(
sequence_ = nullptr;
}

class ScreenRotationAnimationMetricsReporter
: public ui::AnimationMetricsReporter {
public:
ScreenRotationAnimationMetricsReporter() {}
~ScreenRotationAnimationMetricsReporter() override {}

void Report(int value) override {
UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSmoothness", value);
}

private:
DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationMetricsReporter);
};

} // namespace

struct ScreenRotationAnimator::ScreenRotationRequest {
Expand All @@ -180,10 +196,22 @@ struct ScreenRotationAnimator::ScreenRotationRequest {
ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
: display_id_(display_id),
is_rotating_(false),
metrics_reporter_(
base::MakeUnique<ScreenRotationAnimationMetricsReporter>()),
disable_animation_timers_for_test_(false),
weak_factory_(this) {}

ScreenRotationAnimator::~ScreenRotationAnimator() {}
ScreenRotationAnimator::~ScreenRotationAnimator() {
// To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from
// calling a method on the |animator_|.
weak_factory_.InvalidateWeakPtrs();

// Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in
// order to make sure |metrics_reporter_| outlives the attached animation
// sequence.
old_layer_tree_owner_.reset();
metrics_reporter_.reset();
}

void ScreenRotationAnimator::AnimateRotation(
std::unique_ptr<ScreenRotationRequest> rotation_request) {
Expand Down Expand Up @@ -278,6 +306,7 @@ void ScreenRotationAnimator::AnimateRotation(
// control the animation.
if (disable_animation_timers_for_test_)
animator->set_disable_timer_for_test(true);
animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get());
animator->StartAnimation(animation_sequence.release());

rotation_request.reset();
Expand Down Expand Up @@ -313,15 +342,6 @@ void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver(
screen_rotation_animator_observers_.RemoveObserver(observer);
}

void ScreenRotationAnimator::OnLayerAnimationEnded() {
ProcessAnimationQueue();
}

void ScreenRotationAnimator::OnLayerAnimationAborted() {
AbortAnimations(old_layer_tree_owner_->root());
ProcessAnimationQueue();
}

void ScreenRotationAnimator::ProcessAnimationQueue() {
is_rotating_ = false;
old_layer_tree_owner_.reset();
Expand Down
14 changes: 6 additions & 8 deletions ash/rotator/screen_rotation_animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ui/display/display.h"

namespace ui {
class AnimationMetricsReporter;
class Layer;
class LayerTreeOwner;
} // namespace ui
Expand Down Expand Up @@ -49,9 +50,10 @@ class ASH_EXPORT ScreenRotationAnimator {
void RemoveScreenRotationAnimatorObserver(
ScreenRotationAnimatorObserver* observer);

void OnLayerAnimationEnded();

void OnLayerAnimationAborted();
// When screen rotation animation is ended or aborted, calls |Rotate()| with
// the pending rotation request if the request queue is not empty. Otherwise
// notifies |screen_rotation_animator_observer_|.
void ProcessAnimationQueue();

private:
friend class ash::test::ScreenRotationAnimatorTestApi;
Expand All @@ -64,18 +66,14 @@ class ASH_EXPORT ScreenRotationAnimator {
// |rotation_degrees| arc.
void AnimateRotation(std::unique_ptr<ScreenRotationRequest> rotation_request);

// When screen rotation animation is ended or aborted, if the request queue is
// not empty, it will call |Rotate()| with the pending rotation request.
// Otherwise it will notify |screen_rotation_animator_observer_|.
void ProcessAnimationQueue();

void set_disable_animation_timers_for_test(bool disable_timers);

void StopAnimating();

// The id of the display to rotate.
int64_t display_id_;
bool is_rotating_;
std::unique_ptr<ui::AnimationMetricsReporter> metrics_reporter_;
// Only set in unittest to disable animation timers.
bool disable_animation_timers_for_test_;
base::ObserverList<ScreenRotationAnimatorObserver>
Expand Down
10 changes: 10 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,16 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Ash.Rotation.AnimationSmoothness" units="%">
<owner>wutao@chromium.org</owner>
<summary>
Relative smoothness of animations when rotating screen. 100% represents
ideally smooth 60 frames per second. 50% represents only 30 frames per
second is achieved during the animations. 0% should not happen. This metric
is recorded exactly once when the user rotates the screen.
</summary>
</histogram>

<histogram name="Ash.Shelf.Menu.NumItemsEnabledUponSelection" units="Count">
<owner>bruthig@google.com</owner>
<owner>tdanderson@google.com</owner>
Expand Down

0 comments on commit 3f08f81

Please sign in to comment.