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/browser/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 37 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
38 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 38 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
39 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 39 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
40 #include "content/browser/renderer_host/input/timeout_monitor.h" | 40 #include "content/browser/renderer_host/input/timeout_monitor.h" |
41 #include "content/browser/renderer_host/input/touch_emulator.h" | 41 #include "content/browser/renderer_host/input/touch_emulator.h" |
42 #include "content/browser/renderer_host/render_process_host_impl.h" | 42 #include "content/browser/renderer_host/render_process_host_impl.h" |
43 #include "content/browser/renderer_host/render_view_host_impl.h" | 43 #include "content/browser/renderer_host/render_view_host_impl.h" |
44 #include "content/browser/renderer_host/render_widget_helper.h" | 44 #include "content/browser/renderer_host/render_widget_helper.h" |
45 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 45 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
46 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 46 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 47 #include "content/browser/renderer_host/render_widget_resize_helper.h" |
47 #include "content/common/accessibility_messages.h" | 48 #include "content/common/accessibility_messages.h" |
48 #include "content/common/content_constants_internal.h" | 49 #include "content/common/content_constants_internal.h" |
49 #include "content/common/cursors/webcursor.h" | 50 #include "content/common/cursors/webcursor.h" |
50 #include "content/common/gpu/gpu_messages.h" | 51 #include "content/common/gpu/gpu_messages.h" |
51 #include "content/common/host_shared_bitmap_manager.h" | 52 #include "content/common/host_shared_bitmap_manager.h" |
52 #include "content/common/input_messages.h" | 53 #include "content/common/input_messages.h" |
53 #include "content/common/view_messages.h" | 54 #include "content/common/view_messages.h" |
54 #include "content/public/browser/native_web_keyboard_event.h" | 55 #include "content/public/browser/native_web_keyboard_event.h" |
55 #include "content/public/browser/notification_service.h" | 56 #include "content/public/browser/notification_service.h" |
56 #include "content/public/browser/notification_types.h" | 57 #include "content/public/browser/notification_types.h" |
(...skipping 25 matching lines...) Expand all Loading... |
82 using blink::WebKeyboardEvent; | 83 using blink::WebKeyboardEvent; |
83 using blink::WebMouseEvent; | 84 using blink::WebMouseEvent; |
84 using blink::WebMouseWheelEvent; | 85 using blink::WebMouseWheelEvent; |
85 using blink::WebTextDirection; | 86 using blink::WebTextDirection; |
86 | 87 |
87 namespace content { | 88 namespace content { |
88 namespace { | 89 namespace { |
89 | 90 |
90 bool g_check_for_pending_resize_ack = true; | 91 bool g_check_for_pending_resize_ack = true; |
91 | 92 |
92 // How long to (synchronously) wait for the renderer to respond with a | |
93 // PaintRect message, when our backing-store is invalid, before giving up and | |
94 // returning a null or incorrectly sized backing-store from GetBackingStore. | |
95 // This timeout impacts the "choppiness" of our window resize perf. | |
96 const int kPaintMsgTimeoutMS = 50; | |
97 | |
98 typedef std::pair<int32, int32> RenderWidgetHostID; | 93 typedef std::pair<int32, int32> RenderWidgetHostID; |
99 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> | 94 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> |
100 RoutingIDWidgetMap; | 95 RoutingIDWidgetMap; |
101 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = | 96 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = |
102 LAZY_INSTANCE_INITIALIZER; | 97 LAZY_INSTANCE_INITIALIZER; |
103 | 98 |
104 int GetInputRouterViewFlagsFromCompositorFrameMetadata( | 99 int GetInputRouterViewFlagsFromCompositorFrameMetadata( |
105 const cc::CompositorFrameMetadata metadata) { | 100 const cc::CompositorFrameMetadata metadata) { |
106 int view_flags = InputRouter::VIEW_FLAGS_NONE; | 101 int view_flags = InputRouter::VIEW_FLAGS_NONE; |
107 | 102 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 OnShowDisambiguationPopup) | 464 OnShowDisambiguationPopup) |
470 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnSelectionChanged) | 465 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnSelectionChanged) |
471 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, | 466 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, |
472 OnSelectionBoundsChanged) | 467 OnSelectionBoundsChanged) |
473 #if defined(OS_WIN) | 468 #if defined(OS_WIN) |
474 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowCreated, | 469 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowCreated, |
475 OnWindowlessPluginDummyWindowCreated) | 470 OnWindowlessPluginDummyWindowCreated) |
476 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowDestroyed, | 471 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowDestroyed, |
477 OnWindowlessPluginDummyWindowDestroyed) | 472 OnWindowlessPluginDummyWindowDestroyed) |
478 #endif | 473 #endif |
479 #if defined(OS_MACOSX) | |
480 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, | |
481 OnCompositorSurfaceBuffersSwapped) | |
482 #endif | |
483 #if defined(OS_MACOSX) || defined(USE_AURA) | 474 #if defined(OS_MACOSX) || defined(USE_AURA) |
484 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, | 475 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, |
485 OnImeCompositionRangeChanged) | 476 OnImeCompositionRangeChanged) |
486 #endif | 477 #endif |
487 IPC_MESSAGE_UNHANDLED(handled = false) | 478 IPC_MESSAGE_UNHANDLED(handled = false) |
488 IPC_END_MESSAGE_MAP() | 479 IPC_END_MESSAGE_MAP() |
489 | 480 |
490 if (!handled && input_router_ && input_router_->OnMessageReceived(msg)) | 481 if (!handled && input_router_ && input_router_->OnMessageReceived(msg)) |
491 return true; | 482 return true; |
492 | 483 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 if (view_) | 694 if (view_) |
704 view_->LockCompositingSurface(); | 695 view_->LockCompositingSurface(); |
705 } | 696 } |
706 | 697 |
707 void RenderWidgetHostImpl::UnlockBackingStore() { | 698 void RenderWidgetHostImpl::UnlockBackingStore() { |
708 if (view_) | 699 if (view_) |
709 view_->UnlockCompositingSurface(); | 700 view_->UnlockCompositingSurface(); |
710 } | 701 } |
711 #endif | 702 #endif |
712 | 703 |
| 704 #if defined(OS_MACOSX) |
713 void RenderWidgetHostImpl::PauseForPendingResizeOrRepaints() { | 705 void RenderWidgetHostImpl::PauseForPendingResizeOrRepaints() { |
714 TRACE_EVENT0("browser", | 706 TRACE_EVENT0("browser", |
715 "RenderWidgetHostImpl::PauseForPendingResizeOrRepaints"); | 707 "RenderWidgetHostImpl::PauseForPendingResizeOrRepaints"); |
716 | 708 |
717 if (!CanPauseForPendingResizeOrRepaints()) | 709 if (!CanPauseForPendingResizeOrRepaints()) |
718 return; | 710 return; |
719 | 711 |
720 WaitForSurface(); | 712 WaitForSurface(); |
721 } | 713 } |
722 | 714 |
723 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { | 715 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { |
724 // Do not pause if the view is hidden. | 716 // Do not pause if the view is hidden. |
725 if (is_hidden()) | 717 if (is_hidden()) |
726 return false; | 718 return false; |
727 | 719 |
728 // Do not pause if there is not a paint or resize already coming. | 720 // Do not pause if there is not a paint or resize already coming. |
729 if (!repaint_ack_pending_ && !resize_ack_pending_) | 721 if (!repaint_ack_pending_ && !resize_ack_pending_) |
730 return false; | 722 return false; |
731 | 723 |
732 return true; | 724 return true; |
733 } | 725 } |
734 | 726 |
735 void RenderWidgetHostImpl::WaitForSurface() { | 727 void RenderWidgetHostImpl::WaitForSurface() { |
736 TRACE_EVENT0("browser", "RenderWidgetHostImpl::WaitForSurface"); | 728 TRACE_EVENT0("browser", "RenderWidgetHostImpl::WaitForSurface"); |
737 | 729 |
| 730 // How long to (synchronously) wait for the renderer to respond with a |
| 731 // new frame when our current frame doesn't exist or is the wrong size. |
| 732 // This timeout impacts the "choppiness" of our window resize. |
| 733 const int kPaintMsgTimeoutMS = 50; |
| 734 |
738 if (!view_) | 735 if (!view_) |
739 return; | 736 return; |
740 | 737 |
741 // The view_size will be current_size_ for auto-sized views and otherwise the | 738 // The view_size will be current_size_ for auto-sized views and otherwise the |
742 // size of the view_. (For auto-sized views, current_size_ is updated during | 739 // size of the view_. (For auto-sized views, current_size_ is updated during |
743 // UpdateRect messages.) | 740 // UpdateRect messages.) |
744 gfx::Size view_size = current_size_; | 741 gfx::Size view_size = current_size_; |
745 if (!should_auto_resize_) { | 742 if (!should_auto_resize_) { |
746 // Get the desired size from the current view bounds. | 743 // Get the desired size from the current view bounds. |
747 gfx::Rect view_rect = view_->GetViewBounds(); | 744 gfx::Rect view_rect = view_->GetViewBounds(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 | 782 |
786 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); | 783 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); |
787 TimeTicks end_time = TimeTicks::Now() + max_delay; | 784 TimeTicks end_time = TimeTicks::Now() + max_delay; |
788 do { | 785 do { |
789 TRACE_EVENT0("renderer_host", "WaitForSurface::WaitForUpdate"); | 786 TRACE_EVENT0("renderer_host", "WaitForSurface::WaitForUpdate"); |
790 | 787 |
791 // When we have asked the RenderWidget to resize, and we are still waiting | 788 // When we have asked the RenderWidget to resize, and we are still waiting |
792 // on a response, block for a little while to see if we can't get a response | 789 // on a response, block for a little while to see if we can't get a response |
793 // before returning the old (incorrectly sized) backing store. | 790 // before returning the old (incorrectly sized) backing store. |
794 IPC::Message msg; | 791 IPC::Message msg; |
795 if (process_->WaitForBackingStoreMsg(routing_id_, max_delay, &msg)) { | 792 if (RenderWidgetResizeHelper::Get()->WaitForSingleTaskToRun(max_delay)) { |
796 OnMessageReceived(msg); | |
797 | 793 |
798 // For auto-resized views, current_size_ determines the view_size and it | 794 // For auto-resized views, current_size_ determines the view_size and it |
799 // may have changed during the handling of an UpdateRect message. | 795 // may have changed during the handling of an UpdateRect message. |
800 if (should_auto_resize_) | 796 if (should_auto_resize_) |
801 view_size = current_size_; | 797 view_size = current_size_; |
802 | 798 |
803 // Break now if we got a backing store or accelerated surface of the | 799 // Break now if we got a backing store or accelerated surface of the |
804 // correct size. | 800 // correct size. |
805 if (view_->HasAcceleratedSurface(view_size)) | 801 if (view_->HasAcceleratedSurface(view_size)) |
806 return; | 802 return; |
807 } else { | 803 } else { |
808 TRACE_EVENT0("renderer_host", "WaitForSurface::Timeout"); | 804 TRACE_EVENT0("renderer_host", "WaitForSurface::Timeout"); |
809 break; | 805 break; |
810 } | 806 } |
811 | 807 |
812 // Loop if we still have time left and haven't gotten a properly sized | 808 // Loop if we still have time left and haven't gotten a properly sized |
813 // BackingStore yet. This is necessary to support the GPU path which | 809 // BackingStore yet. This is necessary to support the GPU path which |
814 // typically has multiple frames pipelined -- we may need to skip one or two | 810 // typically has multiple frames pipelined -- we may need to skip one or two |
815 // BackingStore messages to get to the latest. | 811 // BackingStore messages to get to the latest. |
816 max_delay = end_time - TimeTicks::Now(); | 812 max_delay = end_time - TimeTicks::Now(); |
817 } while (max_delay > TimeDelta::FromSeconds(0)); | 813 } while (max_delay > TimeDelta::FromSeconds(0)); |
818 } | 814 } |
| 815 #endif |
819 | 816 |
820 bool RenderWidgetHostImpl::ScheduleComposite() { | 817 bool RenderWidgetHostImpl::ScheduleComposite() { |
821 if (is_hidden_ || current_size_.IsEmpty() || repaint_ack_pending_ || | 818 if (is_hidden_ || current_size_.IsEmpty() || repaint_ack_pending_ || |
822 resize_ack_pending_) { | 819 resize_ack_pending_) { |
823 return false; | 820 return false; |
824 } | 821 } |
825 | 822 |
826 // Send out a request to the renderer to paint the view if required. | 823 // Send out a request to the renderer to paint the view if required. |
827 repaint_start_time_ = TimeTicks::Now(); | 824 repaint_start_time_ = TimeTicks::Now(); |
828 repaint_ack_pending_ = true; | 825 repaint_ack_pending_ = true; |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 SendScreenRects(); | 1403 SendScreenRects(); |
1407 } | 1404 } |
1408 | 1405 |
1409 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { | 1406 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { |
1410 if (view_) { | 1407 if (view_) { |
1411 view_->SetBounds(pos); | 1408 view_->SetBounds(pos); |
1412 Send(new ViewMsg_Move_ACK(routing_id_)); | 1409 Send(new ViewMsg_Move_ACK(routing_id_)); |
1413 } | 1410 } |
1414 } | 1411 } |
1415 | 1412 |
1416 #if defined(OS_MACOSX) | |
1417 void RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped( | |
1418 const ViewHostMsg_CompositorSurfaceBuffersSwapped_Params& params) { | |
1419 // This trace event is used in | |
1420 // chrome/browser/extensions/api/cast_streaming/performance_test.cc | |
1421 TRACE_EVENT0("renderer_host", | |
1422 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped"); | |
1423 // This trace event is used in | |
1424 // chrome/browser/extensions/api/cast_streaming/performance_test.cc | |
1425 UNSHIPPED_TRACE_EVENT0("test_fps", | |
1426 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame")); | |
1427 if (!ui::LatencyInfo::Verify(params.latency_info, | |
1428 "ViewHostMsg_CompositorSurfaceBuffersSwapped")) | |
1429 return; | |
1430 if (!view_) { | |
1431 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | |
1432 ack_params.sync_point = 0; | |
1433 RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id, | |
1434 params.gpu_process_host_id, | |
1435 ack_params); | |
1436 return; | |
1437 } | |
1438 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params gpu_params; | |
1439 gpu_params.surface_id = params.surface_id; | |
1440 gpu_params.surface_handle = params.surface_handle; | |
1441 gpu_params.route_id = params.route_id; | |
1442 gpu_params.size = params.size; | |
1443 gpu_params.scale_factor = params.scale_factor; | |
1444 gpu_params.latency_info = params.latency_info; | |
1445 for (size_t i = 0; i < gpu_params.latency_info.size(); i++) | |
1446 AddLatencyInfoComponentIds(&gpu_params.latency_info[i]); | |
1447 view_->AcceleratedSurfaceBuffersSwapped(gpu_params, | |
1448 params.gpu_process_host_id); | |
1449 view_->DidReceiveRendererFrame(); | |
1450 } | |
1451 #endif // OS_MACOSX | |
1452 | |
1453 bool RenderWidgetHostImpl::OnSwapCompositorFrame( | 1413 bool RenderWidgetHostImpl::OnSwapCompositorFrame( |
1454 const IPC::Message& message) { | 1414 const IPC::Message& message) { |
1455 // This trace event is used in | 1415 // This trace event is used in |
1456 // chrome/browser/extensions/api/cast_streaming/performance_test.cc | 1416 // chrome/browser/extensions/api/cast_streaming/performance_test.cc |
1457 UNSHIPPED_TRACE_EVENT0("test_fps", | 1417 UNSHIPPED_TRACE_EVENT0("test_fps", |
1458 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame")); | 1418 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame")); |
1459 ViewHostMsg_SwapCompositorFrame::Param param; | 1419 ViewHostMsg_SwapCompositorFrame::Param param; |
1460 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1420 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
1461 return false; | 1421 return false; |
1462 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 1422 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 } | 2341 } |
2382 } | 2342 } |
2383 | 2343 |
2384 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2344 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
2385 if (view_) | 2345 if (view_) |
2386 return view_->PreferredReadbackFormat(); | 2346 return view_->PreferredReadbackFormat(); |
2387 return kN32_SkColorType; | 2347 return kN32_SkColorType; |
2388 } | 2348 } |
2389 | 2349 |
2390 } // namespace content | 2350 } // namespace content |
OLD | NEW |