| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/mouse_shape_pump.h" | 5 #include "remoting/host/mouse_shape_pump.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "remoting/proto/control.pb.h" | 12 #include "remoting/proto/control.pb.h" |
| 13 #include "remoting/protocol/cursor_shape_stub.h" | 13 #include "remoting/protocol/cursor_shape_stub.h" |
| 14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 15 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" | 15 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" |
| 16 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h" | 16 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 // Poll mouse shape 10 times a second. | 20 // Poll mouse shape 10 times a second. |
| 21 static const int kCursorCaptureIntervalMs = 100; | 21 static const int kCursorCaptureIntervalMs = 100; |
| 22 | 22 |
| 23 MouseShapePump::MouseShapePump( | 23 MouseShapePump::MouseShapePump( |
| 24 scoped_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor, | 24 std::unique_ptr<webrtc::MouseCursorMonitor> mouse_cursor_monitor, |
| 25 protocol::CursorShapeStub* cursor_shape_stub) | 25 protocol::CursorShapeStub* cursor_shape_stub) |
| 26 : mouse_cursor_monitor_(std::move(mouse_cursor_monitor)), | 26 : mouse_cursor_monitor_(std::move(mouse_cursor_monitor)), |
| 27 cursor_shape_stub_(cursor_shape_stub), | 27 cursor_shape_stub_(cursor_shape_stub), |
| 28 capture_timer_(true, true) { | 28 capture_timer_(true, true) { |
| 29 mouse_cursor_monitor_->Init(this, webrtc::MouseCursorMonitor::SHAPE_ONLY); | 29 mouse_cursor_monitor_->Init(this, webrtc::MouseCursorMonitor::SHAPE_ONLY); |
| 30 capture_timer_.Start( | 30 capture_timer_.Start( |
| 31 FROM_HERE, base::TimeDelta::FromMilliseconds(kCursorCaptureIntervalMs), | 31 FROM_HERE, base::TimeDelta::FromMilliseconds(kCursorCaptureIntervalMs), |
| 32 base::Bind(&MouseShapePump::Capture, base::Unretained(this))); | 32 base::Bind(&MouseShapePump::Capture, base::Unretained(this))); |
| 33 } | 33 } |
| 34 | 34 |
| 35 MouseShapePump::~MouseShapePump() {} | 35 MouseShapePump::~MouseShapePump() {} |
| 36 | 36 |
| 37 void MouseShapePump::Capture() { | 37 void MouseShapePump::Capture() { |
| 38 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
| 39 | 39 |
| 40 mouse_cursor_monitor_->Capture(); | 40 mouse_cursor_monitor_->Capture(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void MouseShapePump::OnMouseCursor(webrtc::MouseCursor* cursor) { | 43 void MouseShapePump::OnMouseCursor(webrtc::MouseCursor* cursor) { |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 | 45 |
| 46 scoped_ptr<webrtc::MouseCursor> owned_cursor(cursor); | 46 std::unique_ptr<webrtc::MouseCursor> owned_cursor(cursor); |
| 47 | 47 |
| 48 scoped_ptr<protocol::CursorShapeInfo> cursor_proto( | 48 std::unique_ptr<protocol::CursorShapeInfo> cursor_proto( |
| 49 new protocol::CursorShapeInfo()); | 49 new protocol::CursorShapeInfo()); |
| 50 cursor_proto->set_width(cursor->image()->size().width()); | 50 cursor_proto->set_width(cursor->image()->size().width()); |
| 51 cursor_proto->set_height(cursor->image()->size().height()); | 51 cursor_proto->set_height(cursor->image()->size().height()); |
| 52 cursor_proto->set_hotspot_x(cursor->hotspot().x()); | 52 cursor_proto->set_hotspot_x(cursor->hotspot().x()); |
| 53 cursor_proto->set_hotspot_y(cursor->hotspot().y()); | 53 cursor_proto->set_hotspot_y(cursor->hotspot().y()); |
| 54 | 54 |
| 55 cursor_proto->set_data(std::string()); | 55 cursor_proto->set_data(std::string()); |
| 56 uint8_t* current_row = cursor->image()->data(); | 56 uint8_t* current_row = cursor->image()->data(); |
| 57 for (int y = 0; y < cursor->image()->size().height(); ++y) { | 57 for (int y = 0; y < cursor->image()->size().height(); ++y) { |
| 58 cursor_proto->mutable_data()->append( | 58 cursor_proto->mutable_data()->append( |
| 59 current_row, | 59 current_row, |
| 60 current_row + cursor->image()->size().width() * | 60 current_row + cursor->image()->size().width() * |
| 61 webrtc::DesktopFrame::kBytesPerPixel); | 61 webrtc::DesktopFrame::kBytesPerPixel); |
| 62 current_row += cursor->image()->stride(); | 62 current_row += cursor->image()->stride(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 cursor_shape_stub_->SetCursorShape(*cursor_proto); | 65 cursor_shape_stub_->SetCursorShape(*cursor_proto); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void MouseShapePump::OnMouseCursorPosition( | 68 void MouseShapePump::OnMouseCursorPosition( |
| 69 webrtc::MouseCursorMonitor::CursorState state, | 69 webrtc::MouseCursorMonitor::CursorState state, |
| 70 const webrtc::DesktopVector& position) { | 70 const webrtc::DesktopVector& position) { |
| 71 // We're not subscribing to mouse position changes. | 71 // We're not subscribing to mouse position changes. |
| 72 NOTREACHED(); | 72 NOTREACHED(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace remoting | 75 } // namespace remoting |
| OLD | NEW |