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

Side by Side Diff: cc/animation/timing_function.cc

Issue 809523004: Define step timing function for the cc animation framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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
OLDNEW
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "cc/animation/timing_function.h" 7 #include "cc/animation/timing_function.h"
8 #include "cc/base/math_util.h"
8 9
9 namespace cc { 10 namespace cc {
10 11
11 TimingFunction::TimingFunction() {} 12 TimingFunction::TimingFunction() {}
12 13
13 TimingFunction::~TimingFunction() {} 14 TimingFunction::~TimingFunction() {}
14 15
15 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::Create( 16 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::Create(
16 double x1, double y1, double x2, double y2) { 17 double x1, double y1, double x2, double y2) {
17 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2)); 18 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 57 }
57 58
58 scoped_ptr<TimingFunction> EaseOutTimingFunction::Create() { 59 scoped_ptr<TimingFunction> EaseOutTimingFunction::Create() {
59 return CubicBezierTimingFunction::Create(0.0, 0.0, 0.58, 1.0); 60 return CubicBezierTimingFunction::Create(0.0, 0.0, 0.58, 1.0);
60 } 61 }
61 62
62 scoped_ptr<TimingFunction> EaseInOutTimingFunction::Create() { 63 scoped_ptr<TimingFunction> EaseInOutTimingFunction::Create() {
63 return CubicBezierTimingFunction::Create(0.42, 0.0, 0.58, 1); 64 return CubicBezierTimingFunction::Create(0.42, 0.0, 0.58, 1);
64 } 65 }
65 66
67 scoped_ptr<StepsTimingFunction> StepsTimingFunction::Create(
68 int steps,
69 float steps_start_offset) {
70 return make_scoped_ptr(new StepsTimingFunction(steps, steps_start_offset));
71 }
72
73 StepsTimingFunction::StepsTimingFunction(int steps, float steps_start_offset)
74 : steps_(steps), steps_start_offset_(steps_start_offset) {
75 // Restrict it to css presets: step_start, step_end and step_middle.
76 DCHECK(steps_start_offset_ == 0 || steps_start_offset_ == 1 ||
77 steps_start_offset_ == 0.5);
ajuma 2014/12/17 16:32:56 If we're restricting to these values, let's use th
loyso (OOO) 2014/12/18 01:53:05 My initial implementation was absolutely like that
ajuma 2014/12/18 02:15:41 Ok.
78 }
79
80 StepsTimingFunction::~StepsTimingFunction() {
81 }
82
83 float StepsTimingFunction::GetValue(double t) const {
84 return MathUtil::ClampToRange(
85 floor((steps_ * t) + steps_start_offset_) / steps_, 0.0, 1.0);
ajuma 2014/12/17 16:32:56 static_cast<double>(steps_) (rather than having an
loyso (OOO) 2014/12/18 01:53:05 There is a bunch of implicit conversions. steps_ i
ajuma 2014/12/18 02:15:41 Yes, please make them explicit. The style guide ta
loyso (OOO) 2014/12/18 03:17:30 That link says nothing on implicit vs. explicit co
ajuma 2014/12/18 14:32:54 It's a (relatively) common practice in cc. It make
86 }
87
88 scoped_ptr<TimingFunction> StepsTimingFunction::Clone() const {
89 return make_scoped_ptr(new StepsTimingFunction(*this));
90 }
91
92 void StepsTimingFunction::Range(float* min, float* max) const {
93 *min = 0.0f;
94 *max = 1.0f;
95 }
96
97 float StepsTimingFunction::Velocity(double x) const {
98 return 0.0f;
99 }
100
66 } // namespace cc 101 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698