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

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: Drop Skia dependencies 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.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 {
15
16 const int kTextureId = 1;
17 const int kDefaultCursorDataSize = 32 * 32 *
18 remoting::GlRenderLayer::kBytesPerPixelRGB32;
19
20 } // namespace
21
22 namespace remoting {
23
24 GlCursor::GlCursor() {}
25
26 GlCursor::~GlCursor() {}
27
28 void GlCursor::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) {
29 int data_size =
30 cursor_shape.width() * cursor_shape.height() *
31 GlRenderLayer::kBytesPerPixelRGB32;
32 if (current_cursor_data_size_ < data_size) {
33 current_cursor_data_size_ =
34 kDefaultCursorDataSize > data_size ? kDefaultCursorDataSize : data_size;
35 current_cursor_data_.reset(new uint8_t[current_cursor_data_size_]);
36 }
37 int stride = cursor_shape.width() * GlRenderLayer::kBytesPerPixelRGB32;
38 libyuv::ABGRToARGB(
39 reinterpret_cast<const uint8_t*>(cursor_shape.data().data()), stride,
40 current_cursor_data_.get(), stride, cursor_shape.width(),
41 cursor_shape.height());
42
43 bool size_changed = current_cursor_width_ != cursor_shape.width() ||
44 current_cursor_height_ != cursor_shape.height();
45
46 current_cursor_width_ = cursor_shape.width();
47 current_cursor_height_ = cursor_shape.height();
48 current_cursor_hotspot_x_ = cursor_shape.hotspot_x();
49 current_cursor_hotspot_y_ = cursor_shape.hotspot_y();
50
51 SetCurrentCursorShape(size_changed);
52
53 SetCursorPosition(cursor_x_, cursor_y_);
54 }
55
56 void GlCursor::SetCanvasSize(int width, int height) {
57 canvas_width_ = width;
58 canvas_height_ = height;
59 SetCursorPosition(cursor_x_, cursor_y_);
60 }
61
62 void GlCursor::SetCursorPosition(int x, int y) {
63 cursor_x_ = x;
64 cursor_y_ = y;
65 if (!canvas_width_ || !canvas_height_ || !current_cursor_data_) {
66 return;
67 }
68 std::array<float, 8> positions;
69 FillRectangleVertexPositions(
70 (x - current_cursor_hotspot_x_) / ((float)canvas_width_),
71 (y - current_cursor_hotspot_y_) / ((float)canvas_height_),
72 ((float)current_cursor_width_) / canvas_width_,
73 ((float)current_cursor_height_) / canvas_height_,
74 &positions);
75 if (layer_) {
76 layer_->SetVertexPositions(positions);
77 }
78 }
79
80 void GlCursor::SetCursorVisible(bool visible) {
81 visible_ = visible;
82 }
83
84 void GlCursor::SetCanvas(GlCanvas* canvas) {
85 if (!canvas) {
86 layer_.reset();
87 return;
88 }
89 layer_.reset(new GlRenderLayer(kTextureId, canvas));
90 if (current_cursor_data_) {
91 SetCurrentCursorShape(true);
92 }
93 SetCursorPosition(cursor_x_, cursor_y_);
94 }
95
96 void GlCursor::Draw() {
97 if (layer_ && current_cursor_data_ && visible_) {
98 layer_->Draw(1.f);
99 }
100 }
101
102 void GlCursor::SetCurrentCursorShape(bool size_changed) {
103 if (layer_) {
104 if (size_changed) {
105 layer_->SetTexture(current_cursor_data_.get(), current_cursor_width_,
106 current_cursor_height_);
107 } else {
108 layer_->UpdateTexture(current_cursor_data_.get(), 0, 0,
109 current_cursor_width_, current_cursor_width_, 0);
110 }
111 }
112 }
113
114 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698