Chromium Code Reviews| Index: content/renderer/render_widget.cc |
| diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc |
| index 5c82eda23832f6bf500bb5cb2975ce53e2c71cbd..ce4988a0d4a0f6568d150da1908d424eacb9112f 100644 |
| --- a/content/renderer/render_widget.cc |
| +++ b/content/renderer/render_widget.cc |
| @@ -36,6 +36,7 @@ |
| #include "content/renderer/gpu/compositor_output_surface.h" |
| #include "content/renderer/gpu/compositor_software_output_device.h" |
| #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
| +#include "content/renderer/gpu/frame_swap_message_queue.h" |
| #include "content/renderer/gpu/mailbox_output_surface.h" |
| #include "content/renderer/gpu/render_widget_compositor.h" |
| #include "content/renderer/ime_event_guard.h" |
| @@ -153,6 +154,44 @@ ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { |
| // be spent in input hanlders before input starts getting throttled. |
| const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; |
| +class QueueMessageSwapPromise : public cc::SwapPromise { |
| + public: |
| + QueueMessageSwapPromise( |
| + scoped_refptr<IPC::SyncMessageFilter> message_sender, |
| + scoped_refptr<content::FrameSwapMessageQueue> message_queue, |
| + IPC::Message* msg) |
| + : message_sender_(message_sender), |
| + message_queue_(message_queue), |
| + msg_(msg) { |
| + DCHECK(message_sender_.get()); |
| + DCHECK(message_queue_.get()); |
| + DCHECK(msg); |
| + } |
| + |
| + virtual ~QueueMessageSwapPromise() { |
| + // Should only happen when the compositor is being deleted. |
| + delete msg_; |
|
piman
2014/05/22 23:32:01
Maybe we should have LayerTreeHost / LayerTreeImpl
mkosiba (inactive)
2014/05/23 15:50:38
Done.
|
| + } |
| + |
| + virtual void DidSwap(int source_frame_number, |
| + cc::CompositorFrameMetadata* metadata) OVERRIDE { |
| + if (!message_queue_->TryQueueMessage(source_frame_number, msg_)) { |
|
piman
2014/05/22 23:32:01
So, I don't think this can ever fail.
SwapPromise
mkosiba (inactive)
2014/05/23 15:50:38
yes, you're right. This simplifies things a bit.
|
| + message_sender_->Send(msg_); |
| + } |
| + msg_ = NULL; |
| + } |
| + |
| + virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { |
| + message_sender_->Send(msg_); |
| + msg_ = NULL; |
| + } |
| + |
| + private: |
| + scoped_refptr<IPC::SyncMessageFilter> message_sender_; |
| + scoped_refptr<content::FrameSwapMessageQueue> message_queue_; |
| + IPC::Message* msg_; |
| +}; |
| + |
| } // namespace |
| namespace content { |
| @@ -397,6 +436,7 @@ RenderWidget::RenderWidget(blink::WebPopupType popup_type, |
| cached_has_main_frame_vertical_scrollbar_(false), |
| #endif |
| popup_origin_scale_for_emulation_(0.f), |
| + frame_swap_message_queue_(new FrameSwapMessageQueue()), |
| resizing_mode_selector_(new ResizingModeSelector()), |
| context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
| if (!swapped_out) |
| @@ -814,7 +854,8 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
| #if defined(OS_ANDROID) |
| if (SynchronousCompositorFactory* factory = |
| SynchronousCompositorFactory::GetInstance()) { |
| - return factory->CreateOutputSurface(routing_id()); |
| + return factory->CreateOutputSurface(routing_id(), |
| + frame_swap_message_queue_); |
| } |
| #endif |
| @@ -837,21 +878,22 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
| if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
| DCHECK(is_threaded_compositing_enabled_); |
| return scoped_ptr<cc::OutputSurface>( |
| - new DelegatedCompositorOutputSurface( |
| - routing_id(), |
| - output_surface_id, |
| - context_provider)); |
| + new DelegatedCompositorOutputSurface(routing_id(), |
| + output_surface_id, |
| + context_provider, |
| + frame_swap_message_queue_)); |
| } |
| if (!context_provider.get()) { |
| scoped_ptr<cc::SoftwareOutputDevice> software_device( |
| new CompositorSoftwareOutputDevice()); |
| - return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
| - routing_id(), |
| - output_surface_id, |
| - NULL, |
| - software_device.Pass(), |
| - true)); |
| + return scoped_ptr<cc::OutputSurface>( |
| + new CompositorOutputSurface(routing_id(), |
| + output_surface_id, |
| + NULL, |
| + software_device.Pass(), |
| + frame_swap_message_queue_, |
| + true)); |
| } |
| if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
| @@ -866,21 +908,21 @@ scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
| format = cc::RGB_565; |
| #endif |
| return scoped_ptr<cc::OutputSurface>( |
| - new MailboxOutputSurface( |
| - routing_id(), |
| - output_surface_id, |
| - context_provider, |
| - scoped_ptr<cc::SoftwareOutputDevice>(), |
| - format)); |
| + new MailboxOutputSurface(routing_id(), |
| + output_surface_id, |
| + context_provider, |
| + scoped_ptr<cc::SoftwareOutputDevice>(), |
| + frame_swap_message_queue_, |
| + format)); |
| } |
| bool use_swap_compositor_frame_message = false; |
| return scoped_ptr<cc::OutputSurface>( |
| - new CompositorOutputSurface( |
| - routing_id(), |
| - output_surface_id, |
| - context_provider, |
| - scoped_ptr<cc::SoftwareOutputDevice>(), |
| - use_swap_compositor_frame_message)); |
| + new CompositorOutputSurface(routing_id(), |
| + output_surface_id, |
| + context_provider, |
| + scoped_ptr<cc::SoftwareOutputDevice>(), |
| + frame_swap_message_queue_, |
| + use_swap_compositor_frame_message)); |
| } |
| void RenderWidget::OnSwapBuffersAborted() { |
| @@ -1208,6 +1250,30 @@ void RenderWidget::DidCommitCompositorFrame() { |
| DidCommitCompositorFrame()); |
| } |
| +namespace {} // namespace |
| + |
| +void RenderWidget::QueueMessage(IPC::Message* msg, |
| + MessageDeliveryPolicy policy) { |
| + if (policy == MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP) { |
| + frame_swap_message_queue_->QueueMessage(msg); |
| + return; |
| + } |
| + |
| + if (!compositor_ || (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE && |
| + !compositor_->commitRequested())) { |
| + Send(msg); |
| + return; |
| + } |
| + DCHECK(policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE || |
| + policy == MESSAGE_DELIVERY_POLICY_WITH_NEXT_COMMIT); |
| + |
| + scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
| + RenderThreadImpl::current()->sync_message_filter(), |
| + frame_swap_message_queue_, |
| + msg)); |
| + compositor_->QueueSwapPromise(promise.Pass()); |
| +} |
| + |
| void RenderWidget::didCommitAndDrawCompositorFrame() { |
| TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
| // Accelerated FPS tick for performance tests. See |