| 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 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 owned_by_render_frame_host_(false), | 291 owned_by_render_frame_host_(false), |
| 292 is_focused_(false), | 292 is_focused_(false), |
| 293 hung_renderer_delay_( | 293 hung_renderer_delay_( |
| 294 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 294 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 295 hang_monitor_event_type_(blink::WebInputEvent::kUndefined), | 295 hang_monitor_event_type_(blink::WebInputEvent::kUndefined), |
| 296 last_event_type_(blink::WebInputEvent::kUndefined), | 296 last_event_type_(blink::WebInputEvent::kUndefined), |
| 297 new_content_rendering_delay_( | 297 new_content_rendering_delay_( |
| 298 base::TimeDelta::FromMilliseconds(kNewContentRenderingDelayMs)), | 298 base::TimeDelta::FromMilliseconds(kNewContentRenderingDelayMs)), |
| 299 current_content_source_id_(0), | 299 current_content_source_id_(0), |
| 300 monitoring_composition_info_(false), | 300 monitoring_composition_info_(false), |
| 301 compositor_frame_sink_binding_(this), | |
| 302 weak_factory_(this) { | 301 weak_factory_(this) { |
| 303 CHECK(delegate_); | 302 CHECK(delegate_); |
| 304 CHECK_NE(MSG_ROUTING_NONE, routing_id_); | 303 CHECK_NE(MSG_ROUTING_NONE, routing_id_); |
| 305 latency_tracker_.SetDelegate(delegate_); | 304 latency_tracker_.SetDelegate(delegate_); |
| 306 | 305 |
| 307 DCHECK(base::TaskScheduler::GetInstance()) | 306 DCHECK(base::TaskScheduler::GetInstance()) |
| 308 << "Ref. Prerequisite section of post_task.h"; | 307 << "Ref. Prerequisite section of post_task.h"; |
| 309 #if defined(OS_WIN) | 308 #if defined(OS_WIN) |
| 310 // Update the display color profile cache so that it is likely to be up to | 309 // Update the display color profile cache so that it is likely to be up to |
| 311 // date when the renderer process requests the color profile. | 310 // date when the renderer process requests the color profile. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } | 406 } |
| 408 | 407 |
| 409 // static | 408 // static |
| 410 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { | 409 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { |
| 411 return static_cast<RenderWidgetHostImpl*>(rwh); | 410 return static_cast<RenderWidgetHostImpl*>(rwh); |
| 412 } | 411 } |
| 413 | 412 |
| 414 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { | 413 void RenderWidgetHostImpl::SetView(RenderWidgetHostViewBase* view) { |
| 415 if (view) { | 414 if (view) { |
| 416 view_ = view->GetWeakPtr(); | 415 view_ = view->GetWeakPtr(); |
| 417 if (renderer_compositor_frame_sink_.is_bound()) { | |
| 418 view->DidCreateNewRendererCompositorFrameSink( | |
| 419 renderer_compositor_frame_sink_.get()); | |
| 420 } | |
| 421 // Views start out not needing begin frames, so only update its state | 416 // Views start out not needing begin frames, so only update its state |
| 422 // if the value has changed. | 417 // if the value has changed. |
| 423 if (needs_begin_frames_) | 418 if (needs_begin_frames_) |
| 424 view_->SetNeedsBeginFrames(needs_begin_frames_); | 419 view_->SetNeedsBeginFrames(needs_begin_frames_); |
| 425 } else { | 420 } else { |
| 426 view_.reset(); | 421 view_.reset(); |
| 427 } | 422 } |
| 428 | 423 |
| 429 synthetic_gesture_controller_.reset(); | 424 synthetic_gesture_controller_.reset(); |
| 430 } | 425 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 IPC_MESSAGE_HANDLER(FrameHostMsg_HittestData, OnHittestData) | 551 IPC_MESSAGE_HANDLER(FrameHostMsg_HittestData, OnHittestData) |
| 557 IPC_MESSAGE_HANDLER(InputHostMsg_QueueSyntheticGesture, | 552 IPC_MESSAGE_HANDLER(InputHostMsg_QueueSyntheticGesture, |
| 558 OnQueueSyntheticGesture) | 553 OnQueueSyntheticGesture) |
| 559 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, | 554 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, |
| 560 OnImeCancelComposition) | 555 OnImeCancelComposition) |
| 561 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) | 556 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnClose) |
| 562 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, | 557 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateScreenRects_ACK, |
| 563 OnUpdateScreenRectsAck) | 558 OnUpdateScreenRectsAck) |
| 564 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) | 559 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnRequestMove) |
| 565 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnSetTooltipText) | 560 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnSetTooltipText) |
| 566 IPC_MESSAGE_HANDLER(ViewHostMsg_BeginFrameDidNotSwap, BeginFrameDidNotSwap) | 561 IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame, |
| 562 OnSwapCompositorFrame(msg)) |
| 563 IPC_MESSAGE_HANDLER(ViewHostMsg_BeginFrameDidNotSwap, |
| 564 OnBeginFrameDidNotSwap) |
| 567 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 565 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 568 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 566 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
| 569 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, | 567 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, |
| 570 OnTextInputStateChanged) | 568 OnTextInputStateChanged) |
| 571 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 569 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
| 572 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 570 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
| 573 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup, | 571 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup, |
| 574 OnShowDisambiguationPopup) | 572 OnShowDisambiguationPopup) |
| 575 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, | 573 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, |
| 576 OnSelectionBoundsChanged) | 574 OnSelectionBoundsChanged) |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 | 863 |
| 866 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { | 864 bool RenderWidgetHostImpl::CanPauseForPendingResizeOrRepaints() { |
| 867 // Do not pause if the view is hidden. | 865 // Do not pause if the view is hidden. |
| 868 if (is_hidden()) | 866 if (is_hidden()) |
| 869 return false; | 867 return false; |
| 870 | 868 |
| 871 // Do not pause if there is not a paint or resize already coming. | 869 // Do not pause if there is not a paint or resize already coming. |
| 872 if (!repaint_ack_pending_ && !resize_ack_pending_) | 870 if (!repaint_ack_pending_ && !resize_ack_pending_) |
| 873 return false; | 871 return false; |
| 874 | 872 |
| 875 if (!renderer_compositor_frame_sink_.is_bound()) | |
| 876 return false; | |
| 877 | |
| 878 return true; | 873 return true; |
| 879 } | 874 } |
| 880 | 875 |
| 881 void RenderWidgetHostImpl::WaitForSurface() { | 876 void RenderWidgetHostImpl::WaitForSurface() { |
| 882 // How long to (synchronously) wait for the renderer to respond with a | 877 // How long to (synchronously) wait for the renderer to respond with a |
| 883 // new frame when our current frame doesn't exist or is the wrong size. | 878 // new frame when our current frame doesn't exist or is the wrong size. |
| 884 // This timeout impacts the "choppiness" of our window resize. | 879 // This timeout impacts the "choppiness" of our window resize. |
| 885 const int kPaintMsgTimeoutMS = 50; | 880 const int kPaintMsgTimeoutMS = 50; |
| 886 | 881 |
| 887 if (!view_) | 882 if (!view_) |
| (...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 SendScreenRects(); | 1913 SendScreenRects(); |
| 1919 } | 1914 } |
| 1920 | 1915 |
| 1921 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { | 1916 void RenderWidgetHostImpl::OnRequestMove(const gfx::Rect& pos) { |
| 1922 if (view_) { | 1917 if (view_) { |
| 1923 view_->SetBounds(pos); | 1918 view_->SetBounds(pos); |
| 1924 Send(new ViewMsg_Move_ACK(routing_id_)); | 1919 Send(new ViewMsg_Move_ACK(routing_id_)); |
| 1925 } | 1920 } |
| 1926 } | 1921 } |
| 1927 | 1922 |
| 1928 void RenderWidgetHostImpl::BeginFrameDidNotSwap(const cc::BeginFrameAck& ack) { | 1923 bool RenderWidgetHostImpl::OnSwapCompositorFrame(const IPC::Message& message) { |
| 1924 // This trace event is used in |
| 1925 // chrome/browser/extensions/api/cast_streaming/performance_test.cc |
| 1926 TRACE_EVENT0("test_fps,benchmark", "OnSwapCompositorFrame"); |
| 1927 |
| 1928 ViewHostMsg_SwapCompositorFrame::Param param; |
| 1929 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
| 1930 return false; |
| 1931 uint32_t compositor_frame_sink_id = std::get<0>(param); |
| 1932 cc::LocalSurfaceId local_surface_id = std::get<1>(param); |
| 1933 cc::CompositorFrame frame(std::move(std::get<2>(param))); |
| 1934 |
| 1935 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { |
| 1936 if (view_) |
| 1937 view_->DidCreateNewRendererCompositorFrameSink(); |
| 1938 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 1939 } |
| 1940 |
| 1941 SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 1942 |
| 1943 return true; |
| 1944 } |
| 1945 |
| 1946 void RenderWidgetHostImpl::OnBeginFrameDidNotSwap( |
| 1947 const cc::BeginFrameAck& ack) { |
| 1929 // |has_damage| is not transmitted. | 1948 // |has_damage| is not transmitted. |
| 1930 cc::BeginFrameAck modified_ack = ack; | 1949 cc::BeginFrameAck modified_ack = ack; |
| 1931 modified_ack.has_damage = false; | 1950 modified_ack.has_damage = false; |
| 1932 | 1951 |
| 1933 if (view_) | 1952 if (view_) |
| 1934 view_->OnBeginFrameDidNotSwap(modified_ack); | 1953 view_->OnBeginFrameDidNotSwap(modified_ack); |
| 1935 } | 1954 } |
| 1936 | 1955 |
| 1937 void RenderWidgetHostImpl::OnUpdateRect( | 1956 void RenderWidgetHostImpl::OnUpdateRect( |
| 1938 const ViewHostMsg_UpdateRect_Params& params) { | 1957 const ViewHostMsg_UpdateRect_Params& params) { |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2355 pending_mouse_lock_request_ = false; | 2374 pending_mouse_lock_request_ = false; |
| 2356 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) { | 2375 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) { |
| 2357 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); | 2376 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); |
| 2358 return false; | 2377 return false; |
| 2359 } | 2378 } |
| 2360 | 2379 |
| 2361 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); | 2380 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); |
| 2362 return true; | 2381 return true; |
| 2363 } | 2382 } |
| 2364 | 2383 |
| 2384 void RenderWidgetHostImpl::SendReclaimCompositorResources( |
| 2385 bool is_swap_ack, |
| 2386 const cc::ReturnedResourceArray& resources) { |
| 2387 Send(new ViewMsg_ReclaimCompositorResources( |
| 2388 routing_id_, last_compositor_frame_sink_id_, is_swap_ack, resources)); |
| 2389 } |
| 2390 |
| 2365 void RenderWidgetHostImpl::DelayedAutoResized() { | 2391 void RenderWidgetHostImpl::DelayedAutoResized() { |
| 2366 gfx::Size new_size = new_auto_size_; | 2392 gfx::Size new_size = new_auto_size_; |
| 2367 // Clear the new_auto_size_ since the empty value is used as a flag to | 2393 // Clear the new_auto_size_ since the empty value is used as a flag to |
| 2368 // indicate that no callback is in progress (i.e. without this line | 2394 // indicate that no callback is in progress (i.e. without this line |
| 2369 // DelayedAutoResized will not get called again). | 2395 // DelayedAutoResized will not get called again). |
| 2370 new_auto_size_.SetSize(0, 0); | 2396 new_auto_size_.SetSize(0, 0); |
| 2371 if (!auto_resize_enabled_) | 2397 if (!auto_resize_enabled_) |
| 2372 return; | 2398 return; |
| 2373 | 2399 |
| 2374 if (delegate_) | 2400 if (delegate_) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2515 | 2541 |
| 2516 void RenderWidgetHostImpl::RequestCompositionUpdates(bool immediate_request, | 2542 void RenderWidgetHostImpl::RequestCompositionUpdates(bool immediate_request, |
| 2517 bool monitor_updates) { | 2543 bool monitor_updates) { |
| 2518 if (!immediate_request && monitor_updates == monitoring_composition_info_) | 2544 if (!immediate_request && monitor_updates == monitoring_composition_info_) |
| 2519 return; | 2545 return; |
| 2520 monitoring_composition_info_ = monitor_updates; | 2546 monitoring_composition_info_ = monitor_updates; |
| 2521 Send(new InputMsg_RequestCompositionUpdates(routing_id_, immediate_request, | 2547 Send(new InputMsg_RequestCompositionUpdates(routing_id_, immediate_request, |
| 2522 monitor_updates)); | 2548 monitor_updates)); |
| 2523 } | 2549 } |
| 2524 | 2550 |
| 2525 void RenderWidgetHostImpl::RequestMojoCompositorFrameSink( | |
| 2526 cc::mojom::MojoCompositorFrameSinkRequest request, | |
| 2527 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | |
| 2528 if (compositor_frame_sink_binding_.is_bound()) | |
| 2529 compositor_frame_sink_binding_.Close(); | |
| 2530 #if defined(OS_MACOSX) | |
| 2531 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
| 2532 ui::WindowResizeHelperMac::Get()->task_runner(); | |
| 2533 // In tests, task_runner might not be initialized. | |
| 2534 if (task_runner) | |
| 2535 compositor_frame_sink_binding_.Bind(std::move(request), task_runner); | |
| 2536 else | |
| 2537 compositor_frame_sink_binding_.Bind(std::move(request)); | |
| 2538 #else | |
| 2539 compositor_frame_sink_binding_.Bind(std::move(request)); | |
| 2540 #endif | |
| 2541 if (view_) | |
| 2542 view_->DidCreateNewRendererCompositorFrameSink(client.get()); | |
| 2543 renderer_compositor_frame_sink_ = std::move(client); | |
| 2544 } | |
| 2545 | |
| 2546 void RenderWidgetHostImpl::SetNeedsBeginFrame(bool needs_begin_frame) { | |
| 2547 OnSetNeedsBeginFrames(needs_begin_frame); | |
| 2548 } | |
| 2549 | |
| 2550 void RenderWidgetHostImpl::SubmitCompositorFrame( | 2551 void RenderWidgetHostImpl::SubmitCompositorFrame( |
| 2551 const cc::LocalSurfaceId& local_surface_id, | 2552 const cc::LocalSurfaceId& local_surface_id, |
| 2552 cc::CompositorFrame frame) { | 2553 cc::CompositorFrame frame) { |
| 2553 // The renderer must allocate a new LocalSurfaceId if frame size or device | 2554 // The renderer must allocate a new LocalSurfaceId if frame size or device |
| 2554 // scale factor changes. | 2555 // scale factor changes. |
| 2555 float device_scale_factor = frame.metadata.device_scale_factor; | 2556 float device_scale_factor = frame.metadata.device_scale_factor; |
| 2556 const gfx::Size& frame_size = | 2557 const gfx::Size& frame_size = |
| 2557 frame.render_pass_list.back()->output_rect.size(); | 2558 frame.render_pass_list.back()->output_rect.size(); |
| 2558 if (local_surface_id == last_local_surface_id_ && | 2559 if (local_surface_id == last_local_surface_id_ && |
| 2559 (frame_size != last_frame_size_ || | 2560 (frame_size != last_frame_size_ || |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2596 // stale graphics on top-level frames. We accept frames that have a source ID | 2597 // stale graphics on top-level frames. We accept frames that have a source ID |
| 2597 // greater than |current_content_source_id_| because in some cases the first | 2598 // greater than |current_content_source_id_| because in some cases the first |
| 2598 // compositor frame can arrive before the navigation commit message that | 2599 // compositor frame can arrive before the navigation commit message that |
| 2599 // updates that value. | 2600 // updates that value. |
| 2600 if (view_ && frame.metadata.content_source_id >= current_content_source_id_) { | 2601 if (view_ && frame.metadata.content_source_id >= current_content_source_id_) { |
| 2601 view_->SubmitCompositorFrame(local_surface_id, std::move(frame)); | 2602 view_->SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 2602 view_->DidReceiveRendererFrame(); | 2603 view_->DidReceiveRendererFrame(); |
| 2603 } else { | 2604 } else { |
| 2604 cc::ReturnedResourceArray resources; | 2605 cc::ReturnedResourceArray resources; |
| 2605 cc::TransferableResource::ReturnResources(frame.resource_list, &resources); | 2606 cc::TransferableResource::ReturnResources(frame.resource_list, &resources); |
| 2606 renderer_compositor_frame_sink_->DidReceiveCompositorFrameAck(resources); | 2607 SendReclaimCompositorResources(true /* is_swap_ack */, resources); |
| 2607 } | 2608 } |
| 2608 | 2609 |
| 2609 // After navigation, if a frame belonging to the new page is received, stop | 2610 // After navigation, if a frame belonging to the new page is received, stop |
| 2610 // the timer that triggers clearing the graphics of the last page. | 2611 // the timer that triggers clearing the graphics of the last page. |
| 2611 if (last_received_content_source_id_ >= current_content_source_id_ && | 2612 if (last_received_content_source_id_ >= current_content_source_id_ && |
| 2612 new_content_rendering_timeout_->IsRunning()) { | 2613 new_content_rendering_timeout_->IsRunning()) { |
| 2613 new_content_rendering_timeout_->Stop(); | 2614 new_content_rendering_timeout_->Stop(); |
| 2614 } | 2615 } |
| 2615 | 2616 |
| 2616 if (delegate_) | 2617 if (delegate_) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2642 RenderProcessHost* rph = GetProcess(); | 2643 RenderProcessHost* rph = GetProcess(); |
| 2643 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); | 2644 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); |
| 2644 i != messages.end(); ++i) { | 2645 i != messages.end(); ++i) { |
| 2645 rph->OnMessageReceived(*i); | 2646 rph->OnMessageReceived(*i); |
| 2646 if (i->dispatch_error()) | 2647 if (i->dispatch_error()) |
| 2647 rph->OnBadMessageReceived(*i); | 2648 rph->OnBadMessageReceived(*i); |
| 2648 } | 2649 } |
| 2649 } | 2650 } |
| 2650 | 2651 |
| 2651 } // namespace content | 2652 } // namespace content |
| OLD | NEW |