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

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: Swap BGRA to RGBA 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
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_math.h"
13 #include "remoting/client/gl_render_layer.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
Sergey Ulanov 2016/07/19 00:42:48 I don't think we want to pull this dependency here
Yuwei 2016/07/19 20:34:23 Done. Reuse the one in remoting/base/util
15
16 namespace {
17
18 const int kTextureId = 2;
19 const int kColorRingsCount = 4;
20 const int kFeedbackTexturePixelDiameter = 256;
Sergey Ulanov 2016/07/19 00:42:48 Problem with the way animation is currently implem
Yuwei 2016/07/19 04:11:52 I think the actual problem of the current implemen
Yuwei 2016/07/19 20:34:23 Leaved comment in Java GlDesktopView.
Sergey Ulanov 2016/07/20 18:06:11 SGTM
21 const float kAnimationDurationMs = 220.f;
22
23 // RGBA8888 colors. From inside to outside.
24 const uint8_t kFeedbackRingColors[kColorRingsCount]
25 [webrtc::DesktopFrame::kBytesPerPixel] = {
26 {0, 0, 0, 0}, // transparent black
27 {0xff, 0xff, 0xff, 0xff}, // white
28 {0, 0, 0, 0xff}, // black
29 {0, 0, 0, 0} // transparent black
30 };
31
32 const float kFeedbackRadiusStops[kColorRingsCount] = {0.0f, 0.8f, 0.9f, 1.0f};
33
34 } // namespace
35
36 namespace remoting {
37
38 GlCursorFeedback::GlCursorFeedback() {
39 }
Sergey Ulanov 2016/07/19 00:42:48 git cl format please
Yuwei 2016/07/19 20:34:23 Done.
40
41 GlCursorFeedback::~GlCursorFeedback() {
42 }
43
44 void GlCursorFeedback::SetCanvas(GlCanvas* canvas) {
45 if (!canvas) {
46 layer_.reset();
47 return;
48 }
49 layer_.reset(new GlRenderLayer(kTextureId, canvas));
50 layer_->SetTexture(GetFeedbackTexture(), kFeedbackTexturePixelDiameter,
51 kFeedbackTexturePixelDiameter);
52 }
53
54 void GlCursorFeedback::StartAnimation(float normalized_x,
55 float normalized_y,
56 float normalized_width,
57 float normalized_height) {
58 max_width_ = normalized_width;
59 max_height_ = normalized_height;
60 cursor_x_ = normalized_x;
61 cursor_y_ = normalized_y;
62 animation_start_time_ = base::TimeTicks::Now();
63 }
64
65 bool GlCursorFeedback::Draw() {
66 if (!layer_ || animation_start_time_.is_null()) {
67 return false;
68 }
69 float progress = (base::TimeTicks::Now() - animation_start_time_)
70 .InMilliseconds() / kAnimationDurationMs;
Sergey Ulanov 2016/07/19 00:42:48 git cl format please
Yuwei 2016/07/19 20:34:23 Done.
71 if (progress > 1) {
72 animation_start_time_ = base::TimeTicks();
73 return false;
74 }
75 float width = progress * max_width_;
76 float height = progress * max_height_;
77 std::array<float, 8> positions;
78 FillRectangleVertexPositions(positions, cursor_x_ - width / 2,
79 cursor_y_ - height / 2, width, height);
80 layer_->SetVertexPositions(positions);
81 layer_->Draw(1.f - progress);
82 return true;
83 }
84
85 void FillColorByRadius(float radius, uint8_t* out) {
86 for (int i = kColorRingsCount - 1; i > -1; i--) {
Sergey Ulanov 2016/07/19 00:42:48 i >= 0 instead of i > -1
Yuwei 2016/07/19 20:34:23 Obsolete.
87 if (radius >= kFeedbackRadiusStops[i]) {
Sergey Ulanov 2016/07/19 00:42:48 It would be better to break here and then move the
Yuwei 2016/07/19 20:34:23 Obsolete.
88 if (i == kColorRingsCount - 1) {
89 // Area outside the circle. Just use the outermost color.
90 memcpy(out, kFeedbackRingColors[i],
91 webrtc::DesktopFrame::kBytesPerPixel);
92 } else {
93 const uint8_t* first_color = kFeedbackRingColors[i];
94 const uint8_t* second_color = kFeedbackRingColors[i + 1];
95 float first_radius = kFeedbackRadiusStops[i];
96 float second_radius = kFeedbackRadiusStops[i + 1];
97 float interpolation_percentage =
98 (radius - first_radius) / (second_radius - first_radius);
99 LinearInterpolate(out, first_color, second_color,
100 interpolation_percentage,
101 webrtc::DesktopFrame::kBytesPerPixel);
102 }
103 return;
104 }
105 }
106 NOTREACHED();
107 }
108
109 // static
110 const uint8_t* GlCursorFeedback::GetFeedbackTexture() {
111 if (texture_) {
112 return texture_.get();
113 }
114 texture_.reset(new uint8_t[kFeedbackTexturePixelDiameter *
115 kFeedbackTexturePixelDiameter *
116 webrtc::DesktopFrame::kBytesPerPixel]);
117 int pixel_radius = kFeedbackTexturePixelDiameter / 2;
118 for (int x = 0; x < kFeedbackTexturePixelDiameter; x++) {
Sergey Ulanov 2016/07/19 00:42:48 This code looks like it would be rather slow. It m
Yuwei 2016/07/19 20:34:23 Done. Using Skia.
119 for (int y = 0; y < kFeedbackTexturePixelDiameter; y++) {
120 float radius = sqrt((x - pixel_radius) * (x - pixel_radius)
121 + (y - pixel_radius) * (y - pixel_radius))
122 / pixel_radius;
123 uint8_t* current = texture_.get() +
124 (y * kFeedbackTexturePixelDiameter + x) *
125 webrtc::DesktopFrame::kBytesPerPixel;
126 FillColorByRadius(radius, current);
127 }
128 }
129 return texture_.get();
130 }
131
132 // static
133 std::unique_ptr<uint8_t[]> GlCursorFeedback::texture_;
Sergey Ulanov 2016/07/19 00:42:48 only POD types are allowed for static variables.
Yuwei 2016/07/19 04:11:52 Yeah I don't think it make sense to have a static
Yuwei 2016/07/19 20:34:23 Done.
134
135 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698