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

Side by Side Diff: sky/viewer/cc/web_animation_impl.cc

Issue 752683002: Break Sky's dependency on cc (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 | « sky/viewer/cc/web_animation_impl.h ('k') | sky/viewer/cc/web_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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sky/viewer/cc/web_animation_impl.h"
6
7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_id_provider.h"
10 #include "sky/viewer/cc/web_filter_animation_curve_impl.h"
11 #include "sky/viewer/cc/web_float_animation_curve_impl.h"
12 #include "sky/viewer/cc/web_transform_animation_curve_impl.h"
13 #include "sky/engine/public/platform/WebCompositorAnimationCurve.h"
14
15 using cc::Animation;
16 using cc::AnimationIdProvider;
17
18 using blink::WebCompositorAnimation;
19 using blink::WebCompositorAnimationCurve;
20
21 namespace sky_viewer_cc {
22
23 WebCompositorAnimationImpl::WebCompositorAnimationImpl(
24 const WebCompositorAnimationCurve& web_curve,
25 TargetProperty target_property,
26 int animation_id,
27 int group_id) {
28 if (!animation_id)
29 animation_id = AnimationIdProvider::NextAnimationId();
30 if (!group_id)
31 group_id = AnimationIdProvider::NextGroupId();
32
33 WebCompositorAnimationCurve::AnimationCurveType curve_type = web_curve.type();
34 scoped_ptr<cc::AnimationCurve> curve;
35 switch (curve_type) {
36 case WebCompositorAnimationCurve::AnimationCurveTypeFloat: {
37 const WebFloatAnimationCurveImpl* float_curve_impl =
38 static_cast<const WebFloatAnimationCurveImpl*>(&web_curve);
39 curve = float_curve_impl->CloneToAnimationCurve();
40 break;
41 }
42 case WebCompositorAnimationCurve::AnimationCurveTypeTransform: {
43 const WebTransformAnimationCurveImpl* transform_curve_impl =
44 static_cast<const WebTransformAnimationCurveImpl*>(&web_curve);
45 curve = transform_curve_impl->CloneToAnimationCurve();
46 break;
47 }
48 case WebCompositorAnimationCurve::AnimationCurveTypeFilter: {
49 const WebFilterAnimationCurveImpl* filter_curve_impl =
50 static_cast<const WebFilterAnimationCurveImpl*>(&web_curve);
51 curve = filter_curve_impl->CloneToAnimationCurve();
52 break;
53 }
54 }
55 animation_ = Animation::Create(
56 curve.Pass(),
57 animation_id,
58 group_id,
59 static_cast<cc::Animation::TargetProperty>(target_property));
60 }
61
62 WebCompositorAnimationImpl::~WebCompositorAnimationImpl() {
63 }
64
65 int WebCompositorAnimationImpl::id() {
66 return animation_->id();
67 }
68
69 blink::WebCompositorAnimation::TargetProperty
70 WebCompositorAnimationImpl::targetProperty() const {
71 return static_cast<WebCompositorAnimationImpl::TargetProperty>(
72 animation_->target_property());
73 }
74
75 #if WEB_ANIMATION_SUPPORTS_FRACTIONAL_ITERATIONS
76 double WebCompositorAnimationImpl::iterations() const {
77 return animation_->iterations();
78 }
79
80 void WebCompositorAnimationImpl::setIterations(double n) {
81 animation_->set_iterations(n);
82 }
83 #else
84 int WebCompositorAnimationImpl::iterations() const {
85 return animation_->iterations();
86 }
87
88 void WebCompositorAnimationImpl::setIterations(int n) {
89 animation_->set_iterations(n);
90 }
91 #endif
92
93 double WebCompositorAnimationImpl::startTime() const {
94 return (animation_->start_time() - base::TimeTicks()).InSecondsF();
95 }
96
97 void WebCompositorAnimationImpl::setStartTime(double monotonic_time) {
98 animation_->set_start_time(base::TimeTicks::FromInternalValue(
99 monotonic_time * base::Time::kMicrosecondsPerSecond));
100 }
101
102 double WebCompositorAnimationImpl::timeOffset() const {
103 return animation_->time_offset().InSecondsF();
104 }
105
106 void WebCompositorAnimationImpl::setTimeOffset(double monotonic_time) {
107 animation_->set_time_offset(base::TimeDelta::FromSecondsD(monotonic_time));
108 }
109
110 #if WEB_ANIMATION_SUPPORTS_FULL_DIRECTION
111 blink::WebCompositorAnimation::Direction WebCompositorAnimationImpl::direction()
112 const {
113 switch (animation_->direction()) {
114 case cc::Animation::Normal:
115 return DirectionNormal;
116 case cc::Animation::Reverse:
117 return DirectionReverse;
118 case cc::Animation::Alternate:
119 return DirectionAlternate;
120 case cc::Animation::AlternateReverse:
121 return DirectionAlternateReverse;
122 default:
123 NOTREACHED();
124 }
125 return DirectionNormal;
126 }
127
128 void WebCompositorAnimationImpl::setDirection(Direction direction) {
129 switch (direction) {
130 case DirectionNormal:
131 animation_->set_direction(cc::Animation::Normal);
132 break;
133 case DirectionReverse:
134 animation_->set_direction(cc::Animation::Reverse);
135 break;
136 case DirectionAlternate:
137 animation_->set_direction(cc::Animation::Alternate);
138 break;
139 case DirectionAlternateReverse:
140 animation_->set_direction(cc::Animation::AlternateReverse);
141 break;
142 }
143 }
144 #else
145 bool WebCompositorAnimationImpl::alternatesDirection() const {
146 return animation_->direction() == cc::Animation::Alternate;
147 }
148
149 void WebCompositorAnimationImpl::setAlternatesDirection(bool alternates) {
150 if (alternates)
151 animation_->set_direction(cc::Animation::Alternate);
152 else
153 animation_->set_direction(cc::Animation::Normal);
154 }
155 #endif
156
157 double WebCompositorAnimationImpl::playbackRate() const {
158 return animation_->playback_rate();
159 }
160
161 void WebCompositorAnimationImpl::setPlaybackRate(double playback_rate) {
162 animation_->set_playback_rate(playback_rate);
163 }
164
165 scoped_ptr<cc::Animation> WebCompositorAnimationImpl::PassAnimation() {
166 animation_->set_needs_synchronized_start_time(true);
167 return animation_.Pass();
168 }
169
170 } // namespace sky_viewer_cc
OLDNEW
« no previous file with comments | « sky/viewer/cc/web_animation_impl.h ('k') | sky/viewer/cc/web_animation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698