| Index: remoting/client/gl_cursor.cc
|
| diff --git a/remoting/client/gl_cursor.cc b/remoting/client/gl_cursor.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a4fd6eea8544b8865fa191db68538e367cd327d9
|
| --- /dev/null
|
| +++ b/remoting/client/gl_cursor.cc
|
| @@ -0,0 +1,112 @@
|
| +// 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.h"
|
| +
|
| +#include "remoting/base/util.h"
|
| +#include "remoting/client/gl_canvas.h"
|
| +#include "remoting/client/gl_math.h"
|
| +#include "remoting/client/gl_render_layer.h"
|
| +#include "remoting/proto/control.pb.h"
|
| +#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
|
| +
|
| +namespace {
|
| +
|
| +const int kTextureId = 1;
|
| +const int kDefaultCursorDataSize =
|
| + 32 * 32 * webrtc::DesktopFrame::kBytesPerPixel;
|
| +
|
| +} // namespace
|
| +
|
| +namespace remoting {
|
| +
|
| +GlCursor::GlCursor() {
|
| +}
|
| +
|
| +GlCursor::~GlCursor() {
|
| +}
|
| +
|
| +void GlCursor::SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) {
|
| + int data_size = cursor_shape.width() * cursor_shape.height() *
|
| + webrtc::DesktopFrame::kBytesPerPixel;
|
| + if (current_cursor_data_size_ < data_size) {
|
| + current_cursor_data_size_ =
|
| + kDefaultCursorDataSize > data_size ? kDefaultCursorDataSize : data_size;
|
| + current_cursor_data_.reset(new uint8_t[current_cursor_data_size_]);
|
| + }
|
| + CopyAndSwapRB(reinterpret_cast<const uint8_t*>(cursor_shape.data().data()),
|
| + current_cursor_data_.get(), data_size);
|
| +
|
| + bool size_changed = current_cursor_width_ != cursor_shape.width() ||
|
| + current_cursor_height_ != cursor_shape.height();
|
| +
|
| + current_cursor_width_ = cursor_shape.width();
|
| + current_cursor_height_ = cursor_shape.height();
|
| + current_cursor_hotspot_x_ = cursor_shape.hotspot_x();
|
| + current_cursor_hotspot_y_ = cursor_shape.hotspot_y();
|
| +
|
| + SetCurrentCursorShape(size_changed);
|
| +
|
| + SetCursorPosition(cursor_x_, cursor_y_);
|
| +}
|
| +
|
| +void GlCursor::SetCanvasSize(int width, int height) {
|
| + canvas_width_ = width;
|
| + canvas_height_ = height;
|
| + SetCursorPosition(cursor_x_, cursor_y_);
|
| +}
|
| +
|
| +void GlCursor::SetCursorPosition(int x, int y) {
|
| + cursor_x_ = x;
|
| + cursor_y_ = y;
|
| + if (!canvas_width_ || !canvas_height_ || !current_cursor_data_) {
|
| + return;
|
| + }
|
| + std::array<float, 8> positions;
|
| + FillRectangleVertexPositions(
|
| + positions,
|
| + (x - current_cursor_hotspot_x_) / ((float) canvas_width_),
|
| + (y - current_cursor_hotspot_y_) / ((float) canvas_height_),
|
| + ((float) current_cursor_width_) / canvas_width_,
|
| + ((float) current_cursor_height_) / canvas_height_);
|
| + if (layer_) {
|
| + layer_->SetVertexPositions(positions);
|
| + }
|
| +}
|
| +
|
| +void GlCursor::SetCursorVisible(bool visible) {
|
| + visible_ = visible;
|
| +}
|
| +
|
| +void GlCursor::SetCanvas(GlCanvas* canvas) {
|
| + if (!canvas) {
|
| + layer_.reset();
|
| + return;
|
| + }
|
| + layer_.reset(new GlRenderLayer(kTextureId, canvas));
|
| + if (current_cursor_data_) {
|
| + SetCurrentCursorShape(true);
|
| + }
|
| + SetCursorPosition(cursor_x_, cursor_y_);
|
| +}
|
| +
|
| +void GlCursor::Draw() {
|
| + if (layer_ && current_cursor_data_ && visible_) {
|
| + layer_->Draw(1.f);
|
| + }
|
| +}
|
| +
|
| +void GlCursor::SetCurrentCursorShape(bool size_changed) {
|
| + if (layer_) {
|
| + if (size_changed) {
|
| + layer_->SetTexture(current_cursor_data_.get(), current_cursor_width_,
|
| + current_cursor_height_);
|
| + } else {
|
| + layer_->UpdateTexture(current_cursor_data_.get(), 0, 0,
|
| + current_cursor_width_, current_cursor_width_, 0);
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|