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/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "base/trace_event/trace_event_synthetic_delay.h" | 19 #include "base/trace_event/trace_event_synthetic_delay.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "cc/base/switches.h" | 21 #include "cc/base/switches.h" |
22 #include "cc/debug/benchmark_instrumentation.h" | 22 #include "cc/debug/benchmark_instrumentation.h" |
23 #include "cc/output/output_surface.h" | 23 #include "cc/output/output_surface.h" |
| 24 #include "cc/output/promise.h" |
24 #include "cc/trees/layer_tree_host.h" | 25 #include "cc/trees/layer_tree_host.h" |
25 #include "content/child/npapi/webplugin.h" | 26 #include "content/child/npapi/webplugin.h" |
26 #include "content/common/gpu/client/context_provider_command_buffer.h" | 27 #include "content/common/gpu/client/context_provider_command_buffer.h" |
27 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 28 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
28 #include "content/common/gpu/gpu_process_launch_causes.h" | 29 #include "content/common/gpu/gpu_process_launch_causes.h" |
29 #include "content/common/input/synthetic_gesture_packet.h" | 30 #include "content/common/input/synthetic_gesture_packet.h" |
30 #include "content/common/input/web_input_event_traits.h" | 31 #include "content/common/input/web_input_event_traits.h" |
31 #include "content/common/input_messages.h" | 32 #include "content/common/input_messages.h" |
32 #include "content/common/swapped_out_messages.h" | 33 #include "content/common/swapped_out_messages.h" |
33 #include "content/common/view_messages.h" | 34 #include "content/common/view_messages.h" |
34 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/context_menu_params.h" | 36 #include "content/public/common/context_menu_params.h" |
36 #include "content/renderer/cursor_utils.h" | 37 #include "content/renderer/cursor_utils.h" |
37 #include "content/renderer/external_popup_menu.h" | 38 #include "content/renderer/external_popup_menu.h" |
38 #include "content/renderer/gpu/compositor_output_surface.h" | 39 #include "content/renderer/gpu/compositor_output_surface.h" |
39 #include "content/renderer/gpu/compositor_software_output_device.h" | 40 #include "content/renderer/gpu/compositor_software_output_device.h" |
40 #include "content/renderer/gpu/delegated_compositor_output_surface.h" | 41 #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
41 #include "content/renderer/gpu/frame_swap_message_queue.h" | 42 #include "content/renderer/gpu/frame_update_message_queue.h" |
42 #include "content/renderer/gpu/mailbox_output_surface.h" | 43 #include "content/renderer/gpu/mailbox_output_surface.h" |
| 44 #include "content/renderer/gpu/queue_message_activation_promise.h" |
43 #include "content/renderer/gpu/queue_message_swap_promise.h" | 45 #include "content/renderer/gpu/queue_message_swap_promise.h" |
44 #include "content/renderer/gpu/render_widget_compositor.h" | 46 #include "content/renderer/gpu/render_widget_compositor.h" |
45 #include "content/renderer/ime_event_guard.h" | 47 #include "content/renderer/ime_event_guard.h" |
46 #include "content/renderer/input/input_handler_manager.h" | 48 #include "content/renderer/input/input_handler_manager.h" |
47 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 49 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
48 #include "content/renderer/render_frame_impl.h" | 50 #include "content/renderer/render_frame_impl.h" |
49 #include "content/renderer/render_frame_proxy.h" | 51 #include "content/renderer/render_frame_proxy.h" |
50 #include "content/renderer/render_process.h" | 52 #include "content/renderer/render_process.h" |
51 #include "content/renderer/render_thread_impl.h" | 53 #include "content/renderer/render_thread_impl.h" |
52 #include "content/renderer/renderer_blink_platform_impl.h" | 54 #include "content/renderer/renderer_blink_platform_impl.h" |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 screen_info_(screen_info), | 510 screen_info_(screen_info), |
509 device_scale_factor_(screen_info_.deviceScaleFactor), | 511 device_scale_factor_(screen_info_.deviceScaleFactor), |
510 current_event_latency_info_(NULL), | 512 current_event_latency_info_(NULL), |
511 next_output_surface_id_(0), | 513 next_output_surface_id_(0), |
512 #if defined(OS_ANDROID) | 514 #if defined(OS_ANDROID) |
513 text_field_is_dirty_(false), | 515 text_field_is_dirty_(false), |
514 outstanding_ime_acks_(0), | 516 outstanding_ime_acks_(0), |
515 body_background_color_(SK_ColorWHITE), | 517 body_background_color_(SK_ColorWHITE), |
516 #endif | 518 #endif |
517 popup_origin_scale_for_emulation_(0.f), | 519 popup_origin_scale_for_emulation_(0.f), |
518 frame_swap_message_queue_(new FrameSwapMessageQueue()), | 520 frame_update_message_queue_(new FrameUpdateMessageQueue()), |
519 resizing_mode_selector_(new ResizingModeSelector()), | 521 resizing_mode_selector_(new ResizingModeSelector()), |
520 context_menu_source_type_(ui::MENU_SOURCE_MOUSE), | 522 context_menu_source_type_(ui::MENU_SOURCE_MOUSE), |
521 has_host_context_menu_location_(false) { | 523 has_host_context_menu_location_(false) { |
522 if (!swapped_out) | 524 if (!swapped_out) |
523 RenderProcess::current()->AddRefProcess(); | 525 RenderProcess::current()->AddRefProcess(); |
524 DCHECK(RenderThread::Get()); | 526 DCHECK(RenderThread::Get()); |
525 device_color_profile_.push_back('0'); | 527 device_color_profile_.push_back('0'); |
526 } | 528 } |
527 | 529 |
528 RenderWidget::~RenderWidget() { | 530 RenderWidget::~RenderWidget() { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 | 994 |
993 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 995 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
994 // For widgets that are never visible, we don't start the compositor, so we | 996 // For widgets that are never visible, we don't start the compositor, so we |
995 // never get a request for a cc::OutputSurface. | 997 // never get a request for a cc::OutputSurface. |
996 DCHECK(!never_visible_); | 998 DCHECK(!never_visible_); |
997 | 999 |
998 #if defined(OS_ANDROID) | 1000 #if defined(OS_ANDROID) |
999 if (SynchronousCompositorFactory* factory = | 1001 if (SynchronousCompositorFactory* factory = |
1000 SynchronousCompositorFactory::GetInstance()) { | 1002 SynchronousCompositorFactory::GetInstance()) { |
1001 return factory->CreateOutputSurface(routing_id(), | 1003 return factory->CreateOutputSurface(routing_id(), |
1002 frame_swap_message_queue_); | 1004 frame_update_message_queue_); |
1003 } | 1005 } |
1004 #endif | 1006 #endif |
1005 | 1007 |
1006 const base::CommandLine& command_line = | 1008 const base::CommandLine& command_line = |
1007 *base::CommandLine::ForCurrentProcess(); | 1009 *base::CommandLine::ForCurrentProcess(); |
1008 bool use_software = fallback; | 1010 bool use_software = fallback; |
1009 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 1011 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
1010 use_software = true; | 1012 use_software = true; |
1011 | 1013 |
1012 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 1014 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
(...skipping 12 matching lines...) Expand all Loading... |
1025 // Cause the compositor to wait and try again. | 1027 // Cause the compositor to wait and try again. |
1026 return scoped_ptr<cc::OutputSurface>(); | 1028 return scoped_ptr<cc::OutputSurface>(); |
1027 } | 1029 } |
1028 } | 1030 } |
1029 | 1031 |
1030 uint32 output_surface_id = next_output_surface_id_++; | 1032 uint32 output_surface_id = next_output_surface_id_++; |
1031 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 1033 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
1032 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner()); | 1034 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner()); |
1033 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface( | 1035 return scoped_ptr<cc::OutputSurface>(new DelegatedCompositorOutputSurface( |
1034 routing_id(), output_surface_id, context_provider, | 1036 routing_id(), output_surface_id, context_provider, |
1035 worker_context_provider, frame_swap_message_queue_)); | 1037 worker_context_provider, frame_update_message_queue_)); |
1036 } | 1038 } |
1037 if (!context_provider.get()) { | 1039 if (!context_provider.get()) { |
1038 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 1040 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
1039 new CompositorSoftwareOutputDevice()); | 1041 new CompositorSoftwareOutputDevice()); |
1040 | 1042 |
1041 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 1043 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
1042 routing_id(), output_surface_id, nullptr, nullptr, | 1044 routing_id(), output_surface_id, nullptr, nullptr, |
1043 software_device.Pass(), frame_swap_message_queue_, true)); | 1045 software_device.Pass(), frame_update_message_queue_, true)); |
1044 } | 1046 } |
1045 | 1047 |
1046 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 1048 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
1047 // Composite-to-mailbox is currently used for layout tests in order to cause | 1049 // Composite-to-mailbox is currently used for layout tests in order to cause |
1048 // them to draw inside in the renderer to do the readback there. This should | 1050 // them to draw inside in the renderer to do the readback there. This should |
1049 // no longer be the case when crbug.com/311404 is fixed. | 1051 // no longer be the case when crbug.com/311404 is fixed. |
1050 DCHECK(RenderThreadImpl::current()->layout_test_mode()); | 1052 DCHECK(RenderThreadImpl::current()->layout_test_mode()); |
1051 cc::ResourceFormat format = cc::RGBA_8888; | 1053 cc::ResourceFormat format = cc::RGBA_8888; |
1052 if (base::SysInfo::IsLowEndDevice()) | 1054 if (base::SysInfo::IsLowEndDevice()) |
1053 format = cc::RGB_565; | 1055 format = cc::RGB_565; |
1054 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface( | 1056 return scoped_ptr<cc::OutputSurface>(new MailboxOutputSurface( |
1055 routing_id(), output_surface_id, context_provider, | 1057 routing_id(), output_surface_id, context_provider, |
1056 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(), | 1058 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(), |
1057 frame_swap_message_queue_, format)); | 1059 frame_update_message_queue_, format)); |
1058 } | 1060 } |
1059 bool use_swap_compositor_frame_message = false; | 1061 bool use_swap_compositor_frame_message = false; |
1060 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 1062 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
1061 routing_id(), output_surface_id, context_provider, | 1063 routing_id(), output_surface_id, context_provider, |
1062 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(), | 1064 worker_context_provider, scoped_ptr<cc::SoftwareOutputDevice>(), |
1063 frame_swap_message_queue_, use_swap_compositor_frame_message)); | 1065 frame_update_message_queue_, use_swap_compositor_frame_message)); |
1064 } | 1066 } |
1065 | 1067 |
1066 void RenderWidget::OnSwapBuffersAborted() { | 1068 void RenderWidget::OnSwapBuffersAborted() { |
1067 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 1069 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
1068 // Schedule another frame so the compositor learns about it. | 1070 // Schedule another frame so the compositor learns about it. |
1069 scheduleComposite(); | 1071 scheduleComposite(); |
1070 } | 1072 } |
1071 | 1073 |
1072 void RenderWidget::OnSwapBuffersPosted() { | 1074 void RenderWidget::OnSwapBuffersPosted() { |
1073 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); | 1075 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 DidCommitCompositorFrame()); | 1417 DidCommitCompositorFrame()); |
1416 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, | 1418 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, |
1417 DidCommitCompositorFrame()); | 1419 DidCommitCompositorFrame()); |
1418 #if defined(VIDEO_HOLE) | 1420 #if defined(VIDEO_HOLE) |
1419 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, | 1421 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, |
1420 DidCommitCompositorFrame()); | 1422 DidCommitCompositorFrame()); |
1421 #endif // defined(VIDEO_HOLE) | 1423 #endif // defined(VIDEO_HOLE) |
1422 } | 1424 } |
1423 | 1425 |
1424 // static | 1426 // static |
1425 scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl( | 1427 scoped_ptr<cc::Promise> RenderWidget::QueueMessageImpl( |
1426 IPC::Message* msg, | 1428 IPC::Message* msg, |
1427 MessageDeliveryPolicy policy, | 1429 MessageDeliveryPolicy policy, |
1428 FrameSwapMessageQueue* frame_swap_message_queue, | 1430 FrameUpdateMessageQueue* frame_update_message_queue, |
1429 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, | 1431 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter, |
1430 int source_frame_number) { | 1432 int source_frame_number) { |
1431 bool first_message_for_frame = false; | 1433 bool first_message_for_frame = false; |
1432 frame_swap_message_queue->QueueMessageForFrame(policy, | 1434 frame_update_message_queue->QueueMessageForFrame(policy, |
1433 source_frame_number, | 1435 source_frame_number, |
1434 make_scoped_ptr(msg), | 1436 make_scoped_ptr(msg), |
1435 &first_message_for_frame); | 1437 &first_message_for_frame); |
| 1438 scoped_ptr<cc::Promise> promise; |
1436 if (first_message_for_frame) { | 1439 if (first_message_for_frame) { |
1437 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( | 1440 switch (policy) { |
1438 sync_message_filter, frame_swap_message_queue, source_frame_number)); | 1441 case MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE: |
1439 return promise; | 1442 case MESSAGE_DELIVERY_POLICY_WITH_ACTIVATION: |
| 1443 promise.reset(new QueueMessageActivationPromise( |
| 1444 sync_message_filter, frame_update_message_queue, |
| 1445 source_frame_number)); |
| 1446 case MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP: |
| 1447 promise.reset(new QueueMessageSwapPromise(sync_message_filter, |
| 1448 frame_update_message_queue, |
| 1449 source_frame_number)); |
| 1450 break; |
| 1451 } |
1440 } | 1452 } |
1441 return nullptr; | 1453 return promise; |
1442 } | 1454 } |
1443 | 1455 |
1444 void RenderWidget::QueueMessage(IPC::Message* msg, | 1456 void RenderWidget::QueueMessage(IPC::Message* msg, |
1445 MessageDeliveryPolicy policy) { | 1457 MessageDeliveryPolicy policy) { |
1446 // RenderThreadImpl::current() is NULL in some tests. | 1458 // RenderThreadImpl::current() is NULL in some tests. |
1447 if (!compositor_ || !RenderThreadImpl::current()) { | 1459 if (!compositor_ || !RenderThreadImpl::current()) { |
1448 Send(msg); | 1460 Send(msg); |
1449 return; | 1461 return; |
1450 } | 1462 } |
1451 | 1463 |
1452 scoped_ptr<cc::SwapPromise> swap_promise = | 1464 scoped_ptr<cc::Promise> promise = |
1453 QueueMessageImpl(msg, | 1465 QueueMessageImpl(msg, |
1454 policy, | 1466 policy, |
1455 frame_swap_message_queue_.get(), | 1467 frame_update_message_queue_.get(), |
1456 RenderThreadImpl::current()->sync_message_filter(), | 1468 RenderThreadImpl::current()->sync_message_filter(), |
1457 compositor_->GetSourceFrameNumber()); | 1469 compositor_->GetSourceFrameNumber()); |
1458 | 1470 |
1459 if (swap_promise) { | 1471 if (promise) { |
1460 compositor_->QueueSwapPromise(swap_promise.Pass()); | 1472 compositor_->QueuePromise(promise.Pass()); |
1461 // Request a commit. This might either A) request a commit ahead of time | 1473 // Request a commit. This might either A) request a commit ahead of time |
1462 // or B) request a commit which is not needed because there are not | 1474 // or B) request a commit which is not needed because there are not |
1463 // pending updates. If B) then the commit will be skipped and the swap | 1475 // pending updates. If B) then the commit will be skipped and the swap |
1464 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we | 1476 // promises will be broken (see EarlyOut_NoUpdates). To achieve that we |
1465 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that | 1477 // call SetNeedsUpdateLayers instead of SetNeedsCommit so that |
1466 // can_cancel_commit is not unset. | 1478 // can_cancel_commit is not unset. |
1467 compositor_->SetNeedsUpdateLayers(); | 1479 compositor_->SetNeedsUpdateLayers(); |
1468 } | 1480 } |
1469 } | 1481 } |
1470 | 1482 |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2452 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2441 video_hole_frames_.AddObserver(frame); | 2453 video_hole_frames_.AddObserver(frame); |
2442 } | 2454 } |
2443 | 2455 |
2444 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2456 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2445 video_hole_frames_.RemoveObserver(frame); | 2457 video_hole_frames_.RemoveObserver(frame); |
2446 } | 2458 } |
2447 #endif // defined(VIDEO_HOLE) | 2459 #endif // defined(VIDEO_HOLE) |
2448 | 2460 |
2449 } // namespace content | 2461 } // namespace content |
OLD | NEW |