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

Unified Diff: remoting/client/gl_cursor_feedback_texture.cc

Issue 2148743005: [Remoting Android] Cursor & Cursor Feedback for OpenGL Renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move parameters around 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_texture.cc
diff --git a/remoting/client/gl_cursor_feedback_texture.cc b/remoting/client/gl_cursor_feedback_texture.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e33553bcc2d6bed1a0cf25bf77aaab7bac495768
--- /dev/null
+++ b/remoting/client/gl_cursor_feedback_texture.cc
@@ -0,0 +1,124 @@
+// 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_texture.h"
+
+#include "remoting/base/util.h"
+
+namespace {
+
+const int kColorRingsCount = 4;
+const int kFeedbackTexturePixelDiameter = 512;
+const int kFeedbackTexturePixelRadius = kFeedbackTexturePixelDiameter / 2;
+
+// RGBA8888 colors. From inside to outside.
+const uint8_t kFeedbackRingColors[kColorRingsCount]
+ [remoting::kBytesPerPixelRGB32] = {
+ {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 {
+
+void LinearInterpolate(const uint8_t* in1,
Sergey Ulanov 2016/07/20 23:51:40 nit: move to anonymous namespace above.
Yuwei 2016/07/21 01:03:37 Obsolete. Inlined now.
+ const uint8_t* in2,
+ uint8_t* out,
+ int percentage,
Sergey Ulanov 2016/07/20 23:51:40 nit: if you use [0..256] range instead of [0..100]
Yuwei 2016/07/21 01:03:37 Done.
+ int current_dimension) {
+ out[current_dimension] = (in1[current_dimension] * (100 - percentage) +
+ in2[current_dimension] * percentage) / 100;
+}
+
+void FillColorByRadius(float radius, uint32_t* out) {
Sergey Ulanov 2016/07/20 23:51:40 Maybe replace this with uint32_t GetColorByRadius(
Yuwei 2016/07/21 01:03:37 Done.
+ int i;
Sergey Ulanov 2016/07/20 23:51:40 ring_index?
Yuwei 2016/07/21 01:03:37 Done.
+ // Find first radius stop that is not smaller than current radius.
+ for (i = kColorRingsCount - 1; radius < kFeedbackRadiusStops[i] && i >= 0;
Sergey Ulanov 2016/07/20 23:51:40 Use while loop here or move the "radius < kFeedbac
Yuwei 2016/07/21 01:03:37 Done.
+ i--) {
+ }
+
+ if (i < 0) {
+ NOTREACHED();
+ return;
+ }
+
+ if (i == kColorRingsCount - 1) {
+ // Area outside the circle. Just use the outermost color.
+ *out = *reinterpret_cast<const uint32_t*>(kFeedbackRingColors[i]);
+ return;
+ }
+
+ 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];
+
+ int percentage =
+ (radius - first_radius) * 100 / (second_radius - first_radius);
+ uint8_t* byte_out = reinterpret_cast<uint8_t*>(out);
+ LinearInterpolate(first_color, second_color, byte_out, percentage, 0);
Sergey Ulanov 2016/07/20 23:51:40 for loop? Also I don't think you actually need Lin
Yuwei 2016/07/21 01:03:37 Done.
+ LinearInterpolate(first_color, second_color, byte_out, percentage, 1);
+ LinearInterpolate(first_color, second_color, byte_out, percentage, 2);
+ LinearInterpolate(first_color, second_color, byte_out, percentage, 3);
+}
+
+void FillColorMapping(uint32_t* map) {
+ for (int x = 0; x < kFeedbackTexturePixelRadius; x++) {
+ for (int y = 0; y <= x; y++) {
+ float radius =
+ sqrt(x * x + y * y) / kFeedbackTexturePixelRadius;
+ FillColorByRadius(radius, map + x + y * kFeedbackTexturePixelRadius);
Sergey Ulanov 2016/07/20 23:51:40 This code would be simpler if you just set color i
Yuwei 2016/07/21 01:03:37 Done. BTW x and y are related to the center of th
+ }
+ }
+}
+
+void FillFeedbackTexture(uint32_t* texture) {
+ // Color: RGBA8888. Equivalent to the upper part of the forth quadrant.
+ std::unique_ptr<uint32_t[]> coord_color_map(
Sergey Ulanov 2016/07/20 23:51:40 See my comment above. You can iterate over one 8th
Yuwei 2016/07/21 01:03:37 Done. Now it take about 8ms to generate the textur
+ new uint32_t[kFeedbackTexturePixelRadius * kFeedbackTexturePixelRadius]);
+
+ FillColorMapping(coord_color_map.get());
+
+ for (int x = 0; x < kFeedbackTexturePixelDiameter; x++) {
+ for (int y = 0; y < kFeedbackTexturePixelDiameter; y++) {
+ int mapped_x = abs(x - kFeedbackTexturePixelRadius);
+ int mapped_y = abs(y - kFeedbackTexturePixelRadius);
+ if (mapped_x < mapped_y) {
+ int temp_x = mapped_x;
+ mapped_x = mapped_y;
+ mapped_y = temp_x;
+ }
+ texture[x + y * kFeedbackTexturePixelDiameter] =
+ coord_color_map[mapped_x + mapped_y * kFeedbackTexturePixelRadius];
+ }
+ }
+}
+
+GlCursorFeedbackTexture* GlCursorFeedbackTexture::GetInstance() {
+ return base::Singleton<GlCursorFeedbackTexture>::get();
+}
+
+const uint8_t* GlCursorFeedbackTexture::GetTexture() const {
+ return reinterpret_cast<uint8_t*>(texture_.get());
+}
+
+int GlCursorFeedbackTexture::GetTextureDiameter() const {
+ return kFeedbackTexturePixelDiameter;
+}
+
+GlCursorFeedbackTexture::GlCursorFeedbackTexture() :
+ texture_(new uint32_t[kFeedbackTexturePixelDiameter *
Sergey Ulanov 2016/07/20 23:51:40 git cl format please
Yuwei 2016/07/21 01:03:37 Done.
+ kFeedbackTexturePixelDiameter]) {
+ FillFeedbackTexture(texture_.get());
+}
+
+GlCursorFeedbackTexture::~GlCursorFeedbackTexture() {
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698