OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "remoting/client/gl_cursor_feedback.h" | 5 #include "remoting/client/gl_cursor_feedback.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | |
8 #include <array> | 9 #include <array> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "remoting/client/gl_canvas.h" | 12 #include "remoting/client/gl_canvas.h" |
12 #include "remoting/client/gl_cursor_feedback_texture.h" | 13 #include "remoting/client/gl_cursor_feedback_texture.h" |
13 #include "remoting/client/gl_math.h" | 14 #include "remoting/client/gl_math.h" |
14 #include "remoting/client/gl_render_layer.h" | 15 #include "remoting/client/gl_render_layer.h" |
15 #include "remoting/client/gl_texture_ids.h" | 16 #include "remoting/client/gl_texture_ids.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 const float kAnimationDurationMs = 220.f; | 19 |
20 const float kAnimationDurationMs = 300.f; | |
21 | |
22 // progress: [0, 1], indicating the progress of the animation. | |
joedow
2016/08/23 01:27:20
params are referenced like this |progress|. It wo
Yuwei
2016/08/23 01:56:23
Done.
| |
23 // Returns a coefficient ([0, 1]) to be multiplied with the maximum diameter to | |
24 // get the current diameter of the animation. | |
25 float GetExpansionCoeff(float progress) { | |
joedow
2016/08/23 01:27:20
Coeff should be spelled out (GetExpansionCoefficie
Yuwei
2016/08/23 01:56:23
Done.
| |
26 // Decelerating expansion. This is conforming to the material design spec. | |
27 // More time will be spent showing the larger circle and the animation will | |
28 // look more rapid given the same time duration. | |
29 auto get_unnormalized_coeff = [](float progress) { | |
30 static const float expansion_base = 400.f; | |
joedow
2016/08/23 01:27:20
const values should use the same format as above (
Yuwei
2016/08/23 01:56:23
Done.
| |
31 return 1.f - pow(expansion_base, -progress); | |
32 }; | |
33 static const float expansion_normalization = get_unnormalized_coeff(1); | |
34 return get_unnormalized_coeff(progress) / expansion_normalization; | |
35 } | |
36 | |
37 // progress: [0, 1], indicating the progress of the animation. | |
38 // Returns a coefficient ([0, 1]) to be multiplied with the alpha channel of the | |
39 // texture. | |
40 float GetAlphaCoeff(float progress) { | |
joedow
2016/08/23 01:27:20
I don't think this needs to be a separate function
Yuwei
2016/08/23 01:56:23
Done.
| |
41 // Linear fade-out. | |
42 return 1.f - progress; | |
43 } | |
44 | |
19 } // namespace | 45 } // namespace |
20 | 46 |
21 namespace remoting { | 47 namespace remoting { |
22 | 48 |
23 GlCursorFeedback::GlCursorFeedback() {} | 49 GlCursorFeedback::GlCursorFeedback() {} |
24 | 50 |
25 GlCursorFeedback::~GlCursorFeedback() {} | 51 GlCursorFeedback::~GlCursorFeedback() {} |
26 | 52 |
27 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) { | 53 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) { |
28 if (!canvas) { | 54 if (!canvas) { |
(...skipping 18 matching lines...) Expand all Loading... | |
47 if (!layer_ || animation_start_time_.is_null()) { | 73 if (!layer_ || animation_start_time_.is_null()) { |
48 return false; | 74 return false; |
49 } | 75 } |
50 float progress = | 76 float progress = |
51 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / | 77 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / |
52 kAnimationDurationMs; | 78 kAnimationDurationMs; |
53 if (progress > 1) { | 79 if (progress > 1) { |
54 animation_start_time_ = base::TimeTicks(); | 80 animation_start_time_ = base::TimeTicks(); |
55 return false; | 81 return false; |
56 } | 82 } |
57 float diameter = progress * max_diameter_; | 83 float diameter = GetExpansionCoeff(progress) * max_diameter_; |
58 std::array<float, 8> positions; | 84 std::array<float, 8> positions; |
59 FillRectangleVertexPositions(cursor_x_ - diameter / 2, | 85 FillRectangleVertexPositions(cursor_x_ - diameter / 2, |
60 cursor_y_ - diameter / 2, | 86 cursor_y_ - diameter / 2, |
61 diameter, diameter, &positions); | 87 diameter, diameter, &positions); |
62 layer_->SetVertexPositions(positions); | 88 layer_->SetVertexPositions(positions); |
63 layer_->Draw(1.f - progress); | 89 layer_->Draw(GetAlphaCoeff(progress)); |
64 return true; | 90 return true; |
65 } | 91 } |
66 | 92 |
67 } // namespace remoting | 93 } // namespace remoting |
OLD | NEW |