Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/client/gl_cursor_feedback.h" | |
| 6 | |
| 7 #include <math.h> | |
| 8 #include <array> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "remoting/client/gl_canvas.h" | |
| 12 #include "remoting/client/gl_cursor_feedback_texture.h" | |
| 13 #include "remoting/client/gl_math.h" | |
| 14 #include "remoting/client/gl_render_layer.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const int kTextureId = 2; | |
|
Sergey Ulanov
2016/07/21 19:28:48
maybe not for this CL: would it be useful to have
Yuwei
2016/07/21 21:44:41
Acknowledged. Will send another CL for this.
| |
| 19 const float kAnimationDurationMs = 220.f; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 namespace remoting { | |
| 24 | |
| 25 GlCursorFeedback::GlCursorFeedback() {} | |
| 26 | |
| 27 GlCursorFeedback::~GlCursorFeedback() {} | |
| 28 | |
| 29 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) { | |
| 30 if (!canvas) { | |
| 31 layer_.reset(); | |
| 32 return; | |
| 33 } | |
| 34 layer_.reset(new GlRenderLayer(kTextureId, canvas)); | |
| 35 GlCursorFeedbackTexture* texture = GlCursorFeedbackTexture::GetInstance(); | |
| 36 layer_->SetTexture(texture->GetTexture(), texture->GetTextureDiameter(), | |
| 37 texture->GetTextureDiameter()); | |
| 38 } | |
| 39 | |
| 40 void GlCursorFeedback::StartAnimation(float normalized_x, | |
| 41 float normalized_y, | |
| 42 float normalized_width, | |
| 43 float normalized_height) { | |
| 44 max_width_ = normalized_width; | |
| 45 max_height_ = normalized_height; | |
| 46 cursor_x_ = normalized_x; | |
| 47 cursor_y_ = normalized_y; | |
| 48 animation_start_time_ = base::TimeTicks::Now(); | |
| 49 } | |
| 50 | |
| 51 bool GlCursorFeedback::Draw() { | |
| 52 if (!layer_ || animation_start_time_.is_null()) { | |
| 53 return false; | |
| 54 } | |
| 55 float progress = | |
| 56 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() / | |
| 57 kAnimationDurationMs; | |
| 58 if (progress > 1) { | |
| 59 animation_start_time_ = base::TimeTicks(); | |
| 60 return false; | |
| 61 } | |
| 62 float width = progress * max_width_; | |
| 63 float height = progress * max_height_; | |
| 64 std::array<float, 8> positions; | |
| 65 FillRectangleVertexPositions(cursor_x_ - width / 2, cursor_y_ - height / 2, | |
| 66 width, height, &positions); | |
| 67 layer_->SetVertexPositions(positions); | |
| 68 layer_->Draw(1.f - progress); | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 } // namespace remoting | |
| OLD | NEW |