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/display/gl_cursor_feedback.h" | 5 #include "remoting/client/display/gl_cursor_feedback.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <array> | 9 #include <array> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "remoting/client/display/gl_canvas.h" | 12 #include "remoting/client/display/canvas.h" |
13 #include "remoting/client/display/gl_cursor_feedback_texture.h" | 13 #include "remoting/client/display/gl_cursor_feedback_texture.h" |
14 #include "remoting/client/display/gl_math.h" | 14 #include "remoting/client/display/gl_math.h" |
15 #include "remoting/client/display/gl_render_layer.h" | 15 #include "remoting/client/display/gl_render_layer.h" |
16 #include "remoting/client/display/gl_texture_ids.h" | 16 #include "remoting/client/display/gl_texture_ids.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const float kAnimationDurationMs = 300.f; | 20 const float kAnimationDurationMs = 300.f; |
21 | 21 |
22 // This function is for calculating the size of the feedback animation circle at | 22 // This function is for calculating the size of the feedback animation circle at |
(...skipping 13 matching lines...) Expand all Loading... |
36 return 1.f - pow(kExpansionBase, -progress); | 36 return 1.f - pow(kExpansionBase, -progress); |
37 }; | 37 }; |
38 static const float kExpansionNormalization = get_unnormalized_coeff(1); | 38 static const float kExpansionNormalization = get_unnormalized_coeff(1); |
39 return get_unnormalized_coeff(progress) / kExpansionNormalization; | 39 return get_unnormalized_coeff(progress) / kExpansionNormalization; |
40 } | 40 } |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 namespace remoting { | 44 namespace remoting { |
45 | 45 |
46 GlCursorFeedback::GlCursorFeedback() {} | 46 GlCursorFeedback::GlCursorFeedback() : weak_factory_(this) { |
| 47 SetZIndex(DrawableZIndex::CURSOR_FEEDBACK); |
| 48 } |
47 | 49 |
48 GlCursorFeedback::~GlCursorFeedback() {} | 50 GlCursorFeedback::~GlCursorFeedback() {} |
49 | 51 |
50 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) { | 52 void GlCursorFeedback::SetCanvas(base::WeakPtr<Canvas> canvas) { |
51 if (!canvas) { | 53 if (!canvas) { |
52 layer_.reset(); | 54 layer_.reset(); |
53 return; | 55 return; |
54 } | 56 } |
55 layer_.reset(new GlRenderLayer(kGlCursorFeedbackTextureId, canvas)); | 57 layer_.reset(new GlRenderLayer(kGlCursorFeedbackTextureId, canvas)); |
56 GlCursorFeedbackTexture* texture = GlCursorFeedbackTexture::GetInstance(); | 58 GlCursorFeedbackTexture* texture = GlCursorFeedbackTexture::GetInstance(); |
57 layer_->SetTexture(texture->GetTexture().data(), | 59 layer_->SetTexture(texture->GetTexture().data(), |
58 GlCursorFeedbackTexture::kTextureWidth, | 60 GlCursorFeedbackTexture::kTextureWidth, |
59 GlCursorFeedbackTexture::kTextureWidth, 0); | 61 GlCursorFeedbackTexture::kTextureWidth, 0); |
60 } | 62 } |
61 | 63 |
62 void GlCursorFeedback::StartAnimation(float x, float y, float diameter) { | 64 void GlCursorFeedback::StartAnimation(float x, float y, float diameter) { |
63 cursor_x_ = x; | 65 cursor_x_ = x; |
64 cursor_y_ = y; | 66 cursor_y_ = y; |
65 max_diameter_ = diameter; | 67 max_diameter_ = diameter; |
66 animation_start_time_ = base::TimeTicks::Now(); | 68 animation_start_time_ = base::TimeTicks::Now(); |
67 } | 69 } |
68 | 70 |
69 bool GlCursorFeedback::Draw() { | 71 bool GlCursorFeedback::Draw() { |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); |
70 if (!layer_ || animation_start_time_.is_null()) { | 73 if (!layer_ || animation_start_time_.is_null()) { |
71 return false; | 74 return false; |
72 } | 75 } |
73 float progress = | 76 float progress = |
74 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / | 77 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / |
75 kAnimationDurationMs; | 78 kAnimationDurationMs; |
76 if (progress > 1) { | 79 if (progress > 1) { |
77 animation_start_time_ = base::TimeTicks(); | 80 animation_start_time_ = base::TimeTicks(); |
78 return false; | 81 return false; |
79 } | 82 } |
80 float diameter = GetExpansionCoefficient(progress) * max_diameter_; | 83 float diameter = GetExpansionCoefficient(progress) * max_diameter_; |
81 std::array<float, 8> positions; | 84 std::array<float, 8> positions; |
82 FillRectangleVertexPositions(cursor_x_ - diameter / 2, | 85 FillRectangleVertexPositions(cursor_x_ - diameter / 2, |
83 cursor_y_ - diameter / 2, diameter, diameter, | 86 cursor_y_ - diameter / 2, diameter, diameter, |
84 &positions); | 87 &positions); |
85 layer_->SetVertexPositions(positions); | 88 layer_->SetVertexPositions(positions); |
86 | 89 |
87 // Linear fade-out. | 90 // Linear fade-out. |
88 layer_->Draw(1.f - progress); | 91 layer_->Draw(1.f - progress); |
89 return true; | 92 return true; |
90 } | 93 } |
91 | 94 |
| 95 base::WeakPtr<Drawable> GlCursorFeedback::GetWeakPtr() { |
| 96 DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 return weak_factory_.GetWeakPtr(); |
| 98 } |
| 99 |
92 } // namespace remoting | 100 } // namespace remoting |
OLD | NEW |