Chromium Code Reviews| Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
| diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
| index b4be49a49912a8a43c8bb5920c986ae0f3eff973..d0106acfcf0f96d6c8d4ec71562691c1e6c87489 100644 |
| --- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
| +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
| @@ -92,35 +92,6 @@ using WebKit::WebTouchEvent; |
| namespace content { |
| -void ReleaseMailbox(scoped_refptr<MemoryHolder> holder, |
| - unsigned sync_point, |
| - bool lost_resource) {} |
| - |
| -class MemoryHolder : public base::RefCounted<MemoryHolder> { |
| - public: |
| - MemoryHolder(scoped_ptr<base::SharedMemory> shared_memory, |
| - gfx::Size frame_size, |
| - base::Callback<void()> callback) |
| - : shared_memory_(shared_memory.Pass()), |
| - frame_size_(frame_size), |
| - callback_(callback) {} |
| - |
| - void GetMailbox(cc::TextureMailbox* mailbox, |
| - scoped_ptr<cc::SingleReleaseCallback>* release_callback) { |
| - *mailbox = cc::TextureMailbox(shared_memory_.get(), frame_size_); |
| - *release_callback = cc::SingleReleaseCallback::Create( |
| - base::Bind(ReleaseMailbox, make_scoped_refptr(this))); |
| - } |
| - |
| - private: |
| - friend class base::RefCounted<MemoryHolder>; |
| - ~MemoryHolder() { callback_.Run(); } |
| - |
| - scoped_ptr<base::SharedMemory> shared_memory_; |
| - gfx::Size frame_size_; |
| - base::Callback<void()> callback_; |
| -}; |
| - |
| namespace { |
| void MailboxReleaseCallback(scoped_ptr<base::SharedMemory> shared_memory, |
| @@ -592,6 +563,8 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) |
| text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| can_compose_inline_(true), |
| has_composition_text_(false), |
| + software_framebuffer_(new SoftwareFramebuffer( |
| + this, RenderWidgetHostImpl::From(host))), |
| last_output_surface_id_(0), |
| skipped_frames_(false), |
| last_swapped_surface_scale_factor_(1.f), |
| @@ -696,8 +669,7 @@ void RenderWidgetHostViewAura::WasShown() { |
| if (!host_->is_hidden()) |
| return; |
| host_->WasShown(); |
| - if (framebuffer_holder_) |
| - FrameMemoryManager::GetInstance()->SetFrameVisibility(this, true); |
| + software_framebuffer_->WasShown(); |
| aura::RootWindow* root = window_->GetRootWindow(); |
| if (root) { |
| @@ -725,8 +697,7 @@ void RenderWidgetHostViewAura::WasHidden() { |
| if (!host_ || host_->is_hidden()) |
| return; |
| host_->WasHidden(); |
| - if (framebuffer_holder_) |
| - FrameMemoryManager::GetInstance()->SetFrameVisibility(this, false); |
| + software_framebuffer_->WasHidden(); |
| released_front_lock_ = NULL; |
| @@ -1286,12 +1257,12 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { |
| current_frame_size_ = ConvertSizeToDIP( |
| current_surface_->device_scale_factor(), current_surface_->size()); |
| CheckResizeLock(); |
| - framebuffer_holder_ = NULL; |
| - FrameMemoryManager::GetInstance()->RemoveFrame(this); |
| - } else if (is_compositing_active && framebuffer_holder_) { |
| + software_framebuffer_->DiscardCurrentFrame(); |
| + } else if (is_compositing_active && |
| + software_framebuffer_->HasCurrentFrame()) { |
| cc::TextureMailbox mailbox; |
| scoped_ptr<cc::SingleReleaseCallback> callback; |
| - framebuffer_holder_->GetMailbox(&mailbox, &callback); |
| + software_framebuffer_->GetCurrentFrameMailbox(&mailbox, &callback); |
| window_->layer()->SetTextureMailbox(mailbox, |
| callback.Pass(), |
| last_swapped_surface_scale_factor_); |
| @@ -1302,8 +1273,7 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() { |
| window_->layer()->SetShowPaintedContent(); |
| resize_lock_.reset(); |
| host_->WasResized(); |
| - framebuffer_holder_ = NULL; |
| - FrameMemoryManager::GetInstance()->RemoveFrame(this); |
| + software_framebuffer_->DiscardCurrentFrame(); |
| } |
| } |
| @@ -1438,8 +1408,7 @@ void RenderWidgetHostViewAura::SwapDelegatedFrame( |
| gfx::Rect damage_rect_in_dip = |
| ConvertRectToDIP(frame_device_scale_factor, damage_rect); |
| - framebuffer_holder_ = NULL; |
| - FrameMemoryManager::GetInstance()->RemoveFrame(this); |
| + software_framebuffer_->DiscardCurrentFrame(); |
| if (ShouldSkipFrame(frame_size_in_dip)) { |
| cc::CompositorFrameAck ack; |
| @@ -1519,23 +1488,18 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame( |
| gfx::Size frame_size_in_dip = |
| ConvertSizeToDIP(frame_device_scale_factor, frame_size); |
| if (ShouldSkipFrame(frame_size_in_dip)) { |
| - ReleaseSoftwareFrame(output_surface_id, frame_data->id); |
| - SendSoftwareFrameAck(output_surface_id); |
| + software_framebuffer_->ReleaseSoftwareFrame(output_surface_id, |
| + frame_data->id); |
| + software_framebuffer_->SendSoftwareFrameAck(output_surface_id); |
| return; |
| } |
| - const size_t size_in_bytes = 4 * frame_size.GetArea(); |
| -#ifdef OS_WIN |
| - scoped_ptr<base::SharedMemory> shared_memory( |
| - new base::SharedMemory(frame_data->handle, true, |
| - host_->GetProcess()->GetHandle())); |
| -#else |
| - scoped_ptr<base::SharedMemory> shared_memory( |
| - new base::SharedMemory(frame_data->handle, true)); |
| -#endif |
| + software_framebuffer_->SwapToNewFrame( |
|
ccameron
2013/10/03 21:46:00
This is a functional change, in that we have fused
piman
2013/10/08 02:58:38
Can the eviction cause re-entrancy? Is that ok?
Ca
ccameron
2013/10/22 07:15:55
The potentialy re-entrancy seemed too iffy... chan
|
| + output_surface_id, frame_data.get(), frame_device_scale_factor); |
| - if (!shared_memory->Map(size_in_bytes)) { |
| - host_->GetProcess()->ReceivedBadMessage(); |
| + // The frame may have immediately evicted if this view is not visible. |
| + if (!software_framebuffer_->HasCurrentFrame()) { |
| + software_framebuffer_->SendSoftwareFrameAck(output_surface_id); |
| return; |
| } |
| @@ -1546,17 +1510,9 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame( |
| last_swapped_surface_size_ = frame_size; |
| last_swapped_surface_scale_factor_ = frame_device_scale_factor; |
| - scoped_refptr<MemoryHolder> holder(new MemoryHolder( |
| - shared_memory.Pass(), |
| - frame_size, |
| - base::Bind(&RenderWidgetHostViewAura::ReleaseSoftwareFrame, |
| - AsWeakPtr(), |
| - output_surface_id, |
| - frame_data->id))); |
| - framebuffer_holder_.swap(holder); |
| cc::TextureMailbox mailbox; |
| scoped_ptr<cc::SingleReleaseCallback> callback; |
| - framebuffer_holder_->GetMailbox(&mailbox, &callback); |
| + software_framebuffer_->GetCurrentFrameMailbox(&mailbox, &callback); |
| DCHECK(mailbox.IsSharedMemory()); |
| current_frame_size_ = frame_size_in_dip; |
| @@ -1572,54 +1528,13 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame( |
| if (compositor) { |
| compositor->SetLatencyInfo(latency_info); |
| AddOnCommitCallbackAndDisableLocks( |
| - base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, |
| - AsWeakPtr(), |
| + base::Bind(&SoftwareFramebuffer::SendSoftwareFrameAck, |
| + software_framebuffer_->AsWeakPtr(), |
| output_surface_id)); |
| } |
| if (paint_observer_) |
| paint_observer_->OnUpdateCompositorContent(); |
| DidReceiveFrameFromRenderer(); |
| - FrameMemoryManager::GetInstance()->AddFrame(this, !host_->is_hidden()); |
| -} |
| - |
| -void RenderWidgetHostViewAura::SendSoftwareFrameAck(uint32 output_surface_id) { |
| - unsigned software_frame_id = 0; |
| - if (!released_software_frames_.empty()) { |
| - unsigned released_output_surface_id = |
| - released_software_frames_.back().output_surface_id; |
| - if (released_output_surface_id == output_surface_id) { |
| - software_frame_id = released_software_frames_.back().frame_id; |
| - released_software_frames_.pop_back(); |
| - } |
| - } |
| - |
| - cc::CompositorFrameAck ack; |
| - ack.last_software_frame_id = software_frame_id; |
| - RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| - host_->GetRoutingID(), output_surface_id, |
| - host_->GetProcess()->GetID(), ack); |
| - SendReclaimSoftwareFrames(); |
| -} |
| - |
| -void RenderWidgetHostViewAura::SendReclaimSoftwareFrames() { |
| - while (!released_software_frames_.empty()) { |
| - cc::CompositorFrameAck ack; |
| - ack.last_software_frame_id = released_software_frames_.back().frame_id; |
| - RenderWidgetHostImpl::SendReclaimCompositorResources( |
| - host_->GetRoutingID(), |
| - released_software_frames_.back().output_surface_id, |
| - host_->GetProcess()->GetID(), |
| - ack); |
| - released_software_frames_.pop_back(); |
| - } |
| -} |
| - |
| -void RenderWidgetHostViewAura::ReleaseSoftwareFrame( |
| - uint32 output_surface_id, |
| - unsigned software_frame_id) { |
| - SendReclaimSoftwareFrames(); |
| - released_software_frames_.push_back( |
| - ReleasedFrameInfo(output_surface_id, software_frame_id)); |
| } |
| void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
| @@ -1689,8 +1604,7 @@ void RenderWidgetHostViewAura::BuffersSwapped( |
| const BufferPresentedCallback& ack_callback) { |
| scoped_refptr<ui::Texture> previous_texture(current_surface_); |
| const gfx::Rect surface_rect = gfx::Rect(surface_size); |
| - framebuffer_holder_ = NULL; |
| - FrameMemoryManager::GetInstance()->RemoveFrame(this); |
| + software_framebuffer_->DiscardCurrentFrame(); |
| if (!SwapBuffersPrepare(surface_rect, |
| surface_scale_factor, |
| @@ -2994,16 +2908,17 @@ void RenderWidgetHostViewAura::OnRootWindowHostMoved( |
| UpdateScreenInfo(window_); |
| } |
| -void RenderWidgetHostViewAura::ReleaseCurrentFrame() { |
|
ccameron
2013/10/03 21:46:00
This is a functional change in that we now ignore
|
| - if (framebuffer_holder_.get() && !current_surface_.get()) { |
| - framebuffer_holder_ = NULL; |
| - ui::Compositor* compositor = GetCompositor(); |
| - if (compositor) { |
| - AddOnCommitCallbackAndDisableLocks(base::Bind( |
| - &RenderWidgetHostViewAura::SendReclaimSoftwareFrames, AsWeakPtr())); |
| - } |
| - UpdateExternalTexture(); |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// RenderWidgetHostViewAura, SoftwareFramebufferClient implementation: |
| + |
| +void RenderWidgetHostViewAura::CurrentSoftwareFrameWasDiscarded() { |
| + ui::Compositor* compositor = GetCompositor(); |
| + if (compositor) { |
| + AddOnCommitCallbackAndDisableLocks(base::Bind( |
| + &SoftwareFramebuffer::SendReclaimSoftwareFrames, |
| + software_framebuffer_->AsWeakPtr())); |
| } |
| + UpdateExternalTexture(); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -3177,10 +3092,6 @@ RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| // Aura root window and we don't have a way to get an input method object |
| // associated with the window, but just in case. |
| DetachFromInputMethod(); |
| - FrameMemoryManager::GetInstance()->RemoveFrame(this); |
| - // The destruction of the holder may call back into the RWHVA, so do it |
| - // early. |
| - framebuffer_holder_ = NULL; |
|
ccameron
2013/10/03 21:46:00
The SoftwareFramebuffer destructor un-sets is back
|
| } |
| void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() { |