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

Side by Side Diff: remoting/client/gl_cursor_feedback.cc

Issue 2148743005: [Remoting Android] Cursor & Cursor Feedback for OpenGL Renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 5 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 | « remoting/client/gl_cursor_feedback.h ('k') | remoting/client/gl_cursor_feedback_texture.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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;
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().data(),
37 GlCursorFeedbackTexture::kTextureWidth,
38 GlCursorFeedbackTexture::kTextureWidth);
39 }
40
41 void GlCursorFeedback::StartAnimation(float normalized_x,
42 float normalized_y,
43 float normalized_width,
44 float normalized_height) {
45 max_width_ = normalized_width;
46 max_height_ = normalized_height;
47 cursor_x_ = normalized_x;
48 cursor_y_ = normalized_y;
49 animation_start_time_ = base::TimeTicks::Now();
50 }
51
52 bool GlCursorFeedback::Draw() {
53 if (!layer_ || animation_start_time_.is_null()) {
54 return false;
55 }
56 float progress =
57 (base::TimeTicks::Now() - animation_start_time_).InMilliseconds() /
58 kAnimationDurationMs;
59 if (progress > 1) {
60 animation_start_time_ = base::TimeTicks();
61 return false;
62 }
63 float width = progress * max_width_;
64 float height = progress * max_height_;
65 std::array<float, 8> positions;
66 FillRectangleVertexPositions(cursor_x_ - width / 2, cursor_y_ - height / 2,
67 width, height, &positions);
68 layer_->SetVertexPositions(positions);
69 layer_->Draw(1.f - progress);
70 return true;
71 }
72
73 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/gl_cursor_feedback.h ('k') | remoting/client/gl_cursor_feedback_texture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698