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

Side by Side Diff: ui/compositor/layer_animation_sequence.cc

Issue 2835983003: Remove WeakPtrFactory from LayerAnimationSequence (Closed)
Patch Set: Created 3 years, 7 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 | « ui/compositor/layer_animation_sequence.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer_animation_sequence.h" 5 #include "ui/compositor/layer_animation_sequence.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
11 #include "cc/animation/animation_id_provider.h" 11 #include "cc/animation/animation_id_provider.h"
12 #include "ui/compositor/layer_animation_delegate.h" 12 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/layer_animation_element.h" 13 #include "ui/compositor/layer_animation_element.h"
14 #include "ui/compositor/layer_animation_observer.h" 14 #include "ui/compositor/layer_animation_observer.h"
15 15
16 namespace ui { 16 namespace ui {
17 17
18 LayerAnimationSequence::LayerAnimationSequence() 18 LayerAnimationSequence::LayerAnimationSequence()
19 : properties_(LayerAnimationElement::UNKNOWN), 19 : properties_(LayerAnimationElement::UNKNOWN),
20 is_cyclic_(false), 20 is_cyclic_(false),
21 last_element_(0), 21 last_element_(0),
22 waiting_for_group_start_(false), 22 waiting_for_group_start_(false),
23 animation_group_id_(0), 23 animation_group_id_(0),
24 last_progressed_fraction_(0.0), 24 last_progressed_fraction_(0.0),
25 animation_metrics_reporter_(nullptr), 25 animation_metrics_reporter_(nullptr) {}
26 weak_ptr_factory_(this) {}
27 26
28 LayerAnimationSequence::LayerAnimationSequence( 27 LayerAnimationSequence::LayerAnimationSequence(
29 std::unique_ptr<LayerAnimationElement> element) 28 std::unique_ptr<LayerAnimationElement> element)
30 : properties_(LayerAnimationElement::UNKNOWN), 29 : properties_(LayerAnimationElement::UNKNOWN),
31 is_cyclic_(false), 30 is_cyclic_(false),
32 last_element_(0), 31 last_element_(0),
33 waiting_for_group_start_(false), 32 waiting_for_group_start_(false),
34 animation_group_id_(0), 33 animation_group_id_(0),
35 last_progressed_fraction_(0.0), 34 last_progressed_fraction_(0.0),
36 animation_metrics_reporter_(nullptr), 35 animation_metrics_reporter_(nullptr) {
37 weak_ptr_factory_(this) {
38 AddElement(std::move(element)); 36 AddElement(std::move(element));
39 } 37 }
40 38
41 LayerAnimationSequence::~LayerAnimationSequence() { 39 LayerAnimationSequence::~LayerAnimationSequence() {
42 for (auto& observer : observers_) 40 for (auto& observer : observers_)
43 observer.DetachedFromSequence(this, true); 41 observer.DetachedFromSequence(this, true);
44 } 42 }
45 43
46 void LayerAnimationSequence::Start(LayerAnimationDelegate* delegate) { 44 void LayerAnimationSequence::Start(LayerAnimationDelegate* delegate) {
47 DCHECK(start_time_ != base::TimeTicks()); 45 DCHECK(start_time_ != base::TimeTicks());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 last_progressed_fraction_ = 81 last_progressed_fraction_ =
84 elements_[current_index]->last_progressed_fraction(); 82 elements_[current_index]->last_progressed_fraction();
85 current_index = last_element_ % elements_.size(); 83 current_index = last_element_ % elements_.size();
86 } 84 }
87 85
88 if (is_cyclic_ || last_element_ < elements_.size()) { 86 if (is_cyclic_ || last_element_ < elements_.size()) {
89 if (!elements_[current_index]->Started()) { 87 if (!elements_[current_index]->Started()) {
90 animation_group_id_ = cc::AnimationIdProvider::NextGroupId(); 88 animation_group_id_ = cc::AnimationIdProvider::NextGroupId();
91 elements_[current_index]->Start(delegate, animation_group_id_); 89 elements_[current_index]->Start(delegate, animation_group_id_);
92 } 90 }
93 base::WeakPtr<LayerAnimationSequence> alive(weak_ptr_factory_.GetWeakPtr()); 91 base::WeakPtr<LayerAnimationSequence> alive(AsWeakPtr());
94 if (elements_[current_index]->Progress(now, delegate)) 92 if (elements_[current_index]->Progress(now, delegate))
95 redraw_required = true; 93 redraw_required = true;
96 if (!alive) 94 if (!alive)
97 return; 95 return;
98 last_progressed_fraction_ = 96 last_progressed_fraction_ =
99 elements_[current_index]->last_progressed_fraction(); 97 elements_[current_index]->last_progressed_fraction();
100 } 98 }
101 99
102 // Since the delegate may be deleted due to the notifications below, it is 100 // Since the delegate may be deleted due to the notifications below, it is
103 // important that we schedule a draw before sending them. 101 // important that we schedule a draw before sending them.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 284
287 LayerAnimationElement* LayerAnimationSequence::CurrentElement() const { 285 LayerAnimationElement* LayerAnimationSequence::CurrentElement() const {
288 if (elements_.empty()) 286 if (elements_.empty())
289 return NULL; 287 return NULL;
290 288
291 size_t current_index = last_element_ % elements_.size(); 289 size_t current_index = last_element_ % elements_.size();
292 return elements_[current_index].get(); 290 return elements_[current_index].get();
293 } 291 }
294 292
295 } // namespace ui 293 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_sequence.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698