Chromium Code Reviews| Index: content/browser/renderer_host/render_widget_host_view_android.cc |
| diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc |
| index dd65887f78db5d47ad01b2adc5b5da168d243a18..f587c252d7dbd6fd14e97a719040c0ccb97658b9 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_android.cc |
| +++ b/content/browser/renderer_host/render_widget_host_view_android.cc |
| @@ -201,9 +201,9 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| using_synchronous_compositor_(SynchronousCompositorImpl::FromID( |
| widget_host->GetProcess()->GetID(), |
| widget_host->GetRoutingID()) != NULL), |
| + vsync_subscribers_bitmask_(0), |
| frame_evictor_(new DelegatedFrameEvictor(this)), |
| - locks_on_frame_count_(0), |
| - observing_root_window_(false) { |
| + locks_on_frame_count_(0) { |
| host_->SetView(this); |
| SetContentViewCore(content_view_core); |
| ImageTransportFactoryAndroid::AddObserver(this); |
| @@ -260,9 +260,8 @@ void RenderWidgetHostViewAndroid::WasShown() { |
| host_->WasShown(ui::LatencyInfo()); |
| if (content_view_core_ && !using_synchronous_compositor_) { |
| - content_view_core_->GetWindowAndroid()->AddObserver(this); |
| + SubscribeToVSync(INPUT | BEGIN_FRAME); |
| content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
| - observing_root_window_ = true; |
| } |
| } |
| @@ -276,10 +275,8 @@ void RenderWidgetHostViewAndroid::WasHidden() { |
| // utilization. |
| host_->WasHidden(); |
| - if (content_view_core_ && !using_synchronous_compositor_) { |
| - content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
| - observing_root_window_ = false; |
| - } |
| + if (content_view_core_ && !using_synchronous_compositor_) |
| + UnsubscribeToVSync(INPUT | BEGIN_FRAME); |
|
jdduke (slow)
2014/08/20 04:11:53
Hmm, this isn't quite what I had in mind. I was th
hush (inactive)
2014/08/20 18:06:50
I see.
I will remove |flush_input_requested_| and
|
| } |
| void RenderWidgetHostViewAndroid::WasResized() { |
| @@ -811,6 +808,10 @@ void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( |
| scoped_ptr<SyntheticGestureTarget> |
| RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { |
| + DCHECK(content_view_core_); |
| + if (using_synchronous_compositor_) |
| + SubscribeToVSync(INPUT); |
| + |
| return scoped_ptr<SyntheticGestureTarget>(new SyntheticGestureTargetAndroid( |
| host_, content_view_core_->CreateTouchEventSynthesizer())); |
| } |
| @@ -1440,10 +1441,8 @@ void RenderWidgetHostViewAndroid::DidStopFlinging() { |
| void RenderWidgetHostViewAndroid::SetContentViewCore( |
| ContentViewCoreImpl* content_view_core) { |
| RemoveLayers(); |
| - if (observing_root_window_ && content_view_core_) { |
| - content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
| - observing_root_window_ = false; |
| - } |
| + if (vsync_subscribers_bitmask_ && content_view_core_) |
| + UnsubscribeToVSync(INPUT | BEGIN_FRAME); |
| bool resize = false; |
| if (content_view_core != content_view_core_) { |
| @@ -1470,8 +1469,7 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( |
| return; |
| if (!using_synchronous_compositor_) { |
| - content_view_core_->GetWindowAndroid()->AddObserver(this); |
| - observing_root_window_ = true; |
| + SubscribeToVSync(INPUT | BEGIN_FRAME); |
| if (needs_begin_frame_) |
| content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
| } |
| @@ -1518,17 +1516,36 @@ void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| RunAckCallbacks(); |
| } |
| +void RenderWidgetHostViewAndroid::SubscribeToVSync(uint32 type) { |
| + if (!vsync_subscribers_bitmask_) |
| + content_view_core_->GetWindowAndroid()->AddObserver(this); |
| + |
| + vsync_subscribers_bitmask_ |= type; |
| + // Synchronous compositor does not request begin frames OnVSync. |
| + DCHECK(!using_synchronous_compositor_ || |
| + !(vsync_subscribers_bitmask_ & BEGIN_FRAME)); |
| +} |
| + |
| +void RenderWidgetHostViewAndroid::UnsubscribeToVSync(uint32 type) { |
| + vsync_subscribers_bitmask_ &= ~type; |
| + if (!vsync_subscribers_bitmask_) |
| + content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
| +} |
| + |
| void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, |
| base::TimeDelta vsync_period) { |
| TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync"); |
| if (!host_) |
| return; |
| - if (flush_input_requested_) { |
| + if (vsync_subscribers_bitmask_ & INPUT & flush_input_requested_) { |
| flush_input_requested_ = false; |
| host_->FlushInput(); |
| } |
| + if (!(vsync_subscribers_bitmask_ & BEGIN_FRAME)) |
| + return; |
| + |
| TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); |
| base::TimeTicks display_time = frame_time + vsync_period; |