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 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1447 } | 1447 } |
1448 } | 1448 } |
1449 | 1449 |
1450 void RenderWidgetHostImpl::GetSnapshotFromBrowser( | 1450 void RenderWidgetHostImpl::GetSnapshotFromBrowser( |
1451 const GetSnapshotFromBrowserCallback& callback, | 1451 const GetSnapshotFromBrowserCallback& callback, |
1452 bool from_surface) { | 1452 bool from_surface) { |
1453 int id = next_browser_snapshot_id_++; | 1453 int id = next_browser_snapshot_id_++; |
1454 if (from_surface) { | 1454 if (from_surface) { |
1455 pending_surface_browser_snapshots_.insert(std::make_pair(id, callback)); | 1455 pending_surface_browser_snapshots_.insert(std::make_pair(id, callback)); |
1456 ui::LatencyInfo latency_info; | 1456 ui::LatencyInfo latency_info; |
1457 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | 1457 latency_info.AddLatencyNumber(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
1458 id); | 1458 0, id); |
1459 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | 1459 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); |
1460 return; | 1460 return; |
1461 } | 1461 } |
1462 | 1462 |
1463 #if defined(OS_MACOSX) | 1463 #if defined(OS_MACOSX) |
1464 // MacOS version of underlying GrabViewSnapshot() blocks while | 1464 // MacOS version of underlying GrabViewSnapshot() blocks while |
1465 // display/GPU are in a power-saving mode, so make sure display | 1465 // display/GPU are in a power-saving mode, so make sure display |
1466 // does not go to sleep for the duration of reading a snapshot. | 1466 // does not go to sleep for the duration of reading a snapshot. |
1467 if (pending_browser_snapshots_.empty()) { | 1467 if (pending_browser_snapshots_.empty()) { |
1468 DCHECK(!power_save_blocker_); | 1468 DCHECK(!power_save_blocker_); |
1469 power_save_blocker_.reset(new device::PowerSaveBlocker( | 1469 power_save_blocker_.reset(new device::PowerSaveBlocker( |
1470 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 1470 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
1471 device::PowerSaveBlocker::kReasonOther, "GetSnapshot", | 1471 device::PowerSaveBlocker::kReasonOther, "GetSnapshot", |
1472 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 1472 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
1473 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 1473 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
1474 } | 1474 } |
1475 #endif | 1475 #endif |
1476 pending_browser_snapshots_.insert(std::make_pair(id, callback)); | 1476 pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
1477 ui::LatencyInfo latency_info; | 1477 ui::LatencyInfo latency_info; |
1478 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | 1478 latency_info.AddLatencyNumber(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, |
1479 id); | 1479 id); |
1480 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | 1480 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); |
1481 } | 1481 } |
1482 | 1482 |
1483 const NativeWebKeyboardEvent* | 1483 const NativeWebKeyboardEvent* |
1484 RenderWidgetHostImpl::GetLastKeyboardEvent() const { | 1484 RenderWidgetHostImpl::GetLastKeyboardEvent() const { |
1485 return input_router_->GetLastKeyboardEvent(); | 1485 return input_router_->GetLastKeyboardEvent(); |
1486 } | 1486 } |
1487 | 1487 |
1488 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, | 1488 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1751 delegate_->RendererResponsive(this); | 1751 delegate_->RendererResponsive(this); |
1752 } | 1752 } |
1753 } | 1753 } |
1754 | 1754 |
1755 void RenderWidgetHostImpl::ClearDisplayedGraphics() { | 1755 void RenderWidgetHostImpl::ClearDisplayedGraphics() { |
1756 NotifyNewContentRenderingTimeoutForTesting(); | 1756 NotifyNewContentRenderingTimeoutForTesting(); |
1757 if (view_) | 1757 if (view_) |
1758 view_->ClearCompositorFrame(); | 1758 view_->ClearCompositorFrame(); |
1759 } | 1759 } |
1760 | 1760 |
1761 void RenderWidgetHostImpl::OnGpuSwapBufersCompletedInternal( | |
1762 const ui::LatencyInfo& latency_info) { | |
1763 ui::LatencyInfo::LatencyComponent window_snapshot_component; | |
1764 if (latency_info.FindLatency(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, | |
1765 GetLatencyComponentId(), | |
1766 &window_snapshot_component)) { | |
1767 int sequence_number = | |
1768 static_cast<int>(window_snapshot_component.sequence_number); | |
1769 #if defined(OS_MACOSX) | |
1770 // On Mac, when using CoreAnmation, there is a delay between when content | |
tdresser
2017/04/03 15:57:11
CoreAnmation -> CoreAnimation
mfomitchev
2017/04/03 17:31:00
Done.
| |
1771 // is drawn to the screen, and when the snapshot will actually pick up | |
1772 // that content. Insert a manual delay of 1/6th of a second (to simulate | |
1773 // 10 frames at 60 fps) before actually taking the snapshot. | |
1774 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
1775 FROM_HERE, | |
1776 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, | |
1777 weak_factory_.GetWeakPtr(), sequence_number), | |
1778 base::TimeDelta::FromSecondsD(1. / 6)); | |
1779 #else | |
1780 WindowSnapshotReachedScreen(sequence_number); | |
1781 #endif | |
1782 } | |
1783 | |
1784 latency_tracker_.OnGpuSwapBufersCompleted(latency_info); | |
1785 } | |
1786 | |
1761 void RenderWidgetHostImpl::OnRenderProcessGone(int status, int exit_code) { | 1787 void RenderWidgetHostImpl::OnRenderProcessGone(int status, int exit_code) { |
1762 // RenderFrameHost owns a RenderWidgetHost when it needs one, in which case | 1788 // RenderFrameHost owns a RenderWidgetHost when it needs one, in which case |
1763 // it handles destruction. | 1789 // it handles destruction. |
1764 if (!owned_by_render_frame_host_) { | 1790 if (!owned_by_render_frame_host_) { |
1765 // TODO(evanm): This synchronously ends up calling "delete this". | 1791 // TODO(evanm): This synchronously ends up calling "delete this". |
1766 // Is that really what we want in response to this message? I'm matching | 1792 // Is that really what we want in response to this message? I'm matching |
1767 // previous behavior of the code here. | 1793 // previous behavior of the code here. |
1768 Destroy(true); | 1794 Destroy(true); |
1769 } else { | 1795 } else { |
1770 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); | 1796 RendererExited(static_cast<base::TerminationStatus>(status), exit_code); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2333 | 2359 |
2334 if (delegate_) | 2360 if (delegate_) |
2335 delegate_->ResizeDueToAutoResize(this, new_size); | 2361 delegate_->ResizeDueToAutoResize(this, new_size); |
2336 } | 2362 } |
2337 | 2363 |
2338 void RenderWidgetHostImpl::DetachDelegate() { | 2364 void RenderWidgetHostImpl::DetachDelegate() { |
2339 delegate_ = NULL; | 2365 delegate_ = NULL; |
2340 latency_tracker_.SetDelegate(nullptr); | 2366 latency_tracker_.SetDelegate(nullptr); |
2341 } | 2367 } |
2342 | 2368 |
2343 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | |
2344 ui::LatencyInfo::LatencyComponent window_snapshot_component; | |
2345 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, | |
2346 GetLatencyComponentId(), | |
2347 &window_snapshot_component)) { | |
2348 int sequence_number = static_cast<int>( | |
2349 window_snapshot_component.sequence_number); | |
2350 #if defined(OS_MACOSX) | |
2351 // On Mac, when using CoreAnmation, there is a delay between when content | |
2352 // is drawn to the screen, and when the snapshot will actually pick up | |
2353 // that content. Insert a manual delay of 1/6th of a second (to simulate | |
2354 // 10 frames at 60 fps) before actually taking the snapshot. | |
2355 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
2356 FROM_HERE, | |
2357 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, | |
2358 weak_factory_.GetWeakPtr(), sequence_number), | |
2359 base::TimeDelta::FromSecondsD(1. / 6)); | |
2360 #else | |
2361 WindowSnapshotReachedScreen(sequence_number); | |
2362 #endif | |
2363 } | |
2364 | |
2365 latency_tracker_.OnFrameSwapped(latency_info); | |
2366 } | |
2367 | |
2368 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2369 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
2369 view_->DidReceiveRendererFrame(); | 2370 view_->DidReceiveRendererFrame(); |
2370 } | 2371 } |
2371 | 2372 |
2372 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2373 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
2373 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2374 DCHECK(base::MessageLoopForUI::IsCurrent()); |
2374 | 2375 |
2375 if (!pending_surface_browser_snapshots_.empty()) { | 2376 if (!pending_surface_browser_snapshots_.empty()) { |
2376 GetView()->CopyFromSurface( | 2377 GetView()->CopyFromSurface( |
2377 gfx::Rect(), gfx::Size(), | 2378 gfx::Rect(), gfx::Size(), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2448 ++it; | 2449 ++it; |
2449 } | 2450 } |
2450 } | 2451 } |
2451 #if defined(OS_MACOSX) | 2452 #if defined(OS_MACOSX) |
2452 if (pending_browser_snapshots_.empty()) | 2453 if (pending_browser_snapshots_.empty()) |
2453 power_save_blocker_.reset(); | 2454 power_save_blocker_.reset(); |
2454 #endif | 2455 #endif |
2455 } | 2456 } |
2456 | 2457 |
2457 // static | 2458 // static |
2458 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2459 void RenderWidgetHostImpl::OnGpuSwapBufersCompleted( |
2459 const std::vector<ui::LatencyInfo>& latency_info) { | 2460 const std::vector<ui::LatencyInfo>& latency_info) { |
2460 for (size_t i = 0; i < latency_info.size(); i++) { | 2461 for (size_t i = 0; i < latency_info.size(); i++) { |
2461 std::set<RenderWidgetHostImpl*> rwhi_set; | 2462 std::set<RenderWidgetHostImpl*> rwhi_set; |
2462 for (const auto& lc : latency_info[i].latency_components()) { | 2463 for (const auto& lc : latency_info[i].latency_components()) { |
2463 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2464 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
2464 lc.first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || | 2465 lc.first.first == ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
2465 lc.first.first == ui::TAB_SHOW_COMPONENT) { | 2466 lc.first.first == ui::TAB_SHOW_COMPONENT) { |
2466 // Matches with GetLatencyComponentId | 2467 // Matches with GetLatencyComponentId |
2467 int routing_id = lc.first.second & 0xffffffff; | 2468 int routing_id = lc.first.second & 0xffffffff; |
2468 int process_id = (lc.first.second >> 32) & 0xffffffff; | 2469 int process_id = (lc.first.second >> 32) & 0xffffffff; |
2469 RenderWidgetHost* rwh = | 2470 RenderWidgetHost* rwh = |
2470 RenderWidgetHost::FromID(process_id, routing_id); | 2471 RenderWidgetHost::FromID(process_id, routing_id); |
2471 if (!rwh) { | 2472 if (!rwh) { |
2472 continue; | 2473 continue; |
2473 } | 2474 } |
2474 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 2475 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
2475 if (rwhi_set.insert(rwhi).second) | 2476 if (rwhi_set.insert(rwhi).second) |
2476 rwhi->FrameSwapped(latency_info[i]); | 2477 rwhi->OnGpuSwapBufersCompletedInternal(latency_info[i]); |
2477 } | 2478 } |
2478 } | 2479 } |
2479 } | 2480 } |
2480 } | 2481 } |
2481 | 2482 |
2482 BrowserAccessibilityManager* | 2483 BrowserAccessibilityManager* |
2483 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { | 2484 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { |
2484 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; | 2485 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; |
2485 } | 2486 } |
2486 | 2487 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2653 | 2654 |
2654 // After navigation, if a frame belonging to the new page is received, stop | 2655 // After navigation, if a frame belonging to the new page is received, stop |
2655 // the timer that triggers clearing the graphics of the last page. | 2656 // the timer that triggers clearing the graphics of the last page. |
2656 if (last_received_content_source_id_ >= current_content_source_id_ && | 2657 if (last_received_content_source_id_ >= current_content_source_id_ && |
2657 new_content_rendering_timeout_->IsRunning()) { | 2658 new_content_rendering_timeout_->IsRunning()) { |
2658 new_content_rendering_timeout_->Stop(); | 2659 new_content_rendering_timeout_->Stop(); |
2659 } | 2660 } |
2660 } | 2661 } |
2661 | 2662 |
2662 } // namespace content | 2663 } // namespace content |
OLD | NEW |