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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 using blink::WebKeyboardEvent; | 82 using blink::WebKeyboardEvent; |
83 using blink::WebMouseEvent; | 83 using blink::WebMouseEvent; |
84 using blink::WebMouseWheelEvent; | 84 using blink::WebMouseWheelEvent; |
85 using blink::WebTextDirection; | 85 using blink::WebTextDirection; |
86 | 86 |
87 namespace content { | 87 namespace content { |
88 namespace { | 88 namespace { |
89 | 89 |
90 bool g_check_for_pending_resize_ack = true; | 90 bool g_check_for_pending_resize_ack = true; |
91 | 91 |
92 const size_t kBrowserCompositeLatencyHistorySize = 60; | |
93 const double kBrowserCompositeLatencyEstimationPercentile = 90.0; | |
94 const double kBrowserCompositeLatencyEstimationSlack = 1.1; | |
95 | |
92 typedef std::pair<int32, int32> RenderWidgetHostID; | 96 typedef std::pair<int32, int32> RenderWidgetHostID; |
93 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> | 97 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> |
94 RoutingIDWidgetMap; | 98 RoutingIDWidgetMap; |
95 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = | 99 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = |
96 LAZY_INSTANCE_INITIALIZER; | 100 LAZY_INSTANCE_INITIALIZER; |
97 | 101 |
98 int GetInputRouterViewFlagsFromCompositorFrameMetadata( | 102 int GetInputRouterViewFlagsFromCompositorFrameMetadata( |
99 const cc::CompositorFrameMetadata metadata) { | 103 const cc::CompositorFrameMetadata metadata) { |
100 int view_flags = InputRouter::VIEW_FLAGS_NONE; | 104 int view_flags = InputRouter::VIEW_FLAGS_NONE; |
101 | 105 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 input_method_active_(false), | 183 input_method_active_(false), |
180 text_direction_updated_(false), | 184 text_direction_updated_(false), |
181 text_direction_(blink::WebTextDirectionLeftToRight), | 185 text_direction_(blink::WebTextDirectionLeftToRight), |
182 text_direction_canceled_(false), | 186 text_direction_canceled_(false), |
183 suppress_next_char_events_(false), | 187 suppress_next_char_events_(false), |
184 pending_mouse_lock_request_(false), | 188 pending_mouse_lock_request_(false), |
185 allow_privileged_mouse_lock_(false), | 189 allow_privileged_mouse_lock_(false), |
186 has_touch_handler_(false), | 190 has_touch_handler_(false), |
187 weak_factory_(this), | 191 weak_factory_(this), |
188 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), | 192 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
189 next_browser_snapshot_id_(1) { | 193 next_browser_snapshot_id_(1), |
194 browser_composite_latency_history_(kBrowserCompositeLatencyHistorySize) { | |
190 CHECK(delegate_); | 195 CHECK(delegate_); |
191 if (routing_id_ == MSG_ROUTING_NONE) { | 196 if (routing_id_ == MSG_ROUTING_NONE) { |
192 routing_id_ = process_->GetNextRoutingID(); | 197 routing_id_ = process_->GetNextRoutingID(); |
193 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 198 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
194 process_->GetID(), | 199 process_->GetID(), |
195 routing_id_); | 200 routing_id_); |
196 } else { | 201 } else { |
197 // TODO(piman): This is a O(N) lookup, where we could forward the | 202 // TODO(piman): This is a O(N) lookup, where we could forward the |
198 // information from the RenderWidgetHelper. The problem is that doing so | 203 // information from the RenderWidgetHelper. The problem is that doing so |
199 // currently leaks outside of content all the way to chrome classes, and | 204 // currently leaks outside of content all the way to chrome classes, and |
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1444 param.b.AssignTo(frame.get()); | 1449 param.b.AssignTo(frame.get()); |
1445 std::vector<IPC::Message> messages_to_deliver_with_frame; | 1450 std::vector<IPC::Message> messages_to_deliver_with_frame; |
1446 messages_to_deliver_with_frame.swap(param.c); | 1451 messages_to_deliver_with_frame.swap(param.c); |
1447 | 1452 |
1448 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) | 1453 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) |
1449 AddLatencyInfoComponentIds(&frame->metadata.latency_info[i]); | 1454 AddLatencyInfoComponentIds(&frame->metadata.latency_info[i]); |
1450 | 1455 |
1451 input_router_->OnViewUpdated( | 1456 input_router_->OnViewUpdated( |
1452 GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata)); | 1457 GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata)); |
1453 | 1458 |
1459 for (size_t i = 0; i < frame->metadata.latency_info.size(); ++i) { | |
1460 frame->metadata.latency_info[i].AddLatencyNumber( | |
1461 ui::INPUT_EVENT_RENDERER_SWAP_RECEIVED_COMPONENT, | |
1462 GetLatencyComponentId(), | |
1463 0); | |
1464 } | |
1465 | |
1454 if (view_) { | 1466 if (view_) { |
1455 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); | 1467 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); |
1456 view_->DidReceiveRendererFrame(); | 1468 view_->DidReceiveRendererFrame(); |
1457 } else { | 1469 } else { |
1458 cc::CompositorFrameAck ack; | 1470 cc::CompositorFrameAck ack; |
1459 if (frame->gl_frame_data) { | 1471 if (frame->gl_frame_data) { |
1460 ack.gl_frame_data = frame->gl_frame_data.Pass(); | 1472 ack.gl_frame_data = frame->gl_frame_data.Pass(); |
1461 ack.gl_frame_data->sync_point = 0; | 1473 ack.gl_frame_data->sync_point = 0; |
1462 } else if (frame->delegated_frame_data) { | 1474 } else if (frame->delegated_frame_data) { |
1463 cc::TransferableResource::ReturnResources( | 1475 cc::TransferableResource::ReturnResources( |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2135 swap_component.event_time - original_component.event_time; | 2147 swap_component.event_time - original_component.event_time; |
2136 for (size_t i = 0; i < original_component.event_count; i++) { | 2148 for (size_t i = 0; i < original_component.event_count; i++) { |
2137 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2149 UMA_HISTOGRAM_CUSTOM_COUNTS( |
2138 "Event.Latency.TouchToScrollUpdateSwap", | 2150 "Event.Latency.TouchToScrollUpdateSwap", |
2139 delta.InMicroseconds(), | 2151 delta.InMicroseconds(), |
2140 1, | 2152 1, |
2141 1000000, | 2153 1000000, |
2142 100); | 2154 100); |
2143 } | 2155 } |
2144 } | 2156 } |
2157 | |
2158 ui::LatencyInfo::LatencyComponent gpu_swap_component; | |
2159 if (!latency_info.FindLatency( | |
2160 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, &gpu_swap_component)) { | |
2161 return; | |
2162 } | |
2163 | |
2164 ui::LatencyInfo::LatencyComponent composite_component; | |
2165 if (latency_info.FindLatency(ui::INPUT_EVENT_RENDERER_SWAP_RECEIVED_COMPONENT, | |
no sievers
2014/10/01 22:15:08
Hmm, so does that ignore the time it took the rend
orglofch
2014/10/02 00:46:04
Yea this is just for the browser composite time. W
no sievers
2014/10/02 20:17:42
Ah ok, it looks like the renderer adjusts the dead
| |
2166 GetLatencyComponentId(), | |
2167 &composite_component)) { | |
2168 base::TimeDelta delta = | |
2169 gpu_swap_component.event_time - composite_component.event_time; | |
2170 browser_composite_latency_history_.InsertSample(delta); | |
2171 } | |
2145 } | 2172 } |
2146 | 2173 |
2147 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2174 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
2148 view_->DidReceiveRendererFrame(); | 2175 view_->DidReceiveRendererFrame(); |
2149 } | 2176 } |
2150 | 2177 |
2151 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( | 2178 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( |
2152 int routing_id, | 2179 int routing_id, |
2153 int snapshot_id, | 2180 int snapshot_id, |
2154 gfx::Size snapshot_size, | 2181 gfx::Size snapshot_size, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2253 const std::vector<ui::LatencyInfo>& latency_info) { | 2280 const std::vector<ui::LatencyInfo>& latency_info) { |
2254 for (size_t i = 0; i < latency_info.size(); i++) { | 2281 for (size_t i = 0; i < latency_info.size(); i++) { |
2255 std::set<RenderWidgetHostImpl*> rwhi_set; | 2282 std::set<RenderWidgetHostImpl*> rwhi_set; |
2256 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2283 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2257 latency_info[i].latency_components.begin(); | 2284 latency_info[i].latency_components.begin(); |
2258 b != latency_info[i].latency_components.end(); | 2285 b != latency_info[i].latency_components.end(); |
2259 ++b) { | 2286 ++b) { |
2260 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2287 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
2261 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || | 2288 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
2262 b->first.first == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT || | 2289 b->first.first == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
2263 b->first.first == ui::TAB_SHOW_COMPONENT) { | 2290 b->first.first == ui::TAB_SHOW_COMPONENT || |
2291 b->first.first == ui::INPUT_EVENT_RENDERER_SWAP_RECEIVED_COMPONENT) { | |
2264 // Matches with GetLatencyComponentId | 2292 // Matches with GetLatencyComponentId |
2265 int routing_id = b->first.second & 0xffffffff; | 2293 int routing_id = b->first.second & 0xffffffff; |
2266 int process_id = (b->first.second >> 32) & 0xffffffff; | 2294 int process_id = (b->first.second >> 32) & 0xffffffff; |
2267 RenderWidgetHost* rwh = | 2295 RenderWidgetHost* rwh = |
2268 RenderWidgetHost::FromID(process_id, routing_id); | 2296 RenderWidgetHost::FromID(process_id, routing_id); |
2269 if (!rwh) { | 2297 if (!rwh) { |
2270 continue; | 2298 continue; |
2271 } | 2299 } |
2272 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 2300 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
2273 if (rwhi_set.insert(rwhi).second) | 2301 if (rwhi_set.insert(rwhi).second) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2308 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { | 2336 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { |
2309 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; | 2337 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; |
2310 } | 2338 } |
2311 | 2339 |
2312 BrowserAccessibilityManager* | 2340 BrowserAccessibilityManager* |
2313 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { | 2341 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { |
2314 return delegate_ ? | 2342 return delegate_ ? |
2315 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; | 2343 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
2316 } | 2344 } |
2317 | 2345 |
2346 base::TimeDelta RenderWidgetHostImpl::GetEstimatedBrowserCompositeTime() { | |
2347 if (browser_composite_latency_history_.SampleCount() > 0) { | |
2348 | |
2349 return browser_composite_latency_history_.Percentile( | |
2350 kBrowserCompositeLatencyEstimationPercentile) * | |
2351 kBrowserCompositeLatencyEstimationSlack; | |
no sievers
2014/10/01 22:15:08
Can we also use the stddev or variance when coming
orglofch
2014/10/02 00:46:04
We could, however, we run the risk of a one-off re
no sievers
2014/10/02 20:17:42
I was actually more worried that we end up using s
orglofch
2014/10/02 22:17:56
Per our offline discussion, I've used the original
| |
2352 } else { | |
2353 return base::TimeDelta::FromMicroseconds( | |
2354 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); | |
2355 } | |
2356 } | |
2357 | |
2318 #if defined(OS_WIN) | 2358 #if defined(OS_WIN) |
2319 gfx::NativeViewAccessible | 2359 gfx::NativeViewAccessible |
2320 RenderWidgetHostImpl::GetParentNativeViewAccessible() { | 2360 RenderWidgetHostImpl::GetParentNativeViewAccessible() { |
2321 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; | 2361 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; |
2322 } | 2362 } |
2323 #endif | 2363 #endif |
2324 | 2364 |
2325 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2365 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
2326 if (view_) | 2366 if (view_) |
2327 return view_->PreferredReadbackFormat(); | 2367 return view_->PreferredReadbackFormat(); |
2328 return kN32_SkColorType; | 2368 return kN32_SkColorType; |
2329 } | 2369 } |
2330 | 2370 |
2331 } // namespace content | 2371 } // namespace content |
OLD | NEW |