| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 #include "skia/ext/image_operations.h" | 63 #include "skia/ext/image_operations.h" |
| 64 #include "skia/ext/platform_canvas.h" | 64 #include "skia/ext/platform_canvas.h" |
| 65 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 65 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 66 #include "ui/events/event.h" | 66 #include "ui/events/event.h" |
| 67 #include "ui/events/keycodes/keyboard_codes.h" | 67 #include "ui/events/keycodes/keyboard_codes.h" |
| 68 #include "ui/gfx/size_conversions.h" | 68 #include "ui/gfx/size_conversions.h" |
| 69 #include "ui/gfx/skbitmap_operations.h" | 69 #include "ui/gfx/skbitmap_operations.h" |
| 70 #include "ui/gfx/vector2d_conversions.h" | 70 #include "ui/gfx/vector2d_conversions.h" |
| 71 #include "ui/snapshot/snapshot.h" | 71 #include "ui/snapshot/snapshot.h" |
| 72 | 72 |
| 73 #if defined(OS_MACOSX) |
| 74 #include "content/browser/renderer_host/render_widget_resize_helper_mac.h" |
| 75 #endif |
| 76 |
| 73 #if defined(OS_WIN) | 77 #if defined(OS_WIN) |
| 74 #include "content/common/plugin_constants_win.h" | 78 #include "content/common/plugin_constants_win.h" |
| 75 #endif | 79 #endif |
| 76 | 80 |
| 77 using base::Time; | 81 using base::Time; |
| 78 using base::TimeDelta; | 82 using base::TimeDelta; |
| 79 using base::TimeTicks; | 83 using base::TimeTicks; |
| 80 using blink::WebGestureEvent; | 84 using blink::WebGestureEvent; |
| 81 using blink::WebInputEvent; | 85 using blink::WebInputEvent; |
| 82 using blink::WebKeyboardEvent; | 86 using blink::WebKeyboardEvent; |
| 83 using blink::WebMouseEvent; | 87 using blink::WebMouseEvent; |
| 84 using blink::WebMouseWheelEvent; | 88 using blink::WebMouseWheelEvent; |
| 85 using blink::WebTextDirection; | 89 using blink::WebTextDirection; |
| 86 | 90 |
| 87 namespace content { | 91 namespace content { |
| 88 namespace { | 92 namespace { |
| 89 | 93 |
| 90 bool g_check_for_pending_resize_ack = true; | 94 bool g_check_for_pending_resize_ack = true; |
| 91 | 95 |
| 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; | 96 typedef std::pair<int32, int32> RenderWidgetHostID; |
| 99 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> | 97 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> |
| 100 RoutingIDWidgetMap; | 98 RoutingIDWidgetMap; |
| 101 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = | 99 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = |
| 102 LAZY_INSTANCE_INITIALIZER; | 100 LAZY_INSTANCE_INITIALIZER; |
| 103 | 101 |
| 104 int GetInputRouterViewFlagsFromCompositorFrameMetadata( | 102 int GetInputRouterViewFlagsFromCompositorFrameMetadata( |
| 105 const cc::CompositorFrameMetadata metadata) { | 103 const cc::CompositorFrameMetadata metadata) { |
| 106 int view_flags = InputRouter::VIEW_FLAGS_NONE; | 104 int view_flags = InputRouter::VIEW_FLAGS_NONE; |
| 107 | 105 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 OnShowDisambiguationPopup) | 467 OnShowDisambiguationPopup) |
| 470 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnSelectionChanged) | 468 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnSelectionChanged) |
| 471 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, | 469 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, |
| 472 OnSelectionBoundsChanged) | 470 OnSelectionBoundsChanged) |
| 473 #if defined(OS_WIN) | 471 #if defined(OS_WIN) |
| 474 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowCreated, | 472 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowCreated, |
| 475 OnWindowlessPluginDummyWindowCreated) | 473 OnWindowlessPluginDummyWindowCreated) |
| 476 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowDestroyed, | 474 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowDestroyed, |
| 477 OnWindowlessPluginDummyWindowDestroyed) | 475 OnWindowlessPluginDummyWindowDestroyed) |
| 478 #endif | 476 #endif |
| 479 #if defined(OS_MACOSX) | |
| 480 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped, | |
| 481 OnCompositorSurfaceBuffersSwapped) | |
| 482 #endif | |
| 483 #if defined(OS_MACOSX) || defined(USE_AURA) | 477 #if defined(OS_MACOSX) || defined(USE_AURA) |
| 484 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, | 478 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, |
| 485 OnImeCompositionRangeChanged) | 479 OnImeCompositionRangeChanged) |
| 486 #endif | 480 #endif |
| 487 IPC_MESSAGE_UNHANDLED(handled = false) | 481 IPC_MESSAGE_UNHANDLED(handled = false) |
| 488 IPC_END_MESSAGE_MAP() | 482 IPC_END_MESSAGE_MAP() |
| 489 | 483 |
| 490 if (!handled && input_router_ && input_router_->OnMessageReceived(msg)) | 484 if (!handled && input_router_ && input_router_->OnMessageReceived(msg)) |
| 491 return true; | 485 return true; |
| 492 | 486 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 if (view_) | 697 if (view_) |
| 704 view_->LockCompositingSurface(); | 698 view_->LockCompositingSurface(); |
| 705 } | 699 } |
| 706 | 700 |
| 707 void RenderWidgetHostImpl::UnlockBackingStore() { | 701 void RenderWidgetHostImpl::UnlockBackingStore() { |
| 708 if (view_) | 702 if (view_) |
| 709 view_->UnlockCompositingSurface(); | 703 view_->UnlockCompositingSurface(); |
| 710 } | 704 } |
| 711 #endif | 705 #endif |
| 712 | 706 |
| 707 #if defined(OS_MACOSX) |
| 713 void RenderWidgetHostImpl::PauseForPendingResizeOrRepaints() { | 708 void RenderWidgetHostImpl::PauseForPendingResizeOrRepaints() { |
| 714 TRACE_EVENT0("browser", | 709 TRACE_EVENT0("browser", |
| 715 "RenderWidgetHostImpl::PauseForPendingResizeOrRepaints"); | 710 "RenderWidgetHostImpl::PauseForPendingResizeOrRepaints"); |
| 716 | 711 |
| 717 if (!CanPauseForPendingResizeOrRepaints()) | 712 if (!CanPauseForPendingResizeOrRepaints()) |
| 718 return; | 713 return; |
| 719 | 714 |
| 720 WaitForSurface(); | 715 WaitForSurface(); |
| 721 } | 716 } |
| 722 | 717 |
| 723 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { | 718 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { |
| 724 // Do not pause if the view is hidden. | 719 // Do not pause if the view is hidden. |
| 725 if (is_hidden()) | 720 if (is_hidden()) |
| 726 return false; | 721 return false; |
| 727 | 722 |
| 728 // Do not pause if there is not a paint or resize already coming. | 723 // Do not pause if there is not a paint or resize already coming. |
| 729 if (!repaint_ack_pending_ && !resize_ack_pending_) | 724 if (!repaint_ack_pending_ && !resize_ack_pending_) |
| 730 return false; | 725 return false; |
| 731 | 726 |
| 732 return true; | 727 return true; |
| 733 } | 728 } |
| 734 | 729 |
| 735 void RenderWidgetHostImpl::WaitForSurface() { | 730 void RenderWidgetHostImpl::WaitForSurface() { |
| 736 TRACE_EVENT0("browser", "RenderWidgetHostImpl::WaitForSurface"); | 731 TRACE_EVENT0("browser", "RenderWidgetHostImpl::WaitForSurface"); |
| 737 | 732 |
| 733 // How long to (synchronously) wait for the renderer to respond with a |
| 734 // new frame when our current frame doesn't exist or is the wrong size. |
| 735 // This timeout impacts the "choppiness" of our window resize. |
| 736 const int kPaintMsgTimeoutMS = 50; |
| 737 |
| 738 if (!view_) | 738 if (!view_) |
| 739 return; | 739 return; |
| 740 | 740 |
| 741 // The view_size will be current_size_ for auto-sized views and otherwise the | 741 // 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 | 742 // size of the view_. (For auto-sized views, current_size_ is updated during |
| 743 // UpdateRect messages.) | 743 // UpdateRect messages.) |
| 744 gfx::Size view_size = current_size_; | 744 gfx::Size view_size = current_size_; |
| 745 if (!should_auto_resize_) { | 745 if (!should_auto_resize_) { |
| 746 // Get the desired size from the current view bounds. | 746 // Get the desired size from the current view bounds. |
| 747 gfx::Rect view_rect = view_->GetViewBounds(); | 747 gfx::Rect view_rect = view_->GetViewBounds(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 | 785 |
| 786 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); | 786 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); |
| 787 TimeTicks end_time = TimeTicks::Now() + max_delay; | 787 TimeTicks end_time = TimeTicks::Now() + max_delay; |
| 788 do { | 788 do { |
| 789 TRACE_EVENT0("renderer_host", "WaitForSurface::WaitForUpdate"); | 789 TRACE_EVENT0("renderer_host", "WaitForSurface::WaitForUpdate"); |
| 790 | 790 |
| 791 // When we have asked the RenderWidget to resize, and we are still waiting | 791 // 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 | 792 // 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. | 793 // before returning the old (incorrectly sized) backing store. |
| 794 IPC::Message msg; | 794 IPC::Message msg; |
| 795 if (process_->WaitForBackingStoreMsg(routing_id_, max_delay, &msg)) { | 795 if (RenderWidgetResizeHelper::Get()->WaitForSingleTaskToRun(max_delay)) { |
| 796 OnMessageReceived(msg); | |
| 797 | 796 |
| 798 // For auto-resized views, current_size_ determines the view_size and it | 797 // For auto-resized views, current_size_ determines the view_size and it |
| 799 // may have changed during the handling of an UpdateRect message. | 798 // may have changed during the handling of an UpdateRect message. |
| 800 if (should_auto_resize_) | 799 if (should_auto_resize_) |
| 801 view_size = current_size_; | 800 view_size = current_size_; |
| 802 | 801 |
| 803 // Break now if we got a backing store or accelerated surface of the | 802 // Break now if we got a backing store or accelerated surface of the |
| 804 // correct size. | 803 // correct size. |
| 805 if (view_->HasAcceleratedSurface(view_size)) | 804 if (view_->HasAcceleratedSurface(view_size)) |
| 806 return; | 805 return; |
| 807 } else { | 806 } else { |
| 808 TRACE_EVENT0("renderer_host", "WaitForSurface::Timeout"); | 807 TRACE_EVENT0("renderer_host", "WaitForSurface::Timeout"); |
| 809 break; | 808 break; |
| 810 } | 809 } |
| 811 | 810 |
| 812 // Loop if we still have time left and haven't gotten a properly sized | 811 // 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 | 812 // 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 | 813 // typically has multiple frames pipelined -- we may need to skip one or two |
| 815 // BackingStore messages to get to the latest. | 814 // BackingStore messages to get to the latest. |
| 816 max_delay = end_time - TimeTicks::Now(); | 815 max_delay = end_time - TimeTicks::Now(); |
| 817 } while (max_delay > TimeDelta::FromSeconds(0)); | 816 } while (max_delay > TimeDelta::FromSeconds(0)); |
| 818 } | 817 } |
| 818 #endif |
| 819 | 819 |
| 820 bool RenderWidgetHostImpl::ScheduleComposite() { | 820 bool RenderWidgetHostImpl::ScheduleComposite() { |
| 821 if (is_hidden_ || current_size_.IsEmpty() || repaint_ack_pending_ || | 821 if (is_hidden_ || current_size_.IsEmpty() || repaint_ack_pending_ || |
| 822 resize_ack_pending_) { | 822 resize_ack_pending_) { |
| 823 return false; | 823 return false; |
| 824 } | 824 } |
| 825 | 825 |
| 826 // Send out a request to the renderer to paint the view if required. | 826 // Send out a request to the renderer to paint the view if required. |
| 827 repaint_start_time_ = TimeTicks::Now(); | 827 repaint_start_time_ = TimeTicks::Now(); |
| 828 repaint_ack_pending_ = true; | 828 repaint_ack_pending_ = true; |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1406 SendScreenRects(); | 1406 SendScreenRects(); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { | 1409 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { |
| 1410 if (view_) { | 1410 if (view_) { |
| 1411 view_->SetBounds(pos); | 1411 view_->SetBounds(pos); |
| 1412 Send(new ViewMsg_Move_ACK(routing_id_)); | 1412 Send(new ViewMsg_Move_ACK(routing_id_)); |
| 1413 } | 1413 } |
| 1414 } | 1414 } |
| 1415 | 1415 |
| 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( | 1416 bool RenderWidgetHostImpl::OnSwapCompositorFrame( |
| 1454 const IPC::Message& message) { | 1417 const IPC::Message& message) { |
| 1455 // This trace event is used in | 1418 // This trace event is used in |
| 1456 // chrome/browser/extensions/api/cast_streaming/performance_test.cc | 1419 // chrome/browser/extensions/api/cast_streaming/performance_test.cc |
| 1457 UNSHIPPED_TRACE_EVENT0("test_fps", | 1420 UNSHIPPED_TRACE_EVENT0("test_fps", |
| 1458 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame")); | 1421 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame")); |
| 1459 ViewHostMsg_SwapCompositorFrame::Param param; | 1422 ViewHostMsg_SwapCompositorFrame::Param param; |
| 1460 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1423 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 1461 return false; | 1424 return false; |
| 1462 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 1425 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2381 } | 2344 } |
| 2382 } | 2345 } |
| 2383 | 2346 |
| 2384 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2347 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
| 2385 if (view_) | 2348 if (view_) |
| 2386 return view_->PreferredReadbackFormat(); | 2349 return view_->PreferredReadbackFormat(); |
| 2387 return kN32_SkColorType; | 2350 return kN32_SkColorType; |
| 2388 } | 2351 } |
| 2389 | 2352 |
| 2390 } // namespace content | 2353 } // namespace content |
| OLD | NEW |