OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "content/common/input_messages.h" | 31 #include "content/common/input_messages.h" |
32 #include "content/common/swapped_out_messages.h" | 32 #include "content/common/swapped_out_messages.h" |
33 #include "content/common/view_messages.h" | 33 #include "content/common/view_messages.h" |
34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/context_menu_params.h" | 35 #include "content/public/common/context_menu_params.h" |
36 #include "content/renderer/cursor_utils.h" | 36 #include "content/renderer/cursor_utils.h" |
37 #include "content/renderer/external_popup_menu.h" | 37 #include "content/renderer/external_popup_menu.h" |
38 #include "content/renderer/gpu/compositor_output_surface.h" | 38 #include "content/renderer/gpu/compositor_output_surface.h" |
39 #include "content/renderer/gpu/compositor_software_output_device.h" | 39 #include "content/renderer/gpu/compositor_software_output_device.h" |
40 #include "content/renderer/gpu/delegated_compositor_output_surface.h" | 40 #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
| 41 #include "content/renderer/gpu/frame_swap_message_queue.h" |
41 #include "content/renderer/gpu/mailbox_output_surface.h" | 42 #include "content/renderer/gpu/mailbox_output_surface.h" |
| 43 #include "content/renderer/gpu/queue_message_swap_promise.h" |
42 #include "content/renderer/gpu/render_widget_compositor.h" | 44 #include "content/renderer/gpu/render_widget_compositor.h" |
43 #include "content/renderer/ime_event_guard.h" | 45 #include "content/renderer/ime_event_guard.h" |
44 #include "content/renderer/input/input_handler_manager.h" | 46 #include "content/renderer/input/input_handler_manager.h" |
45 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 47 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
46 #include "content/renderer/render_frame_impl.h" | 48 #include "content/renderer/render_frame_impl.h" |
47 #include "content/renderer/render_frame_proxy.h" | 49 #include "content/renderer/render_frame_proxy.h" |
48 #include "content/renderer/render_process.h" | 50 #include "content/renderer/render_process.h" |
49 #include "content/renderer/render_thread_impl.h" | 51 #include "content/renderer/render_thread_impl.h" |
50 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 52 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
51 #include "content/renderer/resizing_mode_selector.h" | 53 #include "content/renderer/resizing_mode_selector.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 device_scale_factor_(screen_info_.deviceScaleFactor), | 391 device_scale_factor_(screen_info_.deviceScaleFactor), |
390 is_threaded_compositing_enabled_(false), | 392 is_threaded_compositing_enabled_(false), |
391 current_event_latency_info_(NULL), | 393 current_event_latency_info_(NULL), |
392 next_output_surface_id_(0), | 394 next_output_surface_id_(0), |
393 #if defined(OS_ANDROID) | 395 #if defined(OS_ANDROID) |
394 text_field_is_dirty_(false), | 396 text_field_is_dirty_(false), |
395 outstanding_ime_acks_(0), | 397 outstanding_ime_acks_(0), |
396 body_background_color_(SK_ColorWHITE), | 398 body_background_color_(SK_ColorWHITE), |
397 #endif | 399 #endif |
398 popup_origin_scale_for_emulation_(0.f), | 400 popup_origin_scale_for_emulation_(0.f), |
| 401 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
399 resizing_mode_selector_(new ResizingModeSelector()), | 402 resizing_mode_selector_(new ResizingModeSelector()), |
400 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { | 403 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
401 if (!swapped_out) | 404 if (!swapped_out) |
402 RenderProcess::current()->AddRefProcess(); | 405 RenderProcess::current()->AddRefProcess(); |
403 DCHECK(RenderThread::Get()); | 406 DCHECK(RenderThread::Get()); |
404 is_threaded_compositing_enabled_ = | 407 is_threaded_compositing_enabled_ = |
405 CommandLine::ForCurrentProcess()->HasSwitch( | 408 CommandLine::ForCurrentProcess()->HasSwitch( |
406 switches::kEnableThreadedCompositing); | 409 switches::kEnableThreadedCompositing); |
407 device_color_profile_.push_back('0'); | 410 device_color_profile_.push_back('0'); |
408 } | 411 } |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 } | 808 } |
806 | 809 |
807 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 810 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
808 // For widgets that are never visible, we don't start the compositor, so we | 811 // For widgets that are never visible, we don't start the compositor, so we |
809 // never get a request for a cc::OutputSurface. | 812 // never get a request for a cc::OutputSurface. |
810 DCHECK(!never_visible_); | 813 DCHECK(!never_visible_); |
811 | 814 |
812 #if defined(OS_ANDROID) | 815 #if defined(OS_ANDROID) |
813 if (SynchronousCompositorFactory* factory = | 816 if (SynchronousCompositorFactory* factory = |
814 SynchronousCompositorFactory::GetInstance()) { | 817 SynchronousCompositorFactory::GetInstance()) { |
815 return factory->CreateOutputSurface(routing_id()); | 818 return factory->CreateOutputSurface(routing_id(), |
| 819 frame_swap_message_queue_); |
816 } | 820 } |
817 #endif | 821 #endif |
818 | 822 |
819 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 823 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
820 bool use_software = fallback; | 824 bool use_software = fallback; |
821 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 825 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
822 use_software = true; | 826 use_software = true; |
823 | 827 |
824 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 828 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
825 if (!use_software) { | 829 if (!use_software) { |
826 context_provider = ContextProviderCommandBuffer::Create( | 830 context_provider = ContextProviderCommandBuffer::Create( |
827 CreateGraphicsContext3D(), "RenderCompositor"); | 831 CreateGraphicsContext3D(), "RenderCompositor"); |
828 if (!context_provider.get()) { | 832 if (!context_provider.get()) { |
829 // Cause the compositor to wait and try again. | 833 // Cause the compositor to wait and try again. |
830 return scoped_ptr<cc::OutputSurface>(); | 834 return scoped_ptr<cc::OutputSurface>(); |
831 } | 835 } |
832 } | 836 } |
833 | 837 |
834 uint32 output_surface_id = next_output_surface_id_++; | 838 uint32 output_surface_id = next_output_surface_id_++; |
835 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 839 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
836 DCHECK(is_threaded_compositing_enabled_); | 840 DCHECK(is_threaded_compositing_enabled_); |
837 return scoped_ptr<cc::OutputSurface>( | 841 return scoped_ptr<cc::OutputSurface>( |
838 new DelegatedCompositorOutputSurface( | 842 new DelegatedCompositorOutputSurface(routing_id(), |
839 routing_id(), | 843 output_surface_id, |
840 output_surface_id, | 844 context_provider, |
841 context_provider)); | 845 frame_swap_message_queue_)); |
842 } | 846 } |
843 if (!context_provider.get()) { | 847 if (!context_provider.get()) { |
844 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 848 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
845 new CompositorSoftwareOutputDevice()); | 849 new CompositorSoftwareOutputDevice()); |
846 | 850 |
847 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 851 return scoped_ptr<cc::OutputSurface>( |
848 routing_id(), | 852 new CompositorOutputSurface(routing_id(), |
849 output_surface_id, | 853 output_surface_id, |
850 NULL, | 854 NULL, |
851 software_device.Pass(), | 855 software_device.Pass(), |
852 true)); | 856 frame_swap_message_queue_, |
| 857 true)); |
853 } | 858 } |
854 | 859 |
855 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 860 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
856 // Composite-to-mailbox is currently used for layout tests in order to cause | 861 // Composite-to-mailbox is currently used for layout tests in order to cause |
857 // them to draw inside in the renderer to do the readback there. This should | 862 // them to draw inside in the renderer to do the readback there. This should |
858 // no longer be the case when crbug.com/311404 is fixed. | 863 // no longer be the case when crbug.com/311404 is fixed. |
859 DCHECK(is_threaded_compositing_enabled_ || | 864 DCHECK(is_threaded_compositing_enabled_ || |
860 RenderThreadImpl::current()->layout_test_mode()); | 865 RenderThreadImpl::current()->layout_test_mode()); |
861 cc::ResourceFormat format = cc::RGBA_8888; | 866 cc::ResourceFormat format = cc::RGBA_8888; |
862 if (base::SysInfo::IsLowEndDevice()) | 867 if (base::SysInfo::IsLowEndDevice()) |
863 format = cc::RGB_565; | 868 format = cc::RGB_565; |
864 return scoped_ptr<cc::OutputSurface>( | 869 return scoped_ptr<cc::OutputSurface>( |
865 new MailboxOutputSurface( | 870 new MailboxOutputSurface(routing_id(), |
866 routing_id(), | 871 output_surface_id, |
867 output_surface_id, | 872 context_provider, |
868 context_provider, | 873 scoped_ptr<cc::SoftwareOutputDevice>(), |
869 scoped_ptr<cc::SoftwareOutputDevice>(), | 874 frame_swap_message_queue_, |
870 format)); | 875 format)); |
871 } | 876 } |
872 bool use_swap_compositor_frame_message = false; | 877 bool use_swap_compositor_frame_message = false; |
873 return scoped_ptr<cc::OutputSurface>( | 878 return scoped_ptr<cc::OutputSurface>( |
874 new CompositorOutputSurface( | 879 new CompositorOutputSurface(routing_id(), |
875 routing_id(), | 880 output_surface_id, |
876 output_surface_id, | 881 context_provider, |
877 context_provider, | 882 scoped_ptr<cc::SoftwareOutputDevice>(), |
878 scoped_ptr<cc::SoftwareOutputDevice>(), | 883 frame_swap_message_queue_, |
879 use_swap_compositor_frame_message)); | 884 use_swap_compositor_frame_message)); |
880 } | 885 } |
881 | 886 |
882 void RenderWidget::OnSwapBuffersAborted() { | 887 void RenderWidget::OnSwapBuffersAborted() { |
883 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 888 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
884 // Schedule another frame so the compositor learns about it. | 889 // Schedule another frame so the compositor learns about it. |
885 scheduleComposite(); | 890 scheduleComposite(); |
886 } | 891 } |
887 | 892 |
888 void RenderWidget::OnSwapBuffersPosted() { | 893 void RenderWidget::OnSwapBuffersPosted() { |
889 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); | 894 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 | 1205 |
1201 void RenderWidget::DidCommitCompositorFrame() { | 1206 void RenderWidget::DidCommitCompositorFrame() { |
1202 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, | 1207 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, |
1203 DidCommitCompositorFrame()); | 1208 DidCommitCompositorFrame()); |
1204 #if defined(VIDEO_HOLE) | 1209 #if defined(VIDEO_HOLE) |
1205 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, | 1210 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, |
1206 DidCommitCompositorFrame()); | 1211 DidCommitCompositorFrame()); |
1207 #endif // defined(VIDEO_HOLE) | 1212 #endif // defined(VIDEO_HOLE) |
1208 } | 1213 } |
1209 | 1214 |
| 1215 // static |
| 1216 scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( |
| 1217 IPC::Message* msg, |
| 1218 MessageDeliveryPolicy policy, |
| 1219 FrameSwapMessageQueue* frame_swap_message_queue, |
| 1220 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
| 1221 bool commit_requested, |
| 1222 int source_frame_number) { |
| 1223 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE && |
| 1224 // No need for lock: this gets changed only on this thread. |
| 1225 !commit_requested && |
| 1226 // No need for lock: Messages are only enqueued from this thread, if we |
| 1227 // don't have any now, no other thread will add any. |
| 1228 frame_swap_message_queue->Empty()) { |
| 1229 sync_message_filter->Send(msg); |
| 1230 return scoped_ptr<cc::SwapPromise>(); |
| 1231 } |
| 1232 |
| 1233 bool first_message_for_frame = false; |
| 1234 frame_swap_message_queue->QueueMessageForFrame(policy, |
| 1235 source_frame_number, |
| 1236 make_scoped_ptr(msg), |
| 1237 &first_message_for_frame); |
| 1238 if (first_message_for_frame) { |
| 1239 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
| 1240 sync_message_filter, frame_swap_message_queue, source_frame_number)); |
| 1241 return promise.PassAs<cc::SwapPromise>(); |
| 1242 } |
| 1243 return scoped_ptr<cc::SwapPromise>(); |
| 1244 } |
| 1245 |
| 1246 void RenderWidget::QueueMessage(IPC::Message* msg, |
| 1247 MessageDeliveryPolicy policy) { |
| 1248 if (!compositor_) { |
| 1249 Send(msg); |
| 1250 return; |
| 1251 } |
| 1252 |
| 1253 scoped_ptr<cc::SwapPromise> swap_promise = |
| 1254 QueueMessageImpl(msg, |
| 1255 policy, |
| 1256 frame_swap_message_queue_, |
| 1257 RenderThreadImpl::current()->sync_message_filter(), |
| 1258 compositor_->commitRequested(), |
| 1259 compositor_->GetSourceFrameNumber()); |
| 1260 |
| 1261 if (swap_promise) { |
| 1262 compositor_->QueueSwapPromise(swap_promise.Pass()); |
| 1263 compositor_->SetNeedsCommit(); |
| 1264 } |
| 1265 } |
| 1266 |
1210 void RenderWidget::didCommitAndDrawCompositorFrame() { | 1267 void RenderWidget::didCommitAndDrawCompositorFrame() { |
1211 // NOTE: Tests may break if this event is renamed or moved. See | 1268 // NOTE: Tests may break if this event is renamed or moved. See |
1212 // tab_capture_performancetest.cc. | 1269 // tab_capture_performancetest.cc. |
1213 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); | 1270 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
1214 // Notify subclasses that we initiated the paint operation. | 1271 // Notify subclasses that we initiated the paint operation. |
1215 DidInitiatePaint(); | 1272 DidInitiatePaint(); |
1216 } | 1273 } |
1217 | 1274 |
1218 void RenderWidget::didCompleteSwapBuffers() { | 1275 void RenderWidget::didCompleteSwapBuffers() { |
1219 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); | 1276 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2116 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2060 video_hole_frames_.AddObserver(frame); | 2117 video_hole_frames_.AddObserver(frame); |
2061 } | 2118 } |
2062 | 2119 |
2063 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2120 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2064 video_hole_frames_.RemoveObserver(frame); | 2121 video_hole_frames_.RemoveObserver(frame); |
2065 } | 2122 } |
2066 #endif // defined(VIDEO_HOLE) | 2123 #endif // defined(VIDEO_HOLE) |
2067 | 2124 |
2068 } // namespace content | 2125 } // namespace content |
OLD | NEW |