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 <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "cc/base/hash_pair.h" | |
jam
2013/06/12 19:59:59
it seems wrong that content uses cc's base (or tha
nasko
2013/06/12 21:18:59
Agreed. ajwong and danakj have taken on moving thi
jam
2013/06/12 22:59:27
Yes, please let's wait on that.
nasko
2013/06/20 23:25:26
I've moved the hash_pair into base/containers/hash
| |
21 #include "cc/output/compositor_frame.h" | 22 #include "cc/output/compositor_frame.h" |
22 #include "cc/output/compositor_frame_ack.h" | 23 #include "cc/output/compositor_frame_ack.h" |
23 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
24 #include "content/browser/gpu/gpu_process_host.h" | 25 #include "content/browser/gpu/gpu_process_host.h" |
25 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 26 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
26 #include "content/browser/gpu/gpu_surface_tracker.h" | 27 #include "content/browser/gpu/gpu_surface_tracker.h" |
27 #include "content/browser/renderer_host/backing_store.h" | 28 #include "content/browser/renderer_host/backing_store.h" |
28 #include "content/browser/renderer_host/backing_store_manager.h" | 29 #include "content/browser/renderer_host/backing_store_manager.h" |
29 #include "content/browser/renderer_host/dip_util.h" | 30 #include "content/browser/renderer_host/dip_util.h" |
30 #include "content/browser/renderer_host/gesture_event_filter.h" | 31 #include "content/browser/renderer_host/gesture_event_filter.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 return 1.f; | 114 return 1.f; |
114 return unaccelerated_delta / accelerated_delta; | 115 return unaccelerated_delta / accelerated_delta; |
115 } | 116 } |
116 | 117 |
117 base::LazyInstance<std::vector<RenderWidgetHost::CreatedCallback> > | 118 base::LazyInstance<std::vector<RenderWidgetHost::CreatedCallback> > |
118 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; | 119 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
119 | 120 |
120 } // namespace | 121 } // namespace |
121 | 122 |
122 | 123 |
124 typedef std::pair<int32, int32> RenderWidgetHostID; | |
125 typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*> | |
126 RoutingIDWidgetMap; | |
127 static base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map = | |
128 LAZY_INSTANCE_INITIALIZER; | |
129 | |
123 // static | 130 // static |
124 void RenderWidgetHost::RemoveAllBackingStores() { | 131 void RenderWidgetHost::RemoveAllBackingStores() { |
125 BackingStoreManager::RemoveAllBackingStores(); | 132 BackingStoreManager::RemoveAllBackingStores(); |
126 } | 133 } |
127 | 134 |
128 // static | 135 // static |
129 size_t RenderWidgetHost::BackingStoreMemorySize() { | 136 size_t RenderWidgetHost::BackingStoreMemorySize() { |
130 return BackingStoreManager::MemorySize(); | 137 return BackingStoreManager::MemorySize(); |
131 } | 138 } |
132 | 139 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 // problem, for example by tracking in the RenderWidgetHelper the routing id | 198 // problem, for example by tracking in the RenderWidgetHelper the routing id |
192 // (and surface id) that have been created, but whose RWH haven't yet. | 199 // (and surface id) that have been created, but whose RWH haven't yet. |
193 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( | 200 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( |
194 process_->GetID(), | 201 process_->GetID(), |
195 routing_id_); | 202 routing_id_); |
196 DCHECK(surface_id_); | 203 DCHECK(surface_id_); |
197 } | 204 } |
198 | 205 |
199 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); | 206 is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); |
200 | 207 |
201 process_->Attach(this, routing_id_); | 208 g_routing_id_widget_map.Get().insert(std::make_pair( |
209 RenderWidgetHostID(process->GetID(), routing_id_), this)); | |
210 process_->AddRoute(routing_id_, this); | |
202 // Because the widget initializes as is_hidden_ == false, | 211 // Because the widget initializes as is_hidden_ == false, |
203 // tell the process host that we're alive. | 212 // tell the process host that we're alive. |
204 process_->WidgetRestored(); | 213 process_->WidgetRestored(); |
205 | 214 |
206 accessibility_mode_ = | 215 accessibility_mode_ = |
207 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); | 216 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
208 | 217 |
209 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 218 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
210 g_created_callbacks.Get().at(i).Run(this); | 219 g_created_callbacks.Get().at(i).Run(this); |
211 | 220 |
212 #if defined(USE_AURA) | 221 #if defined(USE_AURA) |
213 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> | 222 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
214 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) == "1"; | 223 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) == "1"; |
215 SetOverscrollControllerEnabled(overscroll_enabled); | 224 SetOverscrollControllerEnabled(overscroll_enabled); |
216 #endif | 225 #endif |
217 } | 226 } |
218 | 227 |
219 RenderWidgetHostImpl::~RenderWidgetHostImpl() { | 228 RenderWidgetHostImpl::~RenderWidgetHostImpl() { |
220 SetView(NULL); | 229 SetView(NULL); |
221 | 230 |
222 // Clear our current or cached backing store if either remains. | 231 // Clear our current or cached backing store if either remains. |
223 BackingStoreManager::RemoveBackingStore(this); | 232 BackingStoreManager::RemoveBackingStore(this); |
224 | 233 |
225 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); | 234 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); |
226 surface_id_ = 0; | 235 surface_id_ = 0; |
227 | 236 |
228 process_->Release(routing_id_); | 237 process_->RemoveRoute(routing_id_); |
238 g_routing_id_widget_map.Get().erase( | |
239 RenderWidgetHostID(process_->GetID(), routing_id_)); | |
229 | 240 |
230 if (delegate_) | 241 if (delegate_) |
231 delegate_->RenderWidgetDeleted(this); | 242 delegate_->RenderWidgetDeleted(this); |
232 } | 243 } |
233 | 244 |
234 // static | 245 // static |
246 RenderWidgetHost* RenderWidgetHost::FromID( | |
247 int32 process_id, | |
248 int32 routing_id) { | |
249 return RenderWidgetHostImpl::FromID(process_id, routing_id); | |
250 } | |
251 | |
252 // static | |
253 RenderWidgetHostImpl* RenderWidgetHostImpl::FromID( | |
254 int32 process_id, | |
255 int32 routing_id) { | |
256 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | |
257 RoutingIDWidgetMap::iterator it = widgets->find( | |
258 RenderWidgetHostID(process_id, routing_id)); | |
259 return it == widgets->end() ? NULL : it->second; | |
260 } | |
261 | |
262 // static | |
263 std::vector<RenderWidgetHost*> RenderWidgetHost::GetRenderWidgetHosts() { | |
264 std::vector<RenderWidgetHost*> hosts; | |
265 RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer(); | |
266 for (RoutingIDWidgetMap::const_iterator it = widgets->begin(); | |
267 it != widgets->end(); | |
268 ++it) { | |
269 hosts.push_back(it->second); | |
270 } | |
271 return hosts; | |
272 } | |
273 | |
274 // static | |
235 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { | 275 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { |
236 return rwh->AsRenderWidgetHostImpl(); | 276 return rwh->AsRenderWidgetHostImpl(); |
237 } | 277 } |
238 | 278 |
239 // static | 279 // static |
240 void RenderWidgetHost::AddCreatedCallback(const CreatedCallback& callback) { | 280 void RenderWidgetHost::AddCreatedCallback(const CreatedCallback& callback) { |
241 g_created_callbacks.Get().push_back(callback); | 281 g_created_callbacks.Get().push_back(callback); |
242 } | 282 } |
243 | 283 |
244 // static | 284 // static |
(...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2536 const ui::LatencyInfo& latency_info) { | 2576 const ui::LatencyInfo& latency_info) { |
2537 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2577 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2538 latency_info.latency_components.begin(); | 2578 latency_info.latency_components.begin(); |
2539 b != latency_info.latency_components.end(); | 2579 b != latency_info.latency_components.end(); |
2540 ++b) { | 2580 ++b) { |
2541 if (b->first.first != ui::INPUT_EVENT_LATENCY_COMPONENT) | 2581 if (b->first.first != ui::INPUT_EVENT_LATENCY_COMPONENT) |
2542 continue; | 2582 continue; |
2543 // Matches with GetLatencyComponentId | 2583 // Matches with GetLatencyComponentId |
2544 int routing_id = b->first.second & 0xffffffff; | 2584 int routing_id = b->first.second & 0xffffffff; |
2545 int process_id = (b->first.second >> 32) & 0xffffffff; | 2585 int process_id = (b->first.second >> 32) & 0xffffffff; |
2546 RenderProcessHost* host = RenderProcessHost::FromID(process_id); | 2586 RenderWidgetHost* rwh = |
2547 if (!host) | 2587 RenderWidgetHost::FromID(process_id, routing_id); |
2548 continue; | |
2549 RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(routing_id); | |
2550 if (!rwh) | 2588 if (!rwh) |
2551 continue; | 2589 continue; |
2552 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2590 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
2553 } | 2591 } |
2554 } | 2592 } |
2555 | 2593 |
2556 } // namespace content | 2594 } // namespace content |
OLD | NEW |