Chromium Code Reviews| Index: media/remoting/remoting_controller.cc |
| diff --git a/media/remoting/remoting_controller.cc b/media/remoting/remoting_controller.cc |
| index 73c372f68673518e429677979a24dbd83fd66864..a5c184e10e0b03ac514fbf90da03aa096557e3c9 100644 |
| --- a/media/remoting/remoting_controller.cc |
| +++ b/media/remoting/remoting_controller.cc |
| @@ -12,6 +12,22 @@ |
| #include "media/remoting/rpc/proto_utils.h" |
| #include "media/remoting/rpc/rpc_broker.h" |
| +namespace { |
| + |
| +float GetVideoViewportRatio(const gfx::Rect& root_rect, |
| + const gfx::Rect& intersect_rect) { |
| + if (root_rect.IsEmpty() || intersect_rect.IsEmpty()) |
| + return 0; |
| + |
| + float intersect_area = static_cast<float>(intersect_rect.width()) * |
| + static_cast<float>(intersect_rect.height()); |
| + float root_area = static_cast<float>(root_rect.width()) * |
| + static_cast<float>(root_rect.height()); |
| + return intersect_area / root_area; |
| +} |
| + |
| +} // namespace |
| + |
| namespace media { |
| RemotingController::RemotingController( |
| @@ -142,6 +158,39 @@ void RemotingController::OnExitedFullscreen() { |
| UpdateAndMaybeSwitch(); |
| } |
| +void RemotingController::OnVideoViewportIntersectionChanged( |
| + const ViewportIntersectionInfo& info) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + |
| + // Reset on any notification, since this indicates the user is scrolling |
| + // around in the document, the document is changing layout, etc. |
| + viewport_fill_debouncer_timer_.Stop(); |
| + |
| + float ratio = GetVideoViewportRatio(info.root_rect, info.intersect_rect); |
| + // Dropping below the threshold should instantly stop remote rendering. |
| + if (ratio < 0.85) { |
|
szager1
2016/11/16 17:53:54
Magic number! Please declare a double kViewportRa
xjz
2016/11/16 20:38:59
Done.
|
| + if (is_mostly_filling_viewport_) { |
| + is_mostly_filling_viewport_ = false; |
| + UpdateAndMaybeSwitch(); |
| + } |
| + return; |
| + } |
| + |
| + // Meeting/Exceeding the threshold should hold steady for 5 seconds before |
| + // starting remote rendering. |
| + if (!is_mostly_filling_viewport_) { |
| + viewport_fill_debouncer_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromSeconds(5), |
| + base::Bind(&RemotingController::OnViewportMostlyFilledAndUnchanging, |
| + weak_factory_.GetWeakPtr())); |
| + } |
| +} |
| + |
| +void RemotingController::OnViewportMostlyFilledAndUnchanging() { |
| + is_mostly_filling_viewport_ = true; |
| + UpdateAndMaybeSwitch(); |
| +} |
| + |
| void RemotingController::OnSetCdm(CdmContext* cdm_context) { |
| DCHECK(task_runner_->BelongsToCurrentThread()); |
| @@ -232,13 +281,11 @@ bool RemotingController::ShouldBeRemoting() { |
| if (!is_sink_available_) |
| return false; |
| - if (!is_fullscreen_) |
| - return false; |
| if (has_video_ && !IsVideoCodecSupported()) |
| return false; |
| if (has_audio_ && !IsAudioCodecSupported()) |
| return false; |
| - return true; |
| + return is_fullscreen_ || is_mostly_filling_viewport_; |
| } |
| void RemotingController::UpdateAndMaybeSwitch() { |