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