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 940a4a4778aa2a2c1892c2ecf000dbf53c3a720a..c79af728efed971cb29348df257697839eeba386 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_android.cc |
| +++ b/content/browser/renderer_host/render_widget_host_view_android.cc |
| @@ -148,7 +148,8 @@ RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
| using_delegated_renderer_(CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kEnableDelegatedRenderer) && |
| !CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kDisableDelegatedRenderer)) { |
| + switches::kDisableDelegatedRenderer)), |
| + locks_on_frame_count_(0) { |
| if (!using_delegated_renderer_) { |
| texture_layer_ = cc::TextureLayer::Create(NULL); |
| layer_ = texture_layer_; |
| @@ -286,6 +287,9 @@ bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
| if (texture_size_in_layer_.IsEmpty()) |
| return false; |
| + if (!frame_evictor_->HasFrame()) |
| + return false; |
| + |
| if (using_delegated_renderer_) { |
| if (!delegated_renderer_layer_.get()) |
| return false; |
| @@ -376,16 +380,37 @@ bool RenderWidgetHostViewAndroid::IsShowing() { |
| return is_showing_ && content_view_core_; |
| } |
| -void RenderWidgetHostViewAndroid::LockResources() { |
| +void RenderWidgetHostViewAndroid::LockSurface() { |
| DCHECK(HasValidFrame()); |
| DCHECK(host_); |
| - DCHECK(!host_->is_hidden()); |
| + DCHECK(frame_evictor_->HasFrame()); |
| frame_evictor_->LockFrame(); |
| + locks_on_frame_count_++; |
| } |
| -void RenderWidgetHostViewAndroid::UnlockResources() { |
| +void RenderWidgetHostViewAndroid::UnlockSurface() { |
| + if (!frame_evictor_->HasFrame() || locks_on_frame_count_ == 0) |
| + return; |
| + |
| DCHECK(HasValidFrame()); |
| frame_evictor_->UnlockFrame(); |
| + locks_on_frame_count_--; |
| + |
| + if (locks_on_frame_count_ == 0 && last_frame_info_) { |
| + InternalSwapCompositorFrame(last_frame_info_->output_surface_id, |
| + last_frame_info_->frame.Pass()); |
| + last_frame_info_.reset(); |
| + } |
| +} |
| + |
| +void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { |
| + if (!frame_evictor_->HasFrame()) { |
| + DCHECK_EQ(locks_on_frame_count_, 0u); |
| + return; |
| + } |
| + while (locks_on_frame_count_ > 0) { |
| + UnlockSurface(); |
| + } |
| } |
| gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
| @@ -755,10 +780,9 @@ void RenderWidgetHostViewAndroid::SwapDelegatedFrame( |
| weak_ptr_factory_.GetWeakPtr(), |
| output_surface_id); |
| + ack_callbacks_.push(ack_callback); |
| if (host_->is_hidden()) |
| - ack_callback.Run(); |
| - else |
| - ack_callbacks_.push(ack_callback); |
| + RunAckCallbacks(); |
| } |
| void RenderWidgetHostViewAndroid::ComputeContentsSize( |
| @@ -776,9 +800,15 @@ void RenderWidgetHostViewAndroid::ComputeContentsSize( |
| UpdateAnimationSize(frame_metadata); |
| } |
| -void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| +void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
| uint32 output_surface_id, |
| scoped_ptr<cc::CompositorFrame> frame) { |
| + if (locks_on_frame_count_ > 0) { |
| + DCHECK(HasValidFrame()); |
| + RetainFrame(output_surface_id, frame.Pass()); |
| + return; |
| + } |
| + |
| // Always let ContentViewCore know about the new frame first, so it can decide |
| // to schedule a Draw immediately when it sees the texture layer invalidation. |
| UpdateContentViewCoreFrameMetadata(frame->metadata); |
| @@ -833,6 +863,32 @@ void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| } |
| +void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( |
| + uint32 output_surface_id, |
| + scoped_ptr<cc::CompositorFrame> frame) { |
| + InternalSwapCompositorFrame(output_surface_id, frame.Pass()); |
| +} |
| + |
| +void RenderWidgetHostViewAndroid::RetainFrame( |
| + uint32 output_surface_id, |
| + scoped_ptr<cc::CompositorFrame> frame) { |
| + DCHECK(locks_on_frame_count_); |
| + |
| + // Store the incoming frame so that it can be swapped when all the locks have |
| + // been released. If there is already a stored frame, then send |
| + // acknowledgement and drop it. |
|
no sievers
2014/03/19 19:22:26
nit: comment, 'If there is already a stored frame,
powei
2014/03/19 21:14:08
Done.
|
| + if (last_frame_info_) { |
| + base::Closure ack_callback = |
| + base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
| + weak_ptr_factory_.GetWeakPtr(), |
| + last_frame_info_->output_surface_id); |
| + |
| + ack_callbacks_.push(ack_callback); |
| + } |
| + |
| + last_frame_info_.reset(new LastFrameInfo(output_surface_id, frame.Pass())); |
| +} |
| + |
| void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
| const cc::CompositorFrameMetadata& frame_metadata) { |
| // This is a subset of OnSwapCompositorFrame() used in the synchronous |
| @@ -932,10 +988,9 @@ void RenderWidgetHostViewAndroid::BuffersSwapped( |
| current_mailbox_ = mailbox; |
| last_output_surface_id_ = output_surface_id; |
| + ack_callbacks_.push(ack_callback); |
| if (host_->is_hidden()) |
| - ack_callback.Run(); |
| - else |
| - ack_callbacks_.push(ack_callback); |
| + RunAckCallbacks(); |
| } |
| void RenderWidgetHostViewAndroid::AttachLayers() { |
| @@ -1249,6 +1304,9 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( |
| if (content_view_core_ && !using_synchronous_compositor_) |
| content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
| + if (content_view_core != content_view_core_) |
| + ReleaseLocksOnSurface(); |
| + |
| content_view_core_ = content_view_core; |
| if (GetBrowserAccessibilityManager()) { |
| @@ -1282,6 +1340,7 @@ void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| } |
| void RenderWidgetHostViewAndroid::OnLostResources() { |
| + ReleaseLocksOnSurface(); |
| if (texture_layer_.get()) |
| texture_layer_->SetIsDrawable(false); |
| if (delegated_renderer_layer_.get()) |