Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1707)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698