| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/desktop_session_agent.h" | 5 #include "remoting/host/desktop_session_agent.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
| 10 #include "ipc/ipc_message.h" | 10 #include "ipc/ipc_message.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { | 78 bool DesktopSessionAgent::OnMessageReceived(const IPC::Message& message) { |
| 79 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 79 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 80 | 80 |
| 81 bool handled = true; | 81 bool handled = true; |
| 82 if (started_) { | 82 if (started_) { |
| 83 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) | 83 IPC_BEGIN_MESSAGE_MAP(DesktopSessionAgent, message) |
| 84 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, | 84 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_CaptureFrame, |
| 85 OnCaptureFrame) | 85 OnCaptureFrame) |
| 86 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InvalidateRegion, | |
| 87 OnInvalidateRegion) | |
| 88 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SharedBufferCreated, | 86 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SharedBufferCreated, |
| 89 OnSharedBufferCreated) | 87 OnSharedBufferCreated) |
| 90 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectClipboardEvent, | 88 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectClipboardEvent, |
| 91 OnInjectClipboardEvent) | 89 OnInjectClipboardEvent) |
| 92 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent, | 90 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectKeyEvent, |
| 93 OnInjectKeyEvent) | 91 OnInjectKeyEvent) |
| 94 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent, | 92 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_InjectMouseEvent, |
| 95 OnInjectMouseEvent) | 93 OnInjectMouseEvent) |
| 96 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution, | 94 IPC_MESSAGE_HANDLER(ChromotingNetworkDesktopMsg_SetScreenResolution, |
| 97 SetScreenResolution) | 95 SetScreenResolution) |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 350 } |
| 353 | 351 |
| 354 // media::ScreenCapturer supports a very few (currently 2) outstanding capture | 352 // media::ScreenCapturer supports a very few (currently 2) outstanding capture |
| 355 // requests. The requests are serialized on |video_capture_task_runner()| task | 353 // requests. The requests are serialized on |video_capture_task_runner()| task |
| 356 // runner. If the client issues more requests, pixel data in captured frames | 354 // runner. If the client issues more requests, pixel data in captured frames |
| 357 // will likely be corrupted but stability of media::ScreenCapturer will not be | 355 // will likely be corrupted but stability of media::ScreenCapturer will not be |
| 358 // affected. | 356 // affected. |
| 359 video_capturer_->CaptureFrame(); | 357 video_capturer_->CaptureFrame(); |
| 360 } | 358 } |
| 361 | 359 |
| 362 void DesktopSessionAgent::OnInvalidateRegion( | |
| 363 const std::vector<SkIRect>& invalid_rects) { | |
| 364 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | |
| 365 video_capture_task_runner()->PostTask( | |
| 366 FROM_HERE, | |
| 367 base::Bind(&DesktopSessionAgent::OnInvalidateRegion, this, | |
| 368 invalid_rects)); | |
| 369 return; | |
| 370 } | |
| 371 | |
| 372 SkIRect bounds = SkIRect::MakeSize(current_size_); | |
| 373 | |
| 374 // Convert |invalid_rects| into a region. | |
| 375 SkRegion invalid_region; | |
| 376 for (std::vector<SkIRect>::const_iterator i = invalid_rects.begin(); | |
| 377 i != invalid_rects.end(); ++i) { | |
| 378 // Validate each rectange and clip it to the frame bounds. | |
| 379 SkIRect rect; | |
| 380 if (rect.intersect(*i, bounds)) { | |
| 381 invalid_region.op(rect, SkRegion::kUnion_Op); | |
| 382 } | |
| 383 } | |
| 384 | |
| 385 video_capturer_->InvalidateRegion(invalid_region); | |
| 386 } | |
| 387 | |
| 388 void DesktopSessionAgent::OnSharedBufferCreated(int id) { | 360 void DesktopSessionAgent::OnSharedBufferCreated(int id) { |
| 389 if (!video_capture_task_runner()->BelongsToCurrentThread()) { | 361 if (!video_capture_task_runner()->BelongsToCurrentThread()) { |
| 390 video_capture_task_runner()->PostTask( | 362 video_capture_task_runner()->PostTask( |
| 391 FROM_HERE, | 363 FROM_HERE, |
| 392 base::Bind(&DesktopSessionAgent::OnSharedBufferCreated, this, id)); | 364 base::Bind(&DesktopSessionAgent::OnSharedBufferCreated, this, id)); |
| 393 return; | 365 return; |
| 394 } | 366 } |
| 395 | 367 |
| 396 // Drop the cached reference to the buffer. | 368 // Drop the cached reference to the buffer. |
| 397 SharedBuffers::iterator i = shared_buffers_.begin(); | 369 SharedBuffers::iterator i = shared_buffers_.begin(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 void DesktopSessionAgent::StartVideoCapturer() { | 466 void DesktopSessionAgent::StartVideoCapturer() { |
| 495 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 467 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 496 | 468 |
| 497 if (video_capturer_) | 469 if (video_capturer_) |
| 498 video_capturer_->Start(this); | 470 video_capturer_->Start(this); |
| 499 } | 471 } |
| 500 | 472 |
| 501 void DesktopSessionAgent::StopVideoCapturer() { | 473 void DesktopSessionAgent::StopVideoCapturer() { |
| 502 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); | 474 DCHECK(video_capture_task_runner()->BelongsToCurrentThread()); |
| 503 | 475 |
| 504 if (video_capturer_) { | 476 video_capturer_.reset(); |
| 505 video_capturer_->Stop(); | |
| 506 video_capturer_.reset(); | |
| 507 } | |
| 508 | 477 |
| 509 // Free any shared buffers left. | 478 // Free any shared buffers left. |
| 510 shared_buffers_.clear(); | 479 shared_buffers_.clear(); |
| 511 } | 480 } |
| 512 | 481 |
| 513 DesktopSessionAgent::DesktopSessionAgent( | 482 DesktopSessionAgent::DesktopSessionAgent( |
| 514 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, | 483 scoped_refptr<AutoThreadTaskRunner> audio_capture_task_runner, |
| 515 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 484 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
| 516 scoped_refptr<AutoThreadTaskRunner> input_task_runner, | 485 scoped_refptr<AutoThreadTaskRunner> input_task_runner, |
| 517 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 486 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 537 base::ClosePlatformFile(desktop_pipe_.fd); | 506 base::ClosePlatformFile(desktop_pipe_.fd); |
| 538 #else // !defined(OS_POSIX) | 507 #else // !defined(OS_POSIX) |
| 539 #error Unsupported platform. | 508 #error Unsupported platform. |
| 540 #endif // !defined(OS_POSIX) | 509 #endif // !defined(OS_POSIX) |
| 541 | 510 |
| 542 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); | 511 desktop_pipe_ = IPC::InvalidPlatformFileForTransit(); |
| 543 } | 512 } |
| 544 } | 513 } |
| 545 | 514 |
| 546 } // namespace remoting | 515 } // namespace remoting |
| OLD | NEW |