Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: ash/rotator/screen_rotation_animator.cc

Issue 2771713004: Adds UMA for screen rotation animation smoothness. (Closed)
Patch Set: Merged and Moves the ScreenRotationAnimationMetricsReporter to .cc. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/rotator/screen_rotation_animator.h" 5 #include "ash/rotator/screen_rotation_animator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/display/window_tree_host_manager.h" 11 #include "ash/display/window_tree_host_manager.h"
12 #include "ash/rotator/screen_rotation_animation.h" 12 #include "ash/rotator/screen_rotation_animation.h"
13 #include "ash/rotator/screen_rotation_animator_observer.h" 13 #include "ash/rotator/screen_rotation_animator_observer.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
21 #include "ui/compositor/layer_animation_element.h"
20 #include "ui/compositor/layer_animation_observer.h" 22 #include "ui/compositor/layer_animation_observer.h"
21 #include "ui/compositor/layer_animation_sequence.h" 23 #include "ui/compositor/layer_animation_sequence.h"
22 #include "ui/compositor/layer_animator.h" 24 #include "ui/compositor/layer_animator.h"
23 #include "ui/compositor/layer_owner.h" 25 #include "ui/compositor/layer_owner.h"
24 #include "ui/compositor/layer_tree_owner.h" 26 #include "ui/compositor/layer_tree_owner.h"
25 #include "ui/display/display.h" 27 #include "ui/display/display.h"
26 #include "ui/display/manager/display_manager.h" 28 #include "ui/display/manager/display_manager.h"
27 #include "ui/display/manager/managed_display_info.h" 29 #include "ui/display/manager/managed_display_info.h"
28 #include "ui/gfx/animation/tween.h" 30 #include "ui/gfx/animation/tween.h"
29 #include "ui/gfx/geometry/point.h" 31 #include "ui/gfx/geometry/point.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 LayerCleanupObserver::~LayerCleanupObserver() { 138 LayerCleanupObserver::~LayerCleanupObserver() {
137 // We must eplicitly detach from |sequence_| because we return true from 139 // We must eplicitly detach from |sequence_| because we return true from
138 // RequiresNotificationWhenAnimatorDestroyed. 140 // RequiresNotificationWhenAnimatorDestroyed.
139 if (sequence_) 141 if (sequence_)
140 sequence_->RemoveObserver(this); 142 sequence_->RemoveObserver(this);
141 } 143 }
142 144
143 void LayerCleanupObserver::OnLayerAnimationEnded( 145 void LayerCleanupObserver::OnLayerAnimationEnded(
144 ui::LayerAnimationSequence* sequence) { 146 ui::LayerAnimationSequence* sequence) {
145 if (animator_) 147 if (animator_)
146 animator_->OnLayerAnimationEnded(); 148 animator_->ProcessAnimationQueue();
147 149
148 delete this; 150 delete this;
149 } 151 }
150 152
151 void LayerCleanupObserver::OnLayerAnimationAborted( 153 void LayerCleanupObserver::OnLayerAnimationAborted(
152 ui::LayerAnimationSequence* sequence) { 154 ui::LayerAnimationSequence* sequence) {
153 if (animator_) 155 if (animator_)
154 animator_->OnLayerAnimationAborted(); 156 animator_->ProcessAnimationQueue();
155 157
156 delete this; 158 delete this;
157 } 159 }
158 160
159 void LayerCleanupObserver::OnAttachedToSequence( 161 void LayerCleanupObserver::OnAttachedToSequence(
160 ui::LayerAnimationSequence* sequence) { 162 ui::LayerAnimationSequence* sequence) {
161 sequence_ = sequence; 163 sequence_ = sequence;
162 } 164 }
163 165
164 void LayerCleanupObserver::OnDetachedFromSequence( 166 void LayerCleanupObserver::OnDetachedFromSequence(
165 ui::LayerAnimationSequence* sequence) { 167 ui::LayerAnimationSequence* sequence) {
166 DCHECK_EQ(sequence, sequence_); 168 DCHECK_EQ(sequence, sequence_);
167 sequence_ = nullptr; 169 sequence_ = nullptr;
168 } 170 }
169 171
172 class ScreenRotationAnimationMetricsReporter
173 : public ui::AnimationMetricsReporter {
174 public:
175 ScreenRotationAnimationMetricsReporter() {}
176 ~ScreenRotationAnimationMetricsReporter() override {}
177
178 void Report(int value) override {
179 UMA_HISTOGRAM_PERCENTAGE("Ash.Rotation.AnimationSmoothness", value);
180 }
181
182 private:
183 DISALLOW_COPY_AND_ASSIGN(ScreenRotationAnimationMetricsReporter);
184 };
185
170 } // namespace 186 } // namespace
171 187
172 struct ScreenRotationAnimator::ScreenRotationRequest { 188 struct ScreenRotationAnimator::ScreenRotationRequest {
173 ScreenRotationRequest(display::Display::Rotation to_rotation, 189 ScreenRotationRequest(display::Display::Rotation to_rotation,
174 display::Display::RotationSource from_source) 190 display::Display::RotationSource from_source)
175 : new_rotation(to_rotation), source(from_source) {} 191 : new_rotation(to_rotation), source(from_source) {}
176 display::Display::Rotation new_rotation; 192 display::Display::Rotation new_rotation;
177 display::Display::RotationSource source; 193 display::Display::RotationSource source;
178 }; 194 };
179 195
180 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) 196 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
181 : display_id_(display_id), 197 : display_id_(display_id),
182 is_rotating_(false), 198 is_rotating_(false),
199 metrics_reporter_(
200 base::MakeUnique<ScreenRotationAnimationMetricsReporter>()),
183 disable_animation_timers_for_test_(false), 201 disable_animation_timers_for_test_(false),
184 weak_factory_(this) {} 202 weak_factory_(this) {}
185 203
186 ScreenRotationAnimator::~ScreenRotationAnimator() {} 204 ScreenRotationAnimator::~ScreenRotationAnimator() {
205 // To prevent a call to |LayerCleanupObserver::OnLayerAnimationAborted()| from
206 // calling a method on the |animator_|.
207 weak_factory_.InvalidateWeakPtrs();
208
209 // Explicitly reset the |old_layer_tree_owner_| and |metrics_reporter_| in
210 // order to make sure |metrics_reporter_| outlives the attached animation
211 // sequence.
212 old_layer_tree_owner_.reset();
213 metrics_reporter_.reset();
214 }
187 215
188 void ScreenRotationAnimator::AnimateRotation( 216 void ScreenRotationAnimator::AnimateRotation(
189 std::unique_ptr<ScreenRotationRequest> rotation_request) { 217 std::unique_ptr<ScreenRotationRequest> rotation_request) {
190 aura::Window* root_window = GetRootWindow(display_id_); 218 aura::Window* root_window = GetRootWindow(display_id_);
191 219
192 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds(); 220 const gfx::Rect original_screen_bounds = root_window->GetTargetBounds();
193 221
194 const int rotation_factor = GetRotationFactor( 222 const int rotation_factor = GetRotationFactor(
195 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation); 223 GetCurrentScreenRotation(display_id_), rotation_request->new_rotation);
196 224
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 299 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
272 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence = 300 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence =
273 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation)); 301 base::MakeUnique<ui::LayerAnimationSequence>(std::move(screen_rotation));
274 // Add an observer so that the cloned layers can be cleaned up with the 302 // Add an observer so that the cloned layers can be cleaned up with the
275 // animation completes/aborts. 303 // animation completes/aborts.
276 animation_sequence->AddObserver(old_layer_cleanup_observer.release()); 304 animation_sequence->AddObserver(old_layer_cleanup_observer.release());
277 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to 305 // In unit test, we can use ash::test::ScreenRotationAnimatorTestApi to
278 // control the animation. 306 // control the animation.
279 if (disable_animation_timers_for_test_) 307 if (disable_animation_timers_for_test_)
280 animator->set_disable_timer_for_test(true); 308 animator->set_disable_timer_for_test(true);
309 animation_sequence->SetAnimationMetricsReporter(metrics_reporter_.get());
281 animator->StartAnimation(animation_sequence.release()); 310 animator->StartAnimation(animation_sequence.release());
282 311
283 rotation_request.reset(); 312 rotation_request.reset();
284 } 313 }
285 314
286 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation, 315 void ScreenRotationAnimator::Rotate(display::Display::Rotation new_rotation,
287 display::Display::RotationSource source) { 316 display::Display::RotationSource source) {
288 if (GetCurrentScreenRotation(display_id_) == new_rotation) 317 if (GetCurrentScreenRotation(display_id_) == new_rotation)
289 return; 318 return;
290 319
(...skipping 15 matching lines...) Expand all
306 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver( 335 void ScreenRotationAnimator::AddScreenRotationAnimatorObserver(
307 ScreenRotationAnimatorObserver* observer) { 336 ScreenRotationAnimatorObserver* observer) {
308 screen_rotation_animator_observers_.AddObserver(observer); 337 screen_rotation_animator_observers_.AddObserver(observer);
309 } 338 }
310 339
311 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver( 340 void ScreenRotationAnimator::RemoveScreenRotationAnimatorObserver(
312 ScreenRotationAnimatorObserver* observer) { 341 ScreenRotationAnimatorObserver* observer) {
313 screen_rotation_animator_observers_.RemoveObserver(observer); 342 screen_rotation_animator_observers_.RemoveObserver(observer);
314 } 343 }
315 344
316 void ScreenRotationAnimator::OnLayerAnimationEnded() {
317 ProcessAnimationQueue();
318 }
319
320 void ScreenRotationAnimator::OnLayerAnimationAborted() {
321 AbortAnimations(old_layer_tree_owner_->root());
322 ProcessAnimationQueue();
323 }
324
325 void ScreenRotationAnimator::ProcessAnimationQueue() { 345 void ScreenRotationAnimator::ProcessAnimationQueue() {
326 is_rotating_ = false; 346 is_rotating_ = false;
327 old_layer_tree_owner_.reset(); 347 old_layer_tree_owner_.reset();
328 if (last_pending_request_ && IsDisplayIdValid(display_id_)) { 348 if (last_pending_request_ && IsDisplayIdValid(display_id_)) {
329 std::unique_ptr<ScreenRotationRequest> rotation_request = 349 std::unique_ptr<ScreenRotationRequest> rotation_request =
330 std::move(last_pending_request_); 350 std::move(last_pending_request_);
331 Rotate(rotation_request->new_rotation, rotation_request->source); 351 Rotate(rotation_request->new_rotation, rotation_request->source);
332 rotation_request.reset(); 352 rotation_request.reset();
333 return; 353 return;
334 } 354 }
(...skipping 13 matching lines...) Expand all
348 if (child_layer == old_layer_tree_owner_->root()) 368 if (child_layer == old_layer_tree_owner_->root())
349 continue; 369 continue;
350 370
351 child_layer->GetAnimator()->StopAnimating(); 371 child_layer->GetAnimator()->StopAnimating();
352 } 372 }
353 373
354 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating(); 374 old_layer_tree_owner_->root()->GetAnimator()->StopAnimating();
355 } 375 }
356 376
357 } // namespace ash 377 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698