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/gpu/gpu_process_host_ui_shim.h" | 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 else | 59 else |
60 delete msg; | 60 delete msg; |
61 } | 61 } |
62 | 62 |
63 void StopGpuProcessOnIO(int host_id) { | 63 void StopGpuProcessOnIO(int host_id) { |
64 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 64 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
65 if (host) | 65 if (host) |
66 host->StopGpuProcess(); | 66 host->StopGpuProcess(); |
67 } | 67 } |
68 | 68 |
69 class ScopedSendOnIOThread { | |
70 public: | |
71 ScopedSendOnIOThread(int host_id, IPC::Message* msg) | |
72 : host_id_(host_id), | |
73 msg_(msg), | |
74 cancelled_(false) { | |
75 } | |
76 | |
77 ~ScopedSendOnIOThread() { | |
78 if (!cancelled_) { | |
79 BrowserThread::PostTask(BrowserThread::IO, | |
80 FROM_HERE, | |
81 base::Bind(&SendOnIOThreadTask, | |
82 host_id_, | |
83 msg_.release())); | |
84 } | |
85 } | |
86 | |
87 void Cancel() { cancelled_ = true; } | |
88 | |
89 private: | |
90 int host_id_; | |
91 scoped_ptr<IPC::Message> msg_; | |
92 bool cancelled_; | |
93 }; | |
94 | |
95 RenderWidgetHostViewBase* GetRenderWidgetHostViewFromSurfaceID( | |
96 int surface_id) { | |
97 int render_process_id = 0; | |
98 int render_widget_id = 0; | |
99 if (!GpuSurfaceTracker::Get()->GetRenderWidgetIDForSurface( | |
100 surface_id, &render_process_id, &render_widget_id)) | |
101 return NULL; | |
102 | |
103 RenderWidgetHost* host = | |
104 RenderWidgetHost::FromID(render_process_id, render_widget_id); | |
105 return host ? static_cast<RenderWidgetHostViewBase*>(host->GetView()) : NULL; | |
106 } | |
107 | |
108 } // namespace | 69 } // namespace |
109 | 70 |
110 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { | 71 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { |
111 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); | 72 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); |
112 if (ui_shim) | 73 if (ui_shim) |
113 ui_shim->OnMessageReceived(msg); | 74 ui_shim->OnMessageReceived(msg); |
114 } | 75 } |
115 | 76 |
116 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) | 77 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) |
117 : host_id_(host_id) { | 78 : host_id_(host_id) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 g_hosts_by_id.Pointer()->Remove(host_id_); | 185 g_hosts_by_id.Pointer()->Remove(host_id_); |
225 } | 186 } |
226 | 187 |
227 bool GpuProcessHostUIShim::OnControlMessageReceived( | 188 bool GpuProcessHostUIShim::OnControlMessageReceived( |
228 const IPC::Message& message) { | 189 const IPC::Message& message) { |
229 DCHECK(CalledOnValidThread()); | 190 DCHECK(CalledOnValidThread()); |
230 | 191 |
231 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | 192 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
232 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, | 193 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, |
233 OnLogMessage) | 194 OnLogMessage) |
234 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceInitialized, | |
235 OnAcceleratedSurfaceInitialized) | |
236 #if defined(OS_MACOSX) | 195 #if defined(OS_MACOSX) |
237 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 196 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
238 OnAcceleratedSurfaceBuffersSwapped) | 197 OnAcceleratedSurfaceBuffersSwapped) |
239 #endif | 198 #endif |
240 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, | 199 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, |
241 OnGraphicsInfoCollected) | 200 OnGraphicsInfoCollected) |
242 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, | 201 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, |
243 OnVideoMemoryUsageStatsReceived); | 202 OnVideoMemoryUsageStatsReceived); |
244 IPC_MESSAGE_HANDLER(GpuHostMsg_AddSubscription, OnAddSubscription); | 203 IPC_MESSAGE_HANDLER(GpuHostMsg_AddSubscription, OnAddSubscription); |
245 IPC_MESSAGE_HANDLER(GpuHostMsg_RemoveSubscription, OnRemoveSubscription); | 204 IPC_MESSAGE_HANDLER(GpuHostMsg_RemoveSubscription, OnRemoveSubscription); |
(...skipping 14 matching lines...) Expand all Loading... |
260 | 219 |
261 void GpuProcessHostUIShim::OnGraphicsInfoCollected( | 220 void GpuProcessHostUIShim::OnGraphicsInfoCollected( |
262 const gpu::GPUInfo& gpu_info) { | 221 const gpu::GPUInfo& gpu_info) { |
263 // OnGraphicsInfoCollected is sent back after the GPU process successfully | 222 // OnGraphicsInfoCollected is sent back after the GPU process successfully |
264 // initializes GL. | 223 // initializes GL. |
265 TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); | 224 TRACE_EVENT0("test_gpu", "OnGraphicsInfoCollected"); |
266 | 225 |
267 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); | 226 GpuDataManagerImpl::GetInstance()->UpdateGpuInfo(gpu_info); |
268 } | 227 } |
269 | 228 |
270 void GpuProcessHostUIShim::OnAcceleratedSurfaceInitialized(int32 surface_id, | |
271 int32 route_id) { | |
272 RenderWidgetHostViewBase* view = | |
273 GetRenderWidgetHostViewFromSurfaceID(surface_id); | |
274 if (!view) | |
275 return; | |
276 view->AcceleratedSurfaceInitialized(route_id); | |
277 } | |
278 | |
279 #if defined(OS_MACOSX) | 229 #if defined(OS_MACOSX) |
280 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( | 230 void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( |
281 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 231 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
282 TRACE_EVENT0("renderer", | 232 TRACE_EVENT0("renderer", |
283 "GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped"); | 233 "GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped"); |
284 if (!ui::LatencyInfo::Verify(params.latency_info, | 234 if (!ui::LatencyInfo::Verify(params.latency_info, |
285 "GpuHostMsg_AcceleratedSurfaceBuffersSwapped")) { | 235 "GpuHostMsg_AcceleratedSurfaceBuffersSwapped")) { |
286 return; | 236 return; |
287 } | 237 } |
288 | 238 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 280 |
331 void GpuProcessHostUIShim::OnRemoveSubscription( | 281 void GpuProcessHostUIShim::OnRemoveSubscription( |
332 int32 process_id, unsigned int target) { | 282 int32 process_id, unsigned int target) { |
333 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); | 283 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); |
334 if (rph) { | 284 if (rph) { |
335 rph->OnRemoveSubscription(target); | 285 rph->OnRemoveSubscription(target); |
336 } | 286 } |
337 } | 287 } |
338 | 288 |
339 } // namespace content | 289 } // namespace content |
OLD | NEW |