OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/animation/animation.h" | 5 #include "cc/animation/animation.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "cc/animation/animation_curve.h" | 11 #include "cc/animation/animation_curve.h" |
12 #include "cc/base/time_util.h" | 12 #include "cc/base/time_util.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // This should match the RunState enum. | 16 // This should match the RunState enum. |
17 static const char* const s_runStateNames[] = {"WAITING_FOR_TARGET_AVAILABILITY", | 17 static const char* const s_runStateNames[] = {"WAITING_FOR_TARGET_AVAILABILITY", |
18 "WAITING_FOR_DELETION", | 18 "WAITING_FOR_DELETION", |
19 "STARTING", | 19 "STARTING", |
20 "RUNNING", | 20 "RUNNING", |
21 "PAUSED", | 21 "PAUSED", |
22 "FINISHED", | 22 "FINISHED", |
23 "ABORTED"}; | 23 "ABORTED"}; |
24 | 24 |
25 static_assert(static_cast<int>(cc::Animation::LAST_RUN_STATE) + 1 == | 25 static_assert(static_cast<int>(cc::Animation::LAST_RUN_STATE) + 1 == |
26 arraysize(s_runStateNames), | 26 arraysize(s_runStateNames), |
27 "RunStateEnumSize should equal the number of elements in " | 27 "RunStateEnumSize should equal the number of elements in " |
28 "s_runStateNames"); | 28 "s_runStateNames"); |
29 | 29 |
30 // This should match the TargetProperty enum. | |
31 static const char* const s_targetPropertyNames[] = {"TRANSFORM", | |
32 "OPACITY", | |
33 "FILTER", | |
34 "SCROLL_OFFSET", | |
35 "BACKGROUND_COLOR"}; | |
36 | |
37 static_assert(static_cast<int>(cc::Animation::LAST_TARGET_PROPERTY) + 1 == | |
38 arraysize(s_targetPropertyNames), | |
39 "TargetPropertyEnumSize should equal the number of elements in " | |
40 "s_targetPropertyNames"); | |
41 | |
42 } // namespace | 30 } // namespace |
43 | 31 |
44 namespace cc { | 32 namespace cc { |
45 | 33 |
46 scoped_ptr<Animation> Animation::Create( | 34 scoped_ptr<Animation> Animation::Create( |
47 scoped_ptr<AnimationCurve> curve, | 35 scoped_ptr<AnimationCurve> curve, |
48 int animation_id, | 36 int animation_id, |
49 int group_id, | 37 int group_id, |
50 TargetProperty target_property) { | 38 AnimationTargetProperty target_property) { |
51 return make_scoped_ptr( | 39 return make_scoped_ptr( |
52 new Animation(std::move(curve), animation_id, group_id, target_property)); | 40 new Animation(std::move(curve), animation_id, group_id, target_property)); |
53 } | 41 } |
54 | 42 |
55 Animation::Animation(scoped_ptr<AnimationCurve> curve, | 43 Animation::Animation(scoped_ptr<AnimationCurve> curve, |
56 int animation_id, | 44 int animation_id, |
57 int group_id, | 45 int group_id, |
58 TargetProperty target_property) | 46 AnimationTargetProperty target_property) |
59 : curve_(std::move(curve)), | 47 : curve_(std::move(curve)), |
60 id_(animation_id), | 48 id_(animation_id), |
61 group_(group_id), | 49 group_(group_id), |
62 target_property_(target_property), | 50 target_property_(target_property), |
63 run_state_(WAITING_FOR_TARGET_AVAILABILITY), | 51 run_state_(WAITING_FOR_TARGET_AVAILABILITY), |
64 iterations_(1), | 52 iterations_(1), |
65 iteration_start_(0), | 53 iteration_start_(0), |
66 direction_(DIRECTION_NORMAL), | 54 direction_(DIRECTION_NORMAL), |
67 playback_rate_(1), | 55 playback_rate_(1), |
68 fill_mode_(FILL_MODE_BOTH), | 56 fill_mode_(FILL_MODE_BOTH), |
69 needs_synchronized_start_time_(false), | 57 needs_synchronized_start_time_(false), |
70 received_finished_event_(false), | 58 received_finished_event_(false), |
71 suspended_(false), | 59 suspended_(false), |
72 is_controlling_instance_(false), | 60 is_controlling_instance_(false), |
73 is_impl_only_(false), | 61 is_impl_only_(false), |
74 affects_active_observers_(true), | 62 affects_active_observers_(true), |
75 affects_pending_observers_(true) {} | 63 affects_pending_observers_(true) {} |
76 | 64 |
77 Animation::~Animation() { | 65 Animation::~Animation() { |
78 if (run_state_ == RUNNING || run_state_ == PAUSED) | 66 if (run_state_ == RUNNING || run_state_ == PAUSED) |
79 SetRunState(ABORTED, base::TimeTicks()); | 67 SetRunState(ABORTED, base::TimeTicks()); |
80 } | 68 } |
81 | 69 |
82 void Animation::SetRunState(RunState run_state, | 70 void Animation::SetRunState(RunState run_state, |
83 base::TimeTicks monotonic_time) { | 71 base::TimeTicks monotonic_time) { |
84 if (suspended_) | 72 if (suspended_) |
85 return; | 73 return; |
86 | 74 |
87 char name_buffer[256]; | 75 char name_buffer[256]; |
88 base::snprintf(name_buffer, | 76 base::snprintf(name_buffer, sizeof(name_buffer), "%s-%d", |
89 sizeof(name_buffer), | 77 GetAnimationTargetPropertyName(target_property_), group_); |
90 "%s-%d", | |
91 s_targetPropertyNames[target_property_], | |
92 group_); | |
93 | 78 |
94 bool is_waiting_to_start = | 79 bool is_waiting_to_start = |
95 run_state_ == WAITING_FOR_TARGET_AVAILABILITY || run_state_ == STARTING; | 80 run_state_ == WAITING_FOR_TARGET_AVAILABILITY || run_state_ == STARTING; |
96 | 81 |
97 if (is_controlling_instance_ && is_waiting_to_start && run_state == RUNNING) { | 82 if (is_controlling_instance_ && is_waiting_to_start && run_state == RUNNING) { |
98 TRACE_EVENT_ASYNC_BEGIN1( | 83 TRACE_EVENT_ASYNC_BEGIN1( |
99 "cc", "Animation", this, "Name", TRACE_STR_COPY(name_buffer)); | 84 "cc", "Animation", this, "Name", TRACE_STR_COPY(name_buffer)); |
100 } | 85 } |
101 | 86 |
102 bool was_finished = is_finished(); | 87 bool was_finished = is_finished(); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // the main thread. | 262 // the main thread. |
278 if (run_state_ == Animation::PAUSED || | 263 if (run_state_ == Animation::PAUSED || |
279 other->run_state_ == Animation::PAUSED) { | 264 other->run_state_ == Animation::PAUSED) { |
280 other->run_state_ = run_state_; | 265 other->run_state_ = run_state_; |
281 other->pause_time_ = pause_time_; | 266 other->pause_time_ = pause_time_; |
282 other->total_paused_time_ = total_paused_time_; | 267 other->total_paused_time_ = total_paused_time_; |
283 } | 268 } |
284 } | 269 } |
285 | 270 |
286 } // namespace cc | 271 } // namespace cc |
OLD | NEW |