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

Side by Side Diff: remoting/client/gl_cursor.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.h ('k') | remoting/client/gl_cursor_feedback.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.h"
6
7 #include "remoting/base/util.h"
8 #include "remoting/client/gl_canvas.h"
9 #include "remoting/client/gl_math.h"
10 #include "remoting/client/gl_render_layer.h"
11 #include "remoting/proto/control.pb.h"
12 #include "third_party/libyuv/include/libyuv/convert_argb.h"
13
14 namespace remoting {
15
16 namespace {
17
18 // TODO(yuweih): Create separate header file for texture IDs to avoid conflicts.
19 const int kTextureId = 1;
20 const int kDefaultCursorDataSize = 32 * 32 * GlRenderLayer::kBytesPerPixel;
21
22 } // namespace
23
24 GlCursor::GlCursor() {}
25
26 GlCursor::~GlCursor() {}
27
28 void GlCursor::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) {
29 int data_size = cursor_shape.width() * cursor_shape.height() *
30 GlRenderLayer::kBytesPerPixel;
31 if (current_cursor_data_size_ < data_size) {
32 current_cursor_data_size_ =
33 kDefaultCursorDataSize > data_size ? kDefaultCursorDataSize : data_size;
34 current_cursor_data_.reset(new uint8_t[current_cursor_data_size_]);
35 }
36 int stride = cursor_shape.width() * GlRenderLayer::kBytesPerPixel;
37 libyuv::ABGRToARGB(
38 reinterpret_cast<const uint8_t*>(cursor_shape.data().data()), stride,
39 current_cursor_data_.get(), stride, cursor_shape.width(),
40 cursor_shape.height());
41
42 bool size_changed = current_cursor_width_ != cursor_shape.width() ||
43 current_cursor_height_ != cursor_shape.height();
44
45 current_cursor_width_ = cursor_shape.width();
46 current_cursor_height_ = cursor_shape.height();
47 current_cursor_hotspot_x_ = cursor_shape.hotspot_x();
48 current_cursor_hotspot_y_ = cursor_shape.hotspot_y();
49
50 SetCurrentCursorShape(size_changed);
51
52 SetCursorPosition(cursor_x_, cursor_y_);
53 }
54
55 void GlCursor::SetCanvasSize(int width, int height) {
56 canvas_width_ = width;
57 canvas_height_ = height;
58 SetCursorPosition(cursor_x_, cursor_y_);
59 }
60
61 void GlCursor::SetCursorPosition(int x, int y) {
62 cursor_x_ = x;
63 cursor_y_ = y;
64 if (!canvas_width_ || !canvas_height_ || !current_cursor_data_) {
65 return;
66 }
67 std::array<float, 8> positions;
68 FillRectangleVertexPositions(
69 (x - current_cursor_hotspot_x_) / ((float)canvas_width_),
70 (y - current_cursor_hotspot_y_) / ((float)canvas_height_),
71 ((float)current_cursor_width_) / canvas_width_,
72 ((float)current_cursor_height_) / canvas_height_,
73 &positions);
74 if (layer_) {
75 layer_->SetVertexPositions(positions);
76 }
77 }
78
79 void GlCursor::SetCursorVisible(bool visible) {
80 visible_ = visible;
81 }
82
83 void GlCursor::SetCanvas(GlCanvas* canvas) {
84 if (!canvas) {
85 layer_.reset();
86 return;
87 }
88 layer_.reset(new GlRenderLayer(kTextureId, canvas));
89 if (current_cursor_data_) {
90 SetCurrentCursorShape(true);
91 }
92 SetCursorPosition(cursor_x_, cursor_y_);
93 }
94
95 void GlCursor::Draw() {
96 if (layer_ && current_cursor_data_ && visible_) {
97 layer_->Draw(1.f);
98 }
99 }
100
101 void GlCursor::SetCurrentCursorShape(bool size_changed) {
102 if (layer_) {
103 if (size_changed) {
104 layer_->SetTexture(current_cursor_data_.get(), current_cursor_width_,
105 current_cursor_height_);
106 } else {
107 layer_->UpdateTexture(current_cursor_data_.get(), 0, 0,
108 current_cursor_width_, current_cursor_width_, 0);
109 }
110 }
111 }
112
113 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/gl_cursor.h ('k') | remoting/client/gl_cursor_feedback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698