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/gfx/animation/multi_animation.cc

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: WIP Created 7 years, 1 month 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/gfx/animation/multi_animation.h ('k') | ui/gfx/animation/multi_animation_unittest.cc » ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/gfx/animation/multi_animation.h" 5 #include "ui/gfx/animation/multi_animation.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/gfx/animation/animation_delegate.h" 8 #include "ui/gfx/animation/animation_delegate.h"
9 9
10 namespace gfx { 10 namespace gfx {
(...skipping 25 matching lines...) Expand all
36 36
37 // static. 37 // static.
38 base::TimeDelta MultiAnimation::GetDefaultTimerInterval() { 38 base::TimeDelta MultiAnimation::GetDefaultTimerInterval() {
39 return base::TimeDelta::FromMilliseconds(kDefaultTimerInterval); 39 return base::TimeDelta::FromMilliseconds(kDefaultTimerInterval);
40 } 40 }
41 41
42 double MultiAnimation::GetCurrentValue() const { 42 double MultiAnimation::GetCurrentValue() const {
43 return current_value_; 43 return current_value_;
44 } 44 }
45 45
46 void MultiAnimation::Step(base::TimeTicks time_now) { 46 void MultiAnimation::Step(gfx::FrameTime time_now) {
47 double last_value = current_value_; 47 double last_value = current_value_;
48 size_t last_index = current_part_index_; 48 size_t last_index = current_part_index_;
49 49
50 int delta = static_cast<int>((time_now - start_time()).InMilliseconds()); 50 int delta = static_cast<int>((time_now - start_time()).InMilliseconds());
51 if (delta >= cycle_time_ms_ && !continuous_) { 51 if (delta >= cycle_time_ms_ && !continuous_) {
52 current_part_index_ = parts_.size() - 1; 52 current_part_index_ = parts_.size() - 1;
53 current_value_ = Tween::CalculateValue(parts_[current_part_index_].type, 1); 53 current_value_ = Tween::CalculateValue(parts_[current_part_index_].type, 1);
54 Stop(); 54 Stop();
55 return; 55 return;
56 } 56 }
57 delta %= cycle_time_ms_; 57 delta %= cycle_time_ms_;
58 const Part& part = GetPart(&delta, &current_part_index_); 58 const Part& part = GetPart(&delta, &current_part_index_);
59 double percent = static_cast<double>(delta + part.start_time_ms) / 59 double percent = static_cast<double>(delta + part.start_time_ms) /
60 static_cast<double>(part.end_time_ms); 60 static_cast<double>(part.end_time_ms);
61 DCHECK(percent <= 1); 61 DCHECK(percent <= 1);
62 current_value_ = Tween::CalculateValue(part.type, percent); 62 current_value_ = Tween::CalculateValue(part.type, percent);
63 63
64 if ((current_value_ != last_value || current_part_index_ != last_index) && 64 if ((current_value_ != last_value || current_part_index_ != last_index) &&
65 delegate()) { 65 delegate()) {
66 delegate()->AnimationProgressed(this); 66 delegate()->AnimationProgressed(this);
67 } 67 }
68 } 68 }
69 69
70 void MultiAnimation::SetStartTime(base::TimeTicks start_time) { 70 void MultiAnimation::SetStartTime(gfx::FrameTime start_time) {
71 Animation::SetStartTime(start_time); 71 Animation::SetStartTime(start_time);
72 current_value_ = 0; 72 current_value_ = 0;
73 current_part_index_ = 0; 73 current_part_index_ = 0;
74 } 74 }
75 75
76 const MultiAnimation::Part& MultiAnimation::GetPart(int* time_ms, 76 const MultiAnimation::Part& MultiAnimation::GetPart(int* time_ms,
77 size_t* part_index) { 77 size_t* part_index) {
78 DCHECK(*time_ms < cycle_time_ms_); 78 DCHECK(*time_ms < cycle_time_ms_);
79 79
80 for (size_t i = 0; i < parts_.size(); ++i) { 80 for (size_t i = 0; i < parts_.size(); ++i) {
81 if (*time_ms < parts_[i].time_ms) { 81 if (*time_ms < parts_[i].time_ms) {
82 *part_index = i; 82 *part_index = i;
83 return parts_[i]; 83 return parts_[i];
84 } 84 }
85 85
86 *time_ms -= parts_[i].time_ms; 86 *time_ms -= parts_[i].time_ms;
87 } 87 }
88 NOTREACHED(); 88 NOTREACHED();
89 *time_ms = 0; 89 *time_ms = 0;
90 *part_index = 0; 90 *part_index = 0;
91 return parts_[0]; 91 return parts_[0];
92 } 92 }
93 93
94 } // namespace gfx 94 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/animation/multi_animation.h ('k') | ui/gfx/animation/multi_animation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698