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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 screen_info_(screen_info), | 404 screen_info_(screen_info), |
403 device_scale_factor_(screen_info_.deviceScaleFactor), | 405 device_scale_factor_(screen_info_.deviceScaleFactor), |
404 current_event_latency_info_(NULL), | 406 current_event_latency_info_(NULL), |
405 next_output_surface_id_(0), | 407 next_output_surface_id_(0), |
406 #if defined(OS_ANDROID) | 408 #if defined(OS_ANDROID) |
407 text_field_is_dirty_(false), | 409 text_field_is_dirty_(false), |
408 outstanding_ime_acks_(0), | 410 outstanding_ime_acks_(0), |
409 body_background_color_(SK_ColorWHITE), | 411 body_background_color_(SK_ColorWHITE), |
410 #endif | 412 #endif |
411 popup_origin_scale_for_emulation_(0.f), | 413 popup_origin_scale_for_emulation_(0.f), |
| 414 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
412 resizing_mode_selector_(new ResizingModeSelector()), | 415 resizing_mode_selector_(new ResizingModeSelector()), |
413 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { | 416 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
414 if (!swapped_out) | 417 if (!swapped_out) |
415 RenderProcess::current()->AddRefProcess(); | 418 RenderProcess::current()->AddRefProcess(); |
416 DCHECK(RenderThread::Get()); | 419 DCHECK(RenderThread::Get()); |
417 device_color_profile_.push_back('0'); | 420 device_color_profile_.push_back('0'); |
418 } | 421 } |
419 | 422 |
420 RenderWidget::~RenderWidget() { | 423 RenderWidget::~RenderWidget() { |
421 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 424 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 } | 816 } |
814 | 817 |
815 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 818 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
816 // For widgets that are never visible, we don't start the compositor, so we | 819 // For widgets that are never visible, we don't start the compositor, so we |
817 // never get a request for a cc::OutputSurface. | 820 // never get a request for a cc::OutputSurface. |
818 DCHECK(!never_visible_); | 821 DCHECK(!never_visible_); |
819 | 822 |
820 #if defined(OS_ANDROID) | 823 #if defined(OS_ANDROID) |
821 if (SynchronousCompositorFactory* factory = | 824 if (SynchronousCompositorFactory* factory = |
822 SynchronousCompositorFactory::GetInstance()) { | 825 SynchronousCompositorFactory::GetInstance()) { |
823 return factory->CreateOutputSurface(routing_id()); | 826 return factory->CreateOutputSurface(routing_id(), |
| 827 frame_swap_message_queue_); |
824 } | 828 } |
825 #endif | 829 #endif |
826 | 830 |
827 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 831 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
828 bool use_software = fallback; | 832 bool use_software = fallback; |
829 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 833 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
830 use_software = true; | 834 use_software = true; |
831 | 835 |
832 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 836 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
833 if (!use_software) { | 837 if (!use_software) { |
834 context_provider = ContextProviderCommandBuffer::Create( | 838 context_provider = ContextProviderCommandBuffer::Create( |
835 CreateGraphicsContext3D(), "RenderCompositor"); | 839 CreateGraphicsContext3D(), "RenderCompositor"); |
836 if (!context_provider.get()) { | 840 if (!context_provider.get()) { |
837 // Cause the compositor to wait and try again. | 841 // Cause the compositor to wait and try again. |
838 return scoped_ptr<cc::OutputSurface>(); | 842 return scoped_ptr<cc::OutputSurface>(); |
839 } | 843 } |
840 } | 844 } |
841 | 845 |
842 uint32 output_surface_id = next_output_surface_id_++; | 846 uint32 output_surface_id = next_output_surface_id_++; |
843 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 847 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
844 DCHECK(IsThreadedCompositingEnabled()); | 848 DCHECK(IsThreadedCompositingEnabled()); |
845 return scoped_ptr<cc::OutputSurface>( | 849 return scoped_ptr<cc::OutputSurface>( |
846 new DelegatedCompositorOutputSurface( | 850 new DelegatedCompositorOutputSurface(routing_id(), |
847 routing_id(), | 851 output_surface_id, |
848 output_surface_id, | 852 context_provider, |
849 context_provider)); | 853 frame_swap_message_queue_)); |
850 } | 854 } |
851 if (!context_provider.get()) { | 855 if (!context_provider.get()) { |
852 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 856 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
853 new CompositorSoftwareOutputDevice()); | 857 new CompositorSoftwareOutputDevice()); |
854 | 858 |
855 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 859 return scoped_ptr<cc::OutputSurface>( |
856 routing_id(), | 860 new CompositorOutputSurface(routing_id(), |
857 output_surface_id, | 861 output_surface_id, |
858 NULL, | 862 NULL, |
859 software_device.Pass(), | 863 software_device.Pass(), |
860 true)); | 864 frame_swap_message_queue_, |
| 865 true)); |
861 } | 866 } |
862 | 867 |
863 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 868 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
864 // Composite-to-mailbox is currently used for layout tests in order to cause | 869 // Composite-to-mailbox is currently used for layout tests in order to cause |
865 // them to draw inside in the renderer to do the readback there. This should | 870 // them to draw inside in the renderer to do the readback there. This should |
866 // no longer be the case when crbug.com/311404 is fixed. | 871 // no longer be the case when crbug.com/311404 is fixed. |
867 DCHECK(IsThreadedCompositingEnabled() || | 872 DCHECK(IsThreadedCompositingEnabled() || |
868 RenderThreadImpl::current()->layout_test_mode()); | 873 RenderThreadImpl::current()->layout_test_mode()); |
869 cc::ResourceFormat format = cc::RGBA_8888; | 874 cc::ResourceFormat format = cc::RGBA_8888; |
870 if (base::SysInfo::IsLowEndDevice()) | 875 if (base::SysInfo::IsLowEndDevice()) |
871 format = cc::RGB_565; | 876 format = cc::RGB_565; |
872 return scoped_ptr<cc::OutputSurface>( | 877 return scoped_ptr<cc::OutputSurface>( |
873 new MailboxOutputSurface( | 878 new MailboxOutputSurface(routing_id(), |
874 routing_id(), | 879 output_surface_id, |
875 output_surface_id, | 880 context_provider, |
876 context_provider, | 881 scoped_ptr<cc::SoftwareOutputDevice>(), |
877 scoped_ptr<cc::SoftwareOutputDevice>(), | 882 frame_swap_message_queue_, |
878 format)); | 883 format)); |
879 } | 884 } |
880 bool use_swap_compositor_frame_message = false; | 885 bool use_swap_compositor_frame_message = false; |
881 return scoped_ptr<cc::OutputSurface>( | 886 return scoped_ptr<cc::OutputSurface>( |
882 new CompositorOutputSurface( | 887 new CompositorOutputSurface(routing_id(), |
883 routing_id(), | 888 output_surface_id, |
884 output_surface_id, | 889 context_provider, |
885 context_provider, | 890 scoped_ptr<cc::SoftwareOutputDevice>(), |
886 scoped_ptr<cc::SoftwareOutputDevice>(), | 891 frame_swap_message_queue_, |
887 use_swap_compositor_frame_message)); | 892 use_swap_compositor_frame_message)); |
888 } | 893 } |
889 | 894 |
890 void RenderWidget::OnSwapBuffersAborted() { | 895 void RenderWidget::OnSwapBuffersAborted() { |
891 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 896 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
892 // Schedule another frame so the compositor learns about it. | 897 // Schedule another frame so the compositor learns about it. |
893 scheduleComposite(); | 898 scheduleComposite(); |
894 } | 899 } |
895 | 900 |
896 void RenderWidget::OnSwapBuffersPosted() { | 901 void RenderWidget::OnSwapBuffersPosted() { |
897 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); | 902 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 | 1230 |
1226 void RenderWidget::DidCommitCompositorFrame() { | 1231 void RenderWidget::DidCommitCompositorFrame() { |
1227 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, | 1232 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, |
1228 DidCommitCompositorFrame()); | 1233 DidCommitCompositorFrame()); |
1229 #if defined(VIDEO_HOLE) | 1234 #if defined(VIDEO_HOLE) |
1230 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, | 1235 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, |
1231 DidCommitCompositorFrame()); | 1236 DidCommitCompositorFrame()); |
1232 #endif // defined(VIDEO_HOLE) | 1237 #endif // defined(VIDEO_HOLE) |
1233 } | 1238 } |
1234 | 1239 |
| 1240 // static |
| 1241 scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( |
| 1242 IPC::Message* msg, |
| 1243 MessageDeliveryPolicy policy, |
| 1244 FrameSwapMessageQueue* frame_swap_message_queue, |
| 1245 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
| 1246 bool commit_requested, |
| 1247 int source_frame_number) { |
| 1248 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE && |
| 1249 // No need for lock: this gets changed only on this thread. |
| 1250 !commit_requested && |
| 1251 // No need for lock: Messages are only enqueued from this thread, if we |
| 1252 // don't have any now, no other thread will add any. |
| 1253 frame_swap_message_queue->Empty()) { |
| 1254 sync_message_filter->Send(msg); |
| 1255 return scoped_ptr<cc::SwapPromise>(); |
| 1256 } |
| 1257 |
| 1258 bool first_message_for_frame = false; |
| 1259 frame_swap_message_queue->QueueMessageForFrame(policy, |
| 1260 source_frame_number, |
| 1261 make_scoped_ptr(msg), |
| 1262 &first_message_for_frame); |
| 1263 if (first_message_for_frame) { |
| 1264 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
| 1265 sync_message_filter, frame_swap_message_queue, source_frame_number)); |
| 1266 return promise.PassAs<cc::SwapPromise>(); |
| 1267 } |
| 1268 return scoped_ptr<cc::SwapPromise>(); |
| 1269 } |
| 1270 |
| 1271 void RenderWidget::QueueMessage(IPC::Message* msg, |
| 1272 MessageDeliveryPolicy policy) { |
| 1273 // RenderThreadImpl::current() is NULL in some tests. |
| 1274 if (!compositor_ || !RenderThreadImpl::current()) { |
| 1275 Send(msg); |
| 1276 return; |
| 1277 } |
| 1278 |
| 1279 scoped_ptr<cc::SwapPromise> swap_promise = |
| 1280 QueueMessageImpl(msg, |
| 1281 policy, |
| 1282 frame_swap_message_queue_, |
| 1283 RenderThreadImpl::current()->sync_message_filter(), |
| 1284 compositor_->commitRequested(), |
| 1285 compositor_->GetSourceFrameNumber()); |
| 1286 |
| 1287 if (swap_promise) { |
| 1288 compositor_->QueueSwapPromise(swap_promise.Pass()); |
| 1289 compositor_->SetNeedsCommit(); |
| 1290 } |
| 1291 } |
| 1292 |
1235 void RenderWidget::didCommitAndDrawCompositorFrame() { | 1293 void RenderWidget::didCommitAndDrawCompositorFrame() { |
1236 // NOTE: Tests may break if this event is renamed or moved. See | 1294 // NOTE: Tests may break if this event is renamed or moved. See |
1237 // tab_capture_performancetest.cc. | 1295 // tab_capture_performancetest.cc. |
1238 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); | 1296 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
1239 // Notify subclasses that we initiated the paint operation. | 1297 // Notify subclasses that we initiated the paint operation. |
1240 DidInitiatePaint(); | 1298 DidInitiatePaint(); |
1241 } | 1299 } |
1242 | 1300 |
1243 void RenderWidget::didCompleteSwapBuffers() { | 1301 void RenderWidget::didCompleteSwapBuffers() { |
1244 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); | 1302 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2149 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2092 video_hole_frames_.AddObserver(frame); | 2150 video_hole_frames_.AddObserver(frame); |
2093 } | 2151 } |
2094 | 2152 |
2095 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2153 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2096 video_hole_frames_.RemoveObserver(frame); | 2154 video_hole_frames_.RemoveObserver(frame); |
2097 } | 2155 } |
2098 #endif // defined(VIDEO_HOLE) | 2156 #endif // defined(VIDEO_HOLE) |
2099 | 2157 |
2100 } // namespace content | 2158 } // namespace content |
OLD | NEW |