| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 using blink::WebKeyboardEvent; | 84 using blink::WebKeyboardEvent; |
| 85 using blink::WebMouseEvent; | 85 using blink::WebMouseEvent; |
| 86 using blink::WebMouseWheelEvent; | 86 using blink::WebMouseWheelEvent; |
| 87 using blink::WebTextDirection; | 87 using blink::WebTextDirection; |
| 88 | 88 |
| 89 namespace content { | 89 namespace content { |
| 90 namespace { | 90 namespace { |
| 91 | 91 |
| 92 bool g_check_for_pending_resize_ack = true; | 92 bool g_check_for_pending_resize_ack = true; |
| 93 | 93 |
| 94 const size_t kBrowserCompositeLatencyHistorySize = 60; |
| 95 const double kBrowserCompositeLatencyEstimationPercentile = 90.0; |
| 96 const double kBrowserCompositeLatencyEstimationSlack = 1.1; |
| 97 |
| 94 typedef std::pair<int32, int32> RenderWidgetHostID; | 98 typedef std::pair<int32, int32> RenderWidgetHostID; |
| 95 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> | 99 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> |
| 96 RoutingIDWidgetMap; | 100 RoutingIDWidgetMap; |
| 97 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = | 101 base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = |
| 98 LAZY_INSTANCE_INITIALIZER; | 102 LAZY_INSTANCE_INITIALIZER; |
| 99 | 103 |
| 100 int GetInputRouterViewFlagsFromCompositorFrameMetadata( | 104 int GetInputRouterViewFlagsFromCompositorFrameMetadata( |
| 101 const cc::CompositorFrameMetadata metadata) { | 105 const cc::CompositorFrameMetadata metadata) { |
| 102 int view_flags = InputRouter::VIEW_FLAGS_NONE; | 106 int view_flags = InputRouter::VIEW_FLAGS_NONE; |
| 103 | 107 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ignore_input_events_(false), | 181 ignore_input_events_(false), |
| 178 input_method_active_(false), | 182 input_method_active_(false), |
| 179 text_direction_updated_(false), | 183 text_direction_updated_(false), |
| 180 text_direction_(blink::WebTextDirectionLeftToRight), | 184 text_direction_(blink::WebTextDirectionLeftToRight), |
| 181 text_direction_canceled_(false), | 185 text_direction_canceled_(false), |
| 182 suppress_next_char_events_(false), | 186 suppress_next_char_events_(false), |
| 183 pending_mouse_lock_request_(false), | 187 pending_mouse_lock_request_(false), |
| 184 allow_privileged_mouse_lock_(false), | 188 allow_privileged_mouse_lock_(false), |
| 185 has_touch_handler_(false), | 189 has_touch_handler_(false), |
| 186 next_browser_snapshot_id_(1), | 190 next_browser_snapshot_id_(1), |
| 191 browser_composite_latency_history_(kBrowserCompositeLatencyHistorySize), |
| 187 weak_factory_(this) { | 192 weak_factory_(this) { |
| 188 CHECK(delegate_); | 193 CHECK(delegate_); |
| 189 if (routing_id_ == MSG_ROUTING_NONE) { | 194 if (routing_id_ == MSG_ROUTING_NONE) { |
| 190 routing_id_ = process_->GetNextRoutingID(); | 195 routing_id_ = process_->GetNextRoutingID(); |
| 191 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 196 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 192 process_->GetID(), | 197 process_->GetID(), |
| 193 routing_id_); | 198 routing_id_); |
| 194 } else { | 199 } else { |
| 195 // TODO(piman): This is a O(N) lookup, where we could forward the | 200 // TODO(piman): This is a O(N) lookup, where we could forward the |
| 196 // information from the RenderWidgetHelper. The problem is that doing so | 201 // information from the RenderWidgetHelper. The problem is that doing so |
| (...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 uint32 output_surface_id = get<0>(param); | 1436 uint32 output_surface_id = get<0>(param); |
| 1432 get<1>(param).AssignTo(frame.get()); | 1437 get<1>(param).AssignTo(frame.get()); |
| 1433 std::vector<IPC::Message> messages_to_deliver_with_frame; | 1438 std::vector<IPC::Message> messages_to_deliver_with_frame; |
| 1434 messages_to_deliver_with_frame.swap(get<2>(param)); | 1439 messages_to_deliver_with_frame.swap(get<2>(param)); |
| 1435 | 1440 |
| 1436 latency_tracker_.OnSwapCompositorFrame(&frame->metadata.latency_info); | 1441 latency_tracker_.OnSwapCompositorFrame(&frame->metadata.latency_info); |
| 1437 | 1442 |
| 1438 input_router_->OnViewUpdated( | 1443 input_router_->OnViewUpdated( |
| 1439 GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata)); | 1444 GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata)); |
| 1440 | 1445 |
| 1446 for (auto& latency : frame->metadata.latency_info) |
| 1447 latency.AddLatencyNumber(ui::INPUT_EVENT_BROWSER_COMPOSITE_COMPONENT, 0, 0); |
| 1448 |
| 1441 if (view_) { | 1449 if (view_) { |
| 1442 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); | 1450 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); |
| 1443 view_->DidReceiveRendererFrame(); | 1451 view_->DidReceiveRendererFrame(); |
| 1444 } else { | 1452 } else { |
| 1445 cc::CompositorFrameAck ack; | 1453 cc::CompositorFrameAck ack; |
| 1446 if (frame->gl_frame_data) { | 1454 if (frame->gl_frame_data) { |
| 1447 ack.gl_frame_data = frame->gl_frame_data.Pass(); | 1455 ack.gl_frame_data = frame->gl_frame_data.Pass(); |
| 1448 ack.gl_frame_data->sync_point = 0; | 1456 ack.gl_frame_data->sync_point = 0; |
| 1449 } else if (frame->delegated_frame_data) { | 1457 } else if (frame->delegated_frame_data) { |
| 1450 cc::TransferableResource::ReturnResources( | 1458 cc::TransferableResource::ReturnResources( |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, | 2012 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, |
| 2005 weak_factory_.GetWeakPtr(), | 2013 weak_factory_.GetWeakPtr(), |
| 2006 sequence_number), | 2014 sequence_number), |
| 2007 base::TimeDelta::FromSecondsD(1. / 6)); | 2015 base::TimeDelta::FromSecondsD(1. / 6)); |
| 2008 #else | 2016 #else |
| 2009 WindowSnapshotReachedScreen(sequence_number); | 2017 WindowSnapshotReachedScreen(sequence_number); |
| 2010 #endif | 2018 #endif |
| 2011 } | 2019 } |
| 2012 | 2020 |
| 2013 latency_tracker_.OnFrameSwapped(latency_info); | 2021 latency_tracker_.OnFrameSwapped(latency_info); |
| 2022 |
| 2023 ui::LatencyInfo::LatencyComponent gpu_swap_component; |
| 2024 if (!latency_info.FindLatency( |
| 2025 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, &gpu_swap_component)) { |
| 2026 return; |
| 2027 } |
| 2028 |
| 2029 ui::LatencyInfo::LatencyComponent composite_component; |
| 2030 if (latency_info.FindLatency(ui::INPUT_EVENT_BROWSER_COMPOSITE_COMPONENT, |
| 2031 0, |
| 2032 &composite_component)) { |
| 2033 base::TimeDelta delta = |
| 2034 gpu_swap_component.event_time - composite_component.event_time; |
| 2035 browser_composite_latency_history_.InsertSample(delta); |
| 2036 } |
| 2014 } | 2037 } |
| 2015 | 2038 |
| 2016 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2039 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2017 view_->DidReceiveRendererFrame(); | 2040 view_->DidReceiveRendererFrame(); |
| 2018 } | 2041 } |
| 2019 | 2042 |
| 2020 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( | 2043 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( |
| 2021 int routing_id, | 2044 int routing_id, |
| 2022 int snapshot_id, | 2045 int snapshot_id, |
| 2023 gfx::Size snapshot_size, | 2046 gfx::Size snapshot_size, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2150 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { | 2173 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { |
| 2151 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; | 2174 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; |
| 2152 } | 2175 } |
| 2153 | 2176 |
| 2154 BrowserAccessibilityManager* | 2177 BrowserAccessibilityManager* |
| 2155 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { | 2178 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { |
| 2156 return delegate_ ? | 2179 return delegate_ ? |
| 2157 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; | 2180 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
| 2158 } | 2181 } |
| 2159 | 2182 |
| 2183 base::TimeDelta RenderWidgetHostImpl::GetEstimatedBrowserCompositeTime() { |
| 2184 // TODO(brianderson): Remove lower bound on estimate once we're sure it won't |
| 2185 // cause regressions. |
| 2186 return std::max( |
| 2187 browser_composite_latency_history_.Percentile( |
| 2188 kBrowserCompositeLatencyEstimationPercentile) * |
| 2189 kBrowserCompositeLatencyEstimationSlack, |
| 2190 base::TimeDelta::FromMicroseconds( |
| 2191 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60))); |
| 2192 } |
| 2193 |
| 2160 #if defined(OS_WIN) | 2194 #if defined(OS_WIN) |
| 2161 gfx::NativeViewAccessible | 2195 gfx::NativeViewAccessible |
| 2162 RenderWidgetHostImpl::GetParentNativeViewAccessible() { | 2196 RenderWidgetHostImpl::GetParentNativeViewAccessible() { |
| 2163 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; | 2197 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; |
| 2164 } | 2198 } |
| 2165 #endif | 2199 #endif |
| 2166 | 2200 |
| 2167 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2201 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
| 2168 if (view_) | 2202 if (view_) |
| 2169 return view_->PreferredReadbackFormat(); | 2203 return view_->PreferredReadbackFormat(); |
| 2170 return kN32_SkColorType; | 2204 return kN32_SkColorType; |
| 2171 } | 2205 } |
| 2172 | 2206 |
| 2173 } // namespace content | 2207 } // namespace content |
| OLD | NEW |