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

Side by Side Diff: ui/gfx/animation/tween.cc

Issue 1543183002: Switch to standard integer types in ui/gfx/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 | « ui/gfx/animation/tween.h ('k') | ui/gfx/animation/tween_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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ui/gfx/animation/tween.h" 5 #include "ui/gfx/animation/tween.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stdint.h>
9
10 #include <algorithm>
11
12 #include "base/logging.h"
13 #include "base/numerics/safe_conversions.h"
14 #include "build/build_config.h"
15 #include "ui/gfx/geometry/cubic_bezier.h"
16 #include "ui/gfx/geometry/safe_integer_conversions.h"
8 17
9 #if defined(OS_WIN) 18 #if defined(OS_WIN)
10 #include <float.h> 19 #include <float.h>
11 #endif 20 #endif
12 21
13 #include <algorithm>
14
15 #include "base/basictypes.h"
16 #include "base/logging.h"
17 #include "base/numerics/safe_conversions.h"
18 #include "ui/gfx/geometry/cubic_bezier.h"
19 #include "ui/gfx/geometry/safe_integer_conversions.h"
20
21 namespace gfx { 22 namespace gfx {
22 23
23 // static 24 // static
24 double Tween::CalculateValue(Tween::Type type, double state) { 25 double Tween::CalculateValue(Tween::Type type, double state) {
25 DCHECK_GE(state, 0); 26 DCHECK_GE(state, 0);
26 DCHECK_LE(state, 1); 27 DCHECK_LE(state, 1);
27 28
28 switch (type) { 29 switch (type) {
29 case EASE_IN: 30 case EASE_IN:
30 return pow(state, 2); 31 return pow(state, 2);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 65
65 case ZERO: 66 case ZERO:
66 return 0; 67 return 0;
67 } 68 }
68 69
69 NOTREACHED(); 70 NOTREACHED();
70 return state; 71 return state;
71 } 72 }
72 73
73 namespace { 74 namespace {
74 uint8 FloatToColorByte(float f) { 75 uint8_t FloatToColorByte(float f) {
75 return base::saturated_cast<uint8>(ToRoundedInt(f * 255.f)); 76 return base::saturated_cast<uint8_t>(ToRoundedInt(f * 255.f));
76 } 77 }
77 78
78 uint8 BlendColorComponents(uint8 start, 79 uint8_t BlendColorComponents(uint8_t start,
79 uint8 target, 80 uint8_t target,
80 float start_alpha, 81 float start_alpha,
81 float target_alpha, 82 float target_alpha,
82 float blended_alpha, 83 float blended_alpha,
83 double progress) { 84 double progress) {
84 // Since progress can be outside [0, 1], blending can produce a value outside 85 // Since progress can be outside [0, 1], blending can produce a value outside
85 // [0, 255]. 86 // [0, 255].
86 float blended_premultiplied = Tween::FloatValueBetween( 87 float blended_premultiplied = Tween::FloatValueBetween(
87 progress, start / 255.f * start_alpha, target / 255.f * target_alpha); 88 progress, start / 255.f * start_alpha, target / 255.f * target_alpha);
88 return FloatToColorByte(blended_premultiplied / blended_alpha); 89 return FloatToColorByte(blended_premultiplied / blended_alpha);
89 } 90 }
90 91
91 } // namespace 92 } // namespace
92 93
93 // static 94 // static
94 SkColor Tween::ColorValueBetween(double value, SkColor start, SkColor target) { 95 SkColor Tween::ColorValueBetween(double value, SkColor start, SkColor target) {
95 float start_a = SkColorGetA(start) / 255.f; 96 float start_a = SkColorGetA(start) / 255.f;
96 float target_a = SkColorGetA(target) / 255.f; 97 float target_a = SkColorGetA(target) / 255.f;
97 float blended_a = FloatValueBetween(value, start_a, target_a); 98 float blended_a = FloatValueBetween(value, start_a, target_a);
98 if (blended_a <= 0.f) 99 if (blended_a <= 0.f)
99 return SkColorSetARGB(0, 0, 0, 0); 100 return SkColorSetARGB(0, 0, 0, 0);
100 blended_a = std::min(blended_a, 1.f); 101 blended_a = std::min(blended_a, 1.f);
101 102
102 uint8 blended_r = BlendColorComponents(SkColorGetR(start), 103 uint8_t blended_r =
103 SkColorGetR(target), 104 BlendColorComponents(SkColorGetR(start), SkColorGetR(target), start_a,
104 start_a, 105 target_a, blended_a, value);
105 target_a, 106 uint8_t blended_g =
106 blended_a, 107 BlendColorComponents(SkColorGetG(start), SkColorGetG(target), start_a,
107 value); 108 target_a, blended_a, value);
108 uint8 blended_g = BlendColorComponents(SkColorGetG(start), 109 uint8_t blended_b =
109 SkColorGetG(target), 110 BlendColorComponents(SkColorGetB(start), SkColorGetB(target), start_a,
110 start_a, 111 target_a, blended_a, value);
111 target_a,
112 blended_a,
113 value);
114 uint8 blended_b = BlendColorComponents(SkColorGetB(start),
115 SkColorGetB(target),
116 start_a,
117 target_a,
118 blended_a,
119 value);
120 112
121 return SkColorSetARGB( 113 return SkColorSetARGB(
122 FloatToColorByte(blended_a), blended_r, blended_g, blended_b); 114 FloatToColorByte(blended_a), blended_r, blended_g, blended_b);
123 } 115 }
124 116
125 // static 117 // static
126 double Tween::DoubleValueBetween(double value, double start, double target) { 118 double Tween::DoubleValueBetween(double value, double start, double target) {
127 return start + (target - start) * value; 119 return start + (target - start) * value;
128 } 120 }
129 121
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (value <= 0.0) 168 if (value <= 0.0)
177 return start_transform; 169 return start_transform;
178 170
179 gfx::Transform to_return = end_transform; 171 gfx::Transform to_return = end_transform;
180 to_return.Blend(start_transform, value); 172 to_return.Blend(start_transform, value);
181 173
182 return to_return; 174 return to_return;
183 } 175 }
184 176
185 } // namespace gfx 177 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/animation/tween.h ('k') | ui/gfx/animation/tween_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698