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 19 matching lines...) Expand all Loading... |
30 #include "content/common/input_messages.h" | 30 #include "content/common/input_messages.h" |
31 #include "content/common/swapped_out_messages.h" | 31 #include "content/common/swapped_out_messages.h" |
32 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
34 #include "content/public/common/context_menu_params.h" | 34 #include "content/public/common/context_menu_params.h" |
35 #include "content/renderer/cursor_utils.h" | 35 #include "content/renderer/cursor_utils.h" |
36 #include "content/renderer/external_popup_menu.h" | 36 #include "content/renderer/external_popup_menu.h" |
37 #include "content/renderer/gpu/compositor_output_surface.h" | 37 #include "content/renderer/gpu/compositor_output_surface.h" |
38 #include "content/renderer/gpu/compositor_software_output_device.h" | 38 #include "content/renderer/gpu/compositor_software_output_device.h" |
39 #include "content/renderer/gpu/delegated_compositor_output_surface.h" | 39 #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
| 40 #include "content/renderer/gpu/frame_swap_message_queue.h" |
40 #include "content/renderer/gpu/mailbox_output_surface.h" | 41 #include "content/renderer/gpu/mailbox_output_surface.h" |
| 42 #include "content/renderer/gpu/queue_message_swap_promise.h" |
41 #include "content/renderer/gpu/render_widget_compositor.h" | 43 #include "content/renderer/gpu/render_widget_compositor.h" |
42 #include "content/renderer/ime_event_guard.h" | 44 #include "content/renderer/ime_event_guard.h" |
43 #include "content/renderer/input/input_handler_manager.h" | 45 #include "content/renderer/input/input_handler_manager.h" |
44 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 46 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
45 #include "content/renderer/render_frame_impl.h" | 47 #include "content/renderer/render_frame_impl.h" |
46 #include "content/renderer/render_frame_proxy.h" | 48 #include "content/renderer/render_frame_proxy.h" |
47 #include "content/renderer/render_process.h" | 49 #include "content/renderer/render_process.h" |
48 #include "content/renderer/render_thread_impl.h" | 50 #include "content/renderer/render_thread_impl.h" |
49 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 51 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
50 #include "content/renderer/resizing_mode_selector.h" | 52 #include "content/renderer/resizing_mode_selector.h" |
(...skipping 338 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 defined(OS_ANDROID) | 867 #if defined(OS_ANDROID) |
863 if (base::android::SysUtils::IsLowEndDevice()) | 868 if (base::android::SysUtils::IsLowEndDevice()) |
864 format = cc::RGB_565; | 869 format = cc::RGB_565; |
865 #endif | 870 #endif |
866 return scoped_ptr<cc::OutputSurface>( | 871 return scoped_ptr<cc::OutputSurface>( |
867 new MailboxOutputSurface( | 872 new MailboxOutputSurface(routing_id(), |
868 routing_id(), | 873 output_surface_id, |
869 output_surface_id, | 874 context_provider, |
870 context_provider, | 875 scoped_ptr<cc::SoftwareOutputDevice>(), |
871 scoped_ptr<cc::SoftwareOutputDevice>(), | 876 frame_swap_message_queue_, |
872 format)); | 877 format)); |
873 } | 878 } |
874 bool use_swap_compositor_frame_message = false; | 879 bool use_swap_compositor_frame_message = false; |
875 return scoped_ptr<cc::OutputSurface>( | 880 return scoped_ptr<cc::OutputSurface>( |
876 new CompositorOutputSurface( | 881 new CompositorOutputSurface(routing_id(), |
877 routing_id(), | 882 output_surface_id, |
878 output_surface_id, | 883 context_provider, |
879 context_provider, | 884 scoped_ptr<cc::SoftwareOutputDevice>(), |
880 scoped_ptr<cc::SoftwareOutputDevice>(), | 885 frame_swap_message_queue_, |
881 use_swap_compositor_frame_message)); | 886 use_swap_compositor_frame_message)); |
882 } | 887 } |
883 | 888 |
884 void RenderWidget::OnSwapBuffersAborted() { | 889 void RenderWidget::OnSwapBuffersAborted() { |
885 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 890 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
886 // Schedule another frame so the compositor learns about it. | 891 // Schedule another frame so the compositor learns about it. |
887 scheduleComposite(); | 892 scheduleComposite(); |
888 } | 893 } |
889 | 894 |
890 void RenderWidget::OnSwapBuffersPosted() { | 895 void RenderWidget::OnSwapBuffersPosted() { |
891 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); | 896 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 | 1207 |
1203 void RenderWidget::DidCommitCompositorFrame() { | 1208 void RenderWidget::DidCommitCompositorFrame() { |
1204 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, | 1209 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, |
1205 DidCommitCompositorFrame()); | 1210 DidCommitCompositorFrame()); |
1206 #if defined(VIDEO_HOLE) | 1211 #if defined(VIDEO_HOLE) |
1207 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, | 1212 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, |
1208 DidCommitCompositorFrame()); | 1213 DidCommitCompositorFrame()); |
1209 #endif // defined(VIDEO_HOLE) | 1214 #endif // defined(VIDEO_HOLE) |
1210 } | 1215 } |
1211 | 1216 |
| 1217 // static |
| 1218 scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( |
| 1219 IPC::Message* msg, |
| 1220 MessageDeliveryPolicy policy, |
| 1221 FrameSwapMessageQueue* frame_swap_message_queue, |
| 1222 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
| 1223 bool commit_requested, |
| 1224 int source_frame_number) { |
| 1225 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE && |
| 1226 // No need for lock: this gets changed only on this thread. |
| 1227 !commit_requested && |
| 1228 // No need for lock: Messages are only enqueued from this thread, if we |
| 1229 // don't have any now, no other thread will add any. |
| 1230 frame_swap_message_queue->Empty()) { |
| 1231 sync_message_filter->Send(msg); |
| 1232 return scoped_ptr<cc::SwapPromise>(); |
| 1233 } |
| 1234 |
| 1235 bool first_message_for_frame = false; |
| 1236 frame_swap_message_queue->QueueMessageForFrame(policy, |
| 1237 source_frame_number, |
| 1238 make_scoped_ptr(msg), |
| 1239 &first_message_for_frame); |
| 1240 if (first_message_for_frame) { |
| 1241 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
| 1242 sync_message_filter, frame_swap_message_queue, source_frame_number)); |
| 1243 return promise.PassAs<cc::SwapPromise>(); |
| 1244 } |
| 1245 return scoped_ptr<cc::SwapPromise>(); |
| 1246 } |
| 1247 |
| 1248 void RenderWidget::QueueMessage(IPC::Message* msg, |
| 1249 MessageDeliveryPolicy policy) { |
| 1250 if (!compositor_) { |
| 1251 Send(msg); |
| 1252 return; |
| 1253 } |
| 1254 |
| 1255 scoped_ptr<cc::SwapPromise> swap_promise = |
| 1256 QueueMessageImpl(msg, |
| 1257 policy, |
| 1258 frame_swap_message_queue_, |
| 1259 RenderThreadImpl::current()->sync_message_filter(), |
| 1260 compositor_->commitRequested(), |
| 1261 compositor_->GetSourceFrameNumber()); |
| 1262 |
| 1263 if (swap_promise) { |
| 1264 compositor_->QueueSwapPromise(swap_promise.Pass()); |
| 1265 compositor_->SetNeedsCommit(); |
| 1266 } |
| 1267 } |
| 1268 |
1212 void RenderWidget::didCommitAndDrawCompositorFrame() { | 1269 void RenderWidget::didCommitAndDrawCompositorFrame() { |
1213 // NOTE: Tests may break if this event is renamed or moved. See | 1270 // NOTE: Tests may break if this event is renamed or moved. See |
1214 // tab_capture_performancetest.cc. | 1271 // tab_capture_performancetest.cc. |
1215 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); | 1272 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
1216 // Notify subclasses that we initiated the paint operation. | 1273 // Notify subclasses that we initiated the paint operation. |
1217 DidInitiatePaint(); | 1274 DidInitiatePaint(); |
1218 } | 1275 } |
1219 | 1276 |
1220 void RenderWidget::didCompleteSwapBuffers() { | 1277 void RenderWidget::didCompleteSwapBuffers() { |
1221 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); | 1278 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2118 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2062 video_hole_frames_.AddObserver(frame); | 2119 video_hole_frames_.AddObserver(frame); |
2063 } | 2120 } |
2064 | 2121 |
2065 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2122 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2066 video_hole_frames_.RemoveObserver(frame); | 2123 video_hole_frames_.RemoveObserver(frame); |
2067 } | 2124 } |
2068 #endif // defined(VIDEO_HOLE) | 2125 #endif // defined(VIDEO_HOLE) |
2069 | 2126 |
2070 } // namespace content | 2127 } // namespace content |
OLD | NEW |