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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/client/gl_cursor_feedback.cc
diff --git a/remoting/client/gl_cursor_feedback.cc b/remoting/client/gl_cursor_feedback.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a3edb7fee4600bc8308d5314d29051bb4b9e169c
--- /dev/null
+++ b/remoting/client/gl_cursor_feedback.cc
@@ -0,0 +1,135 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/client/gl_cursor_feedback.h"
+
+#include <math.h>
+#include <array>
+
+#include "base/logging.h"
+#include "remoting/client/gl_canvas.h"
+#include "remoting/client/gl_math.h"
+#include "remoting/client/gl_render_layer.h"
+#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
+
+namespace {
+
+const int kTextureId = 2;
+const int kColorRingsCount = 4;
+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
+const float kAnimationDurationMs = 220.f;
+
+// RGBA8888 colors. From inside to outside.
+const uint8_t kFeedbackRingColors[kColorRingsCount]
+ [webrtc::DesktopFrame::kBytesPerPixel] = {
+ {0, 0, 0, 0}, // transparent black
+ {0xff, 0xff, 0xff, 0xff}, // white
+ {0, 0, 0, 0xff}, // black
+ {0, 0, 0, 0} // transparent black
+};
+
+const float kFeedbackRadiusStops[kColorRingsCount] = {0.0f, 0.8f, 0.9f, 1.0f};
+
+} // namespace
+
+namespace remoting {
+
+GlCursorFeedback::GlCursorFeedback() {
+}
Sergey Ulanov 2016/07/19 00:42:48 git cl format please
Yuwei 2016/07/19 20:34:23 Done.
+
+GlCursorFeedback::~GlCursorFeedback() {
+}
+
+void GlCursorFeedback::SetCanvas(GlCanvas* canvas) {
+ if (!canvas) {
+ layer_.reset();
+ return;
+ }
+ layer_.reset(new GlRenderLayer(kTextureId, canvas));
+ layer_->SetTexture(GetFeedbackTexture(), kFeedbackTexturePixelDiameter,
+ kFeedbackTexturePixelDiameter);
+}
+
+void GlCursorFeedback::StartAnimation(float normalized_x,
+ float normalized_y,
+ float normalized_width,
+ float normalized_height) {
+ max_width_ = normalized_width;
+ max_height_ = normalized_height;
+ cursor_x_ = normalized_x;
+ cursor_y_ = normalized_y;
+ animation_start_time_ = base::TimeTicks::Now();
+}
+
+bool GlCursorFeedback::Draw() {
+ if (!layer_ || animation_start_time_.is_null()) {
+ return false;
+ }
+ float progress = (base::TimeTicks::Now() - animation_start_time_)
+ .InMilliseconds() / kAnimationDurationMs;
Sergey Ulanov 2016/07/19 00:42:48 git cl format please
Yuwei 2016/07/19 20:34:23 Done.
+ if (progress > 1) {
+ animation_start_time_ = base::TimeTicks();
+ return false;
+ }
+ float width = progress * max_width_;
+ float height = progress * max_height_;
+ std::array<float, 8> positions;
+ FillRectangleVertexPositions(positions, cursor_x_ - width / 2,
+ cursor_y_ - height / 2, width, height);
+ layer_->SetVertexPositions(positions);
+ layer_->Draw(1.f - progress);
+ return true;
+}
+
+void FillColorByRadius(float radius, uint8_t* out) {
+ 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.
+ 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.
+ if (i == kColorRingsCount - 1) {
+ // Area outside the circle. Just use the outermost color.
+ memcpy(out, kFeedbackRingColors[i],
+ webrtc::DesktopFrame::kBytesPerPixel);
+ } else {
+ const uint8_t* first_color = kFeedbackRingColors[i];
+ const uint8_t* second_color = kFeedbackRingColors[i + 1];
+ float first_radius = kFeedbackRadiusStops[i];
+ float second_radius = kFeedbackRadiusStops[i + 1];
+ float interpolation_percentage =
+ (radius - first_radius) / (second_radius - first_radius);
+ LinearInterpolate(out, first_color, second_color,
+ interpolation_percentage,
+ webrtc::DesktopFrame::kBytesPerPixel);
+ }
+ return;
+ }
+ }
+ NOTREACHED();
+}
+
+// static
+const uint8_t* GlCursorFeedback::GetFeedbackTexture() {
+ if (texture_) {
+ return texture_.get();
+ }
+ texture_.reset(new uint8_t[kFeedbackTexturePixelDiameter *
+ kFeedbackTexturePixelDiameter *
+ webrtc::DesktopFrame::kBytesPerPixel]);
+ int pixel_radius = kFeedbackTexturePixelDiameter / 2;
+ 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.
+ for (int y = 0; y < kFeedbackTexturePixelDiameter; y++) {
+ float radius = sqrt((x - pixel_radius) * (x - pixel_radius)
+ + (y - pixel_radius) * (y - pixel_radius))
+ / pixel_radius;
+ uint8_t* current = texture_.get() +
+ (y * kFeedbackTexturePixelDiameter + x) *
+ webrtc::DesktopFrame::kBytesPerPixel;
+ FillColorByRadius(radius, current);
+ }
+ }
+ return texture_.get();
+}
+
+// static
+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.
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698