Chromium Code Reviews| Index: content/browser/renderer_host/render_widget_host_impl.cc |
| diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc |
| index 2c57a2b78d543dafaff3170cf9d2447cc2ce5d62..7819365497b2b5ecc0f28ea6b69396a6a6212384 100644 |
| --- a/content/browser/renderer_host/render_widget_host_impl.cc |
| +++ b/content/browser/renderer_host/render_widget_host_impl.cc |
| @@ -89,6 +89,9 @@ namespace { |
| bool g_check_for_pending_resize_ack = true; |
| +const size_t kBrowserCompositeLatencyHistorySize = 60; |
| +const double kBrowserCompositeLatencyEstimationPercentile = 90.0; |
| + |
| typedef std::pair<int32, int32> RenderWidgetHostID; |
| typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> |
| RoutingIDWidgetMap; |
| @@ -186,7 +189,8 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
| has_touch_handler_(false), |
| weak_factory_(this), |
| last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
| - next_browser_snapshot_id_(1) { |
| + next_browser_snapshot_id_(1), |
| + browser_composite_latency_history_(kBrowserCompositeLatencyHistorySize) { |
| CHECK(delegate_); |
| if (routing_id_ == MSG_ROUTING_NONE) { |
| routing_id_ = process_->GetNextRoutingID(); |
| @@ -1451,6 +1455,13 @@ bool RenderWidgetHostImpl::OnSwapCompositorFrame( |
| input_router_->OnViewUpdated( |
| GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata)); |
| + for (size_t i = 0; i < frame->metadata.latency_info.size(); ++i) { |
| + frame->metadata.latency_info[i].AddLatencyNumber( |
| + ui::INPUT_EVENT_RENDERER_SWAP_RECEIVED_COMPONENT, |
| + GetLatencyComponentId(), |
| + 0); |
| + } |
| + |
| if (view_) { |
| view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); |
| view_->DidReceiveRendererFrame(); |
| @@ -2142,6 +2153,21 @@ void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
| 100); |
| } |
| } |
| + |
| + ui::LatencyInfo::LatencyComponent gpu_swap_component; |
| + if (!latency_info.FindLatency( |
| + ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, &gpu_swap_component)) { |
| + return; |
| + } |
| + |
| + ui::LatencyInfo::LatencyComponent composite_component; |
| + if (latency_info.FindLatency(ui::INPUT_EVENT_RENDERER_SWAP_RECEIVED_COMPONENT, |
| + GetLatencyComponentId(), |
| + &composite_component)) { |
| + base::TimeDelta delta = |
| + gpu_swap_component.event_time - composite_component.event_time; |
| + browser_composite_latency_history_.InsertSample(delta); |
| + } |
| } |
| void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| @@ -2260,7 +2286,8 @@ void RenderWidgetHostImpl::CompositorFrameDrawn( |
| if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
| b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
| b->first.first == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
| - b->first.first == ui::TAB_SHOW_COMPONENT) { |
| + b->first.first == ui::TAB_SHOW_COMPONENT || |
| + b->first.first == ui::INPUT_EVENT_RENDERER_SWAP_RECEIVED_COMPONENT) { |
| // Matches with GetLatencyComponentId |
| int routing_id = b->first.second & 0xffffffff; |
| int process_id = (b->first.second >> 32) & 0xffffffff; |
| @@ -2315,6 +2342,16 @@ BrowserAccessibilityManager* |
| delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
| } |
| +base::TimeDelta RenderWidgetHostImpl::GetEstimatedBrowserCompositeTime() { |
| + if (browser_composite_latency_history_.SampleCount() > 0) { |
| + return browser_composite_latency_history_.Percentile( |
|
brianderson
2014/09/22 22:59:35
Let's add some slack to the estimate by multiplyin
orglofch
2014/09/22 23:55:14
Done.
|
| + kBrowserCompositeLatencyEstimationPercentile); |
| + } else { |
| + return base::TimeDelta::FromMicroseconds( |
| + (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); |
| + } |
| +} |
| + |
| #if defined(OS_WIN) |
| gfx::NativeViewAccessible |
| RenderWidgetHostImpl::GetParentNativeViewAccessible() { |