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

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

Issue 1866203004: Convert //cc from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptrcc: rebase Created 4 years, 8 months 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 | « cc/animation/timing_function.h ('k') | cc/animation/transform_operations.h » ('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/animation/timing_function.h"
6
7 #include <memory>
8
5 #include "base/logging.h" 9 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/ptr_util.h"
7 #include "cc/animation/timing_function.h"
8 #include "cc/base/math_util.h" 11 #include "cc/base/math_util.h"
9 12
10 namespace cc { 13 namespace cc {
11 14
12 TimingFunction::TimingFunction() {} 15 TimingFunction::TimingFunction() {}
13 16
14 TimingFunction::~TimingFunction() {} 17 TimingFunction::~TimingFunction() {}
15 18
16 scoped_ptr<CubicBezierTimingFunction> CubicBezierTimingFunction::Create( 19 std::unique_ptr<CubicBezierTimingFunction>
17 double x1, double y1, double x2, double y2) { 20 CubicBezierTimingFunction::Create(double x1, double y1, double x2, double y2) {
18 return make_scoped_ptr(new CubicBezierTimingFunction(x1, y1, x2, y2)); 21 return base::WrapUnique(new CubicBezierTimingFunction(x1, y1, x2, y2));
19 } 22 }
20 23
21 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1, 24 CubicBezierTimingFunction::CubicBezierTimingFunction(double x1,
22 double y1, 25 double y1,
23 double x2, 26 double x2,
24 double y2) 27 double y2)
25 : bezier_(x1, y1, x2, y2) {} 28 : bezier_(x1, y1, x2, y2) {}
26 29
27 CubicBezierTimingFunction::~CubicBezierTimingFunction() {} 30 CubicBezierTimingFunction::~CubicBezierTimingFunction() {}
28 31
29 float CubicBezierTimingFunction::GetValue(double x) const { 32 float CubicBezierTimingFunction::GetValue(double x) const {
30 return static_cast<float>(bezier_.Solve(x)); 33 return static_cast<float>(bezier_.Solve(x));
31 } 34 }
32 35
33 float CubicBezierTimingFunction::Velocity(double x) const { 36 float CubicBezierTimingFunction::Velocity(double x) const {
34 return static_cast<float>(bezier_.Slope(x)); 37 return static_cast<float>(bezier_.Slope(x));
35 } 38 }
36 39
37 void CubicBezierTimingFunction::Range(float* min, float* max) const { 40 void CubicBezierTimingFunction::Range(float* min, float* max) const {
38 double min_d = 0; 41 double min_d = 0;
39 double max_d = 1; 42 double max_d = 1;
40 bezier_.Range(&min_d, &max_d); 43 bezier_.Range(&min_d, &max_d);
41 *min = static_cast<float>(min_d); 44 *min = static_cast<float>(min_d);
42 *max = static_cast<float>(max_d); 45 *max = static_cast<float>(max_d);
43 } 46 }
44 47
45 scoped_ptr<TimingFunction> CubicBezierTimingFunction::Clone() const { 48 std::unique_ptr<TimingFunction> CubicBezierTimingFunction::Clone() const {
46 return make_scoped_ptr(new CubicBezierTimingFunction(*this)); 49 return base::WrapUnique(new CubicBezierTimingFunction(*this));
47 } 50 }
48 51
49 // These numbers come from 52 // These numbers come from
50 // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag. 53 // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag.
51 scoped_ptr<TimingFunction> EaseTimingFunction::Create() { 54 std::unique_ptr<TimingFunction> EaseTimingFunction::Create() {
52 return CubicBezierTimingFunction::Create(0.25, 0.1, 0.25, 1.0); 55 return CubicBezierTimingFunction::Create(0.25, 0.1, 0.25, 1.0);
53 } 56 }
54 57
55 scoped_ptr<TimingFunction> EaseInTimingFunction::Create() { 58 std::unique_ptr<TimingFunction> EaseInTimingFunction::Create() {
56 return CubicBezierTimingFunction::Create(0.42, 0.0, 1.0, 1.0); 59 return CubicBezierTimingFunction::Create(0.42, 0.0, 1.0, 1.0);
57 } 60 }
58 61
59 scoped_ptr<TimingFunction> EaseOutTimingFunction::Create() { 62 std::unique_ptr<TimingFunction> EaseOutTimingFunction::Create() {
60 return CubicBezierTimingFunction::Create(0.0, 0.0, 0.58, 1.0); 63 return CubicBezierTimingFunction::Create(0.0, 0.0, 0.58, 1.0);
61 } 64 }
62 65
63 scoped_ptr<TimingFunction> EaseInOutTimingFunction::Create() { 66 std::unique_ptr<TimingFunction> EaseInOutTimingFunction::Create() {
64 return CubicBezierTimingFunction::Create(0.42, 0.0, 0.58, 1); 67 return CubicBezierTimingFunction::Create(0.42, 0.0, 0.58, 1);
65 } 68 }
66 69
67 scoped_ptr<StepsTimingFunction> StepsTimingFunction::Create( 70 std::unique_ptr<StepsTimingFunction> StepsTimingFunction::Create(
68 int steps, 71 int steps,
69 float steps_start_offset) { 72 float steps_start_offset) {
70 return make_scoped_ptr(new StepsTimingFunction(steps, steps_start_offset)); 73 return base::WrapUnique(new StepsTimingFunction(steps, steps_start_offset));
71 } 74 }
72 75
73 StepsTimingFunction::StepsTimingFunction(int steps, float steps_start_offset) 76 StepsTimingFunction::StepsTimingFunction(int steps, float steps_start_offset)
74 : steps_(steps), steps_start_offset_(steps_start_offset) { 77 : steps_(steps), steps_start_offset_(steps_start_offset) {
75 // Restrict it to CSS presets: step_start, step_end and step_middle. 78 // Restrict it to CSS presets: step_start, step_end and step_middle.
76 // See the Web Animations specification, 3.12.4. Timing in discrete steps. 79 // See the Web Animations specification, 3.12.4. Timing in discrete steps.
77 DCHECK(steps_start_offset_ == 0 || steps_start_offset_ == 1 || 80 DCHECK(steps_start_offset_ == 0 || steps_start_offset_ == 1 ||
78 steps_start_offset_ == 0.5); 81 steps_start_offset_ == 0.5);
79 } 82 }
80 83
81 StepsTimingFunction::~StepsTimingFunction() { 84 StepsTimingFunction::~StepsTimingFunction() {
82 } 85 }
83 86
84 float StepsTimingFunction::GetValue(double t) const { 87 float StepsTimingFunction::GetValue(double t) const {
85 const double steps = static_cast<double>(steps_); 88 const double steps = static_cast<double>(steps_);
86 const double value = MathUtil::ClampToRange( 89 const double value = MathUtil::ClampToRange(
87 std::floor((steps * t) + steps_start_offset_) / steps, 0.0, 1.0); 90 std::floor((steps * t) + steps_start_offset_) / steps, 0.0, 1.0);
88 return static_cast<float>(value); 91 return static_cast<float>(value);
89 } 92 }
90 93
91 scoped_ptr<TimingFunction> StepsTimingFunction::Clone() const { 94 std::unique_ptr<TimingFunction> StepsTimingFunction::Clone() const {
92 return make_scoped_ptr(new StepsTimingFunction(*this)); 95 return base::WrapUnique(new StepsTimingFunction(*this));
93 } 96 }
94 97
95 void StepsTimingFunction::Range(float* min, float* max) const { 98 void StepsTimingFunction::Range(float* min, float* max) const {
96 *min = 0.0f; 99 *min = 0.0f;
97 *max = 1.0f; 100 *max = 1.0f;
98 } 101 }
99 102
100 float StepsTimingFunction::Velocity(double x) const { 103 float StepsTimingFunction::Velocity(double x) const {
101 return 0.0f; 104 return 0.0f;
102 } 105 }
103 106
104 } // namespace cc 107 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/timing_function.h ('k') | cc/animation/transform_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698