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

Side by Side Diff: cc/timing_function.cc

Issue 11411024: cc: Switch time_source.h and timing_function* to Chrome coding style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « cc/timing_function.h ('k') | cc/timing_function_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 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/timing_function.h" 5 #include "cc/timing_function.h"
6
6 #include "third_party/skia/include/core/SkMath.h" 7 #include "third_party/skia/include/core/SkMath.h"
7 8
8 // TODO(danakj) These methods come from SkInterpolator.cpp. When such a method 9 // TODO(danakj) These methods come from SkInterpolator.cpp. When such a method
9 // is available in the public Skia API, we should switch to using that. 10 // is available in the public Skia API, we should switch to using that.
10 // http://crbug.com/159735 11 // http://crbug.com/159735
11 namespace { 12 namespace {
12 13
13 // Dot14 has 14 bits for decimal places, and the remainder for whole numbers. 14 // Dot14 has 14 bits for decimal places, and the remainder for whole numbers.
14 typedef int Dot14; 15 typedef int Dot14;
15 #define DOT14_ONE (1 << 14) 16 #define DOT14_ONE (1 << 14)
16 #define DOT14_HALF (1 << 13) 17 #define DOT14_HALF (1 << 13)
17 18
18 #define Dot14ToFloat(x) ((x) / 16384.f) 19 #define Dot14ToFloat(x) ((x) / 16384.f)
19 20
20 static inline Dot14 Dot14Mul(Dot14 a, Dot14 b) 21 static inline Dot14 Dot14Mul(Dot14 a, Dot14 b) {
21 {
22 return (a * b + DOT14_HALF) >> 14; 22 return (a * b + DOT14_HALF) >> 14;
23 } 23 }
24 24
25 static inline Dot14 EvalCubic(Dot14 t, Dot14 A, Dot14 B, Dot14 C) 25 static inline Dot14 EvalCubic(Dot14 t, Dot14 A, Dot14 B, Dot14 C) {
26 {
27 return Dot14Mul(Dot14Mul(Dot14Mul(C, t) + B, t) + A, t); 26 return Dot14Mul(Dot14Mul(Dot14Mul(C, t) + B, t) + A, t);
28 } 27 }
29 28
30 static inline Dot14 PinAndConvert(SkScalar x) 29 static inline Dot14 PinAndConvert(SkScalar x) {
31 {
32 if (x <= 0) 30 if (x <= 0)
33 return 0; 31 return 0;
34 if (x >= SK_Scalar1) 32 if (x >= SK_Scalar1)
35 return DOT14_ONE; 33 return DOT14_ONE;
36 return SkScalarToFixed(x) >> 2; 34 return SkScalarToFixed(x) >> 2;
37 } 35 }
38 36
39 SkScalar SkUnitCubicInterp(SkScalar bx, SkScalar by, SkScalar cx, SkScalar cy, S kScalar value) 37 SkScalar SkUnitCubicInterp(SkScalar bx, SkScalar by,
danakj 2012/11/16 00:32:13 I thought you have to put 1 parameter per line if
tfarina 2012/11/16 00:36:35 this is a pair of x, y. Yes, I have thought about
danakj 2012/11/16 00:38:22 No, the less line wrapping the better IMO
40 { 38 SkScalar cx, SkScalar cy,
39 SkScalar value) {
41 Dot14 x = PinAndConvert(value); 40 Dot14 x = PinAndConvert(value);
42 41
43 if (x == 0) return 0; 42 if (x == 0) return 0;
44 if (x == DOT14_ONE) return SK_Scalar1; 43 if (x == DOT14_ONE) return SK_Scalar1;
45 44
46 Dot14 b = PinAndConvert(bx); 45 Dot14 b = PinAndConvert(bx);
47 Dot14 c = PinAndConvert(cx); 46 Dot14 c = PinAndConvert(cx);
48 47
49 // Now compute our coefficients from the control points. 48 // Now compute our coefficients from the control points.
50 // t -> 3b 49 // t -> 3b
(...skipping 17 matching lines...) Expand all
68 67
69 // Now we have t, so compute the coefficient for Y and evaluate. 68 // Now we have t, so compute the coefficient for Y and evaluate.
70 b = PinAndConvert(by); 69 b = PinAndConvert(by);
71 c = PinAndConvert(cy); 70 c = PinAndConvert(cy);
72 A = 3 * b; 71 A = 3 * b;
73 B = 3 * (c - 2 * b); 72 B = 3 * (c - 2 * b);
74 C = 3 * (b - c) + DOT14_ONE; 73 C = 3 * (b - c) + DOT14_ONE;
75 return SkFixedToScalar(EvalCubic(t, A, B, C) << 2); 74 return SkFixedToScalar(EvalCubic(t, A, B, C) << 2);
76 } 75 }
77 76
78 } // anonymous namespace 77 } // namespace
79 78
80 namespace cc { 79 namespace cc {
81 80
82 TimingFunction::TimingFunction() 81 TimingFunction::TimingFunction() {
83 {
84 } 82 }
85 83
86 TimingFunction::~TimingFunction() 84 TimingFunction::~TimingFunction() {
87 {
88 } 85 }
89 86
90 double TimingFunction::duration() const 87 double TimingFunction::duration() const {
91 {
92 return 1.0; 88 return 1.0;
93 } 89 }
94 90
95 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::create(double x 1, double y1, double x2, double y2) 91 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::create(
96 { 92 double x1, double y1, double x2, double y2) {
97 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2)); 93 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2));
98 } 94 }
99 95
100 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, double y1, doubl e x2, double y2) 96 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, double y1,
101 : m_x1(SkDoubleToScalar(x1)) 97 double x2, double y2)
102 , m_y1(SkDoubleToScalar(y1)) 98 : x1_(SkDoubleToScalar(x1)),
103 , m_x2(SkDoubleToScalar(x2)) 99 y1_(SkDoubleToScalar(y1)),
104 , m_y2(SkDoubleToScalar(y2)) 100 x2_(SkDoubleToScalar(x2)),
105 { 101 y2_(SkDoubleToScalar(y2)) {
106 } 102 }
107 103
108 CubicBezierTimingFunction::~CubicBezierTimingFunction() 104 CubicBezierTimingFunction::~CubicBezierTimingFunction() {
109 {
110 } 105 }
111 106
112 float CubicBezierTimingFunction::getValue(double x) const 107 float CubicBezierTimingFunction::getValue(double x) const {
113 { 108 SkScalar value = SkUnitCubicInterp(x1_, y1_, x2_, y2_, x);
114 SkScalar value = SkUnitCubicInterp(m_x1, m_y1, m_x2, m_y2, x); 109 return SkScalarToFloat(value);
115 return SkScalarToFloat(value);
116 } 110 }
117 111
118 scoped_ptr<AnimationCurve> CubicBezierTimingFunction::clone() const 112 scoped_ptr<AnimationCurve> CubicBezierTimingFunction::clone() const {
119 { 113 return make_scoped_ptr(
120 return make_scoped_ptr(new CubicBezierTimingFunction(*this)).PassAs<Animatio nCurve>(); 114 new CubicBezierTimingFunction(*this)).PassAs<AnimationCurve>();
121 } 115 }
122 116
123 // These numbers come from http://www.w3.org/TR/css3-transitions/#transition-tim ing-function_tag. 117 // These numbers come from http://www.w3.org/TR/css3-transitions/#transition-tim ing-function_tag.
124 scoped_ptr<TimingFunction> EaseTimingFunction::create() 118 scoped_ptr<TimingFunction> EaseTimingFunction::create() {
125 { 119 return CubicBezierTimingFunction::create(
126 return CubicBezierTimingFunction::create(0.25, 0.1, 0.25, 1).PassAs<TimingFu nction>(); 120 0.25, 0.1, 0.25, 1).PassAs<TimingFunction>();
127 } 121 }
128 122
129 scoped_ptr<TimingFunction> EaseInTimingFunction::create() 123 scoped_ptr<TimingFunction> EaseInTimingFunction::create() {
130 { 124 return CubicBezierTimingFunction::create(
131 return CubicBezierTimingFunction::create(0.42, 0, 1.0, 1).PassAs<TimingFunct ion>(); 125 0.42, 0, 1.0, 1).PassAs<TimingFunction>();
132 } 126 }
133 127
134 scoped_ptr<TimingFunction> EaseOutTimingFunction::create() 128 scoped_ptr<TimingFunction> EaseOutTimingFunction::create() {
135 { 129 return CubicBezierTimingFunction::create(
136 return CubicBezierTimingFunction::create(0, 0, 0.58, 1).PassAs<TimingFunctio n>(); 130 0, 0, 0.58, 1).PassAs<TimingFunction>();
137 } 131 }
138 132
139 scoped_ptr<TimingFunction> EaseInOutTimingFunction::create() 133 scoped_ptr<TimingFunction> EaseInOutTimingFunction::create() {
140 { 134 return CubicBezierTimingFunction::create(
141 return CubicBezierTimingFunction::create(0.42, 0, 0.58, 1).PassAs<TimingFunc tion>(); 135 0.42, 0, 0.58, 1).PassAs<TimingFunction>();
142 } 136 }
143 137
144 } // namespace cc 138 } // namespace cc
OLDNEW
« no previous file with comments | « cc/timing_function.h ('k') | cc/timing_function_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698