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/webrtc/modules/desktop_capture/desktop_frame.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 const int kTextureId = 1; |
| 17 const int kDefaultCursorDataSize = |
| 18 32 * 32 * webrtc::DesktopFrame::kBytesPerPixel; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 namespace remoting { |
| 23 |
| 24 GlCursor::GlCursor() { |
| 25 } |
| 26 |
| 27 GlCursor::~GlCursor() { |
| 28 } |
| 29 |
| 30 void GlCursor::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) { |
| 31 int data_size = cursor_shape.width() * cursor_shape.height() * |
| 32 webrtc::DesktopFrame::kBytesPerPixel; |
| 33 if (current_cursor_data_size_ < data_size) { |
| 34 current_cursor_data_size_ = |
| 35 kDefaultCursorDataSize > data_size ? kDefaultCursorDataSize : data_size; |
| 36 current_cursor_data_.reset(new uint8_t[current_cursor_data_size_]); |
| 37 } |
| 38 CopyAndSwapRB(reinterpret_cast<const uint8_t*>(cursor_shape.data().data()), |
| 39 current_cursor_data_.get(), data_size); |
| 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, |
| 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 if (layer_) { |
| 74 layer_->SetVertexPositions(positions); |
| 75 } |
| 76 } |
| 77 |
| 78 void GlCursor::SetCursorVisible(bool visible) { |
| 79 visible_ = visible; |
| 80 } |
| 81 |
| 82 void GlCursor::SetCanvas(GlCanvas* canvas) { |
| 83 if (!canvas) { |
| 84 layer_.reset(); |
| 85 return; |
| 86 } |
| 87 layer_.reset(new GlRenderLayer(kTextureId, canvas)); |
| 88 if (current_cursor_data_) { |
| 89 SetCurrentCursorShape(true); |
| 90 } |
| 91 SetCursorPosition(cursor_x_, cursor_y_); |
| 92 } |
| 93 |
| 94 void GlCursor::Draw() { |
| 95 if (layer_ && current_cursor_data_ && visible_) { |
| 96 layer_->Draw(1.f); |
| 97 } |
| 98 } |
| 99 |
| 100 void GlCursor::SetCurrentCursorShape(bool size_changed) { |
| 101 if (layer_) { |
| 102 if (size_changed) { |
| 103 layer_->SetTexture(current_cursor_data_.get(), current_cursor_width_, |
| 104 current_cursor_height_); |
| 105 } else { |
| 106 layer_->UpdateTexture(current_cursor_data_.get(), 0, 0, |
| 107 current_cursor_width_, current_cursor_width_, 0); |
| 108 } |
| 109 } |
| 110 } |
| 111 |
| 112 } // namespace remoting |
OLD | NEW |