| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 LAZY_INSTANCE_INITIALIZER; | 53 LAZY_INSTANCE_INITIALIZER; |
| 54 | 54 |
| 55 void SendOnIOThreadTask(int host_id, IPC::Message* msg) { | 55 void SendOnIOThreadTask(int host_id, IPC::Message* msg) { |
| 56 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 56 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
| 57 if (host) | 57 if (host) |
| 58 host->Send(msg); | 58 host->Send(msg); |
| 59 else | 59 else |
| 60 delete msg; | 60 delete msg; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void StopGpuProcessOnIO(int host_id) { |
| 64 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
| 65 if (host) |
| 66 host->StopGpuProcess(); |
| 67 } |
| 68 |
| 63 class ScopedSendOnIOThread { | 69 class ScopedSendOnIOThread { |
| 64 public: | 70 public: |
| 65 ScopedSendOnIOThread(int host_id, IPC::Message* msg) | 71 ScopedSendOnIOThread(int host_id, IPC::Message* msg) |
| 66 : host_id_(host_id), | 72 : host_id_(host_id), |
| 67 msg_(msg), | 73 msg_(msg), |
| 68 cancelled_(false) { | 74 cancelled_(false) { |
| 69 } | 75 } |
| 70 | 76 |
| 71 ~ScopedSendOnIOThread() { | 77 ~ScopedSendOnIOThread() { |
| 72 if (!cancelled_) { | 78 if (!cancelled_) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 ->OnMessageReceived(message)) | 191 ->OnMessageReceived(message)) |
| 186 return true; | 192 return true; |
| 187 #endif | 193 #endif |
| 188 | 194 |
| 189 if (message.routing_id() != MSG_ROUTING_CONTROL) | 195 if (message.routing_id() != MSG_ROUTING_CONTROL) |
| 190 return false; | 196 return false; |
| 191 | 197 |
| 192 return OnControlMessageReceived(message); | 198 return OnControlMessageReceived(message); |
| 193 } | 199 } |
| 194 | 200 |
| 195 void GpuProcessHostUIShim::RelinquishGpuResources( | 201 void GpuProcessHostUIShim::StopGpuProcess(base::Closure callback) { |
| 196 const base::Closure& callback) { | 202 // TODO(derekjchow): Make this API pretty |
| 197 DCHECK(relinquish_callback_.is_null()); | 203 close_callback_ = callback; |
| 198 relinquish_callback_ = callback; | 204 |
| 199 Send(new GpuMsg_RelinquishResources()); | 205 BrowserThread::PostTask(BrowserThread::IO, |
| 206 FROM_HERE, |
| 207 base::Bind(&StopGpuProcessOnIO, |
| 208 host_id_)); |
| 200 } | 209 } |
| 201 | 210 |
| 202 void GpuProcessHostUIShim::SimulateRemoveAllContext() { | 211 void GpuProcessHostUIShim::SimulateRemoveAllContext() { |
| 203 Send(new GpuMsg_Clean()); | 212 Send(new GpuMsg_Clean()); |
| 204 } | 213 } |
| 205 | 214 |
| 206 void GpuProcessHostUIShim::SimulateCrash() { | 215 void GpuProcessHostUIShim::SimulateCrash() { |
| 207 Send(new GpuMsg_Crash()); | 216 Send(new GpuMsg_Crash()); |
| 208 } | 217 } |
| 209 | 218 |
| 210 void GpuProcessHostUIShim::SimulateHang() { | 219 void GpuProcessHostUIShim::SimulateHang() { |
| 211 Send(new GpuMsg_Hang()); | 220 Send(new GpuMsg_Hang()); |
| 212 } | 221 } |
| 213 | 222 |
| 214 GpuProcessHostUIShim::~GpuProcessHostUIShim() { | 223 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
| 215 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
| 225 if (!close_callback_.is_null()) |
| 226 base::ResetAndReturn(&close_callback_).Run(); |
| 216 g_hosts_by_id.Pointer()->Remove(host_id_); | 227 g_hosts_by_id.Pointer()->Remove(host_id_); |
| 217 } | 228 } |
| 218 | 229 |
| 219 bool GpuProcessHostUIShim::OnControlMessageReceived( | 230 bool GpuProcessHostUIShim::OnControlMessageReceived( |
| 220 const IPC::Message& message) { | 231 const IPC::Message& message) { |
| 221 DCHECK(CalledOnValidThread()); | 232 DCHECK(CalledOnValidThread()); |
| 222 | 233 |
| 223 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | 234 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
| 224 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, | 235 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, |
| 225 OnLogMessage) | 236 OnLogMessage) |
| 226 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceInitialized, | 237 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceInitialized, |
| 227 OnAcceleratedSurfaceInitialized) | 238 OnAcceleratedSurfaceInitialized) |
| 228 #if defined(OS_MACOSX) | 239 #if defined(OS_MACOSX) |
| 229 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 240 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 230 OnAcceleratedSurfaceBuffersSwapped) | 241 OnAcceleratedSurfaceBuffersSwapped) |
| 231 #endif | 242 #endif |
| 232 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, | 243 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, |
| 233 OnGraphicsInfoCollected) | 244 OnGraphicsInfoCollected) |
| 234 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, | 245 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, |
| 235 OnVideoMemoryUsageStatsReceived); | 246 OnVideoMemoryUsageStatsReceived); |
| 236 IPC_MESSAGE_HANDLER(GpuHostMsg_ResourcesRelinquished, | |
| 237 OnResourcesRelinquished) | |
| 238 IPC_MESSAGE_HANDLER(GpuHostMsg_AddSubscription, OnAddSubscription); | 247 IPC_MESSAGE_HANDLER(GpuHostMsg_AddSubscription, OnAddSubscription); |
| 239 IPC_MESSAGE_HANDLER(GpuHostMsg_RemoveSubscription, OnRemoveSubscription); | 248 IPC_MESSAGE_HANDLER(GpuHostMsg_RemoveSubscription, OnRemoveSubscription); |
| 240 | 249 |
| 241 IPC_MESSAGE_UNHANDLED_ERROR() | 250 IPC_MESSAGE_UNHANDLED_ERROR() |
| 242 IPC_END_MESSAGE_MAP() | 251 IPC_END_MESSAGE_MAP() |
| 243 | 252 |
| 244 return true; | 253 return true; |
| 245 } | 254 } |
| 246 | 255 |
| 247 void GpuProcessHostUIShim::OnLogMessage( | 256 void GpuProcessHostUIShim::OnLogMessage( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, ack_params)); | 316 Send(new AcceleratedSurfaceMsg_BufferPresented(params.route_id, ack_params)); |
| 308 } | 317 } |
| 309 #endif | 318 #endif |
| 310 | 319 |
| 311 void GpuProcessHostUIShim::OnVideoMemoryUsageStatsReceived( | 320 void GpuProcessHostUIShim::OnVideoMemoryUsageStatsReceived( |
| 312 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { | 321 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { |
| 313 GpuDataManagerImpl::GetInstance()->UpdateVideoMemoryUsageStats( | 322 GpuDataManagerImpl::GetInstance()->UpdateVideoMemoryUsageStats( |
| 314 video_memory_usage_stats); | 323 video_memory_usage_stats); |
| 315 } | 324 } |
| 316 | 325 |
| 317 void GpuProcessHostUIShim::OnResourcesRelinquished() { | |
| 318 if (!relinquish_callback_.is_null()) { | |
| 319 base::ResetAndReturn(&relinquish_callback_).Run(); | |
| 320 } | |
| 321 } | |
| 322 | |
| 323 void GpuProcessHostUIShim::OnAddSubscription( | 326 void GpuProcessHostUIShim::OnAddSubscription( |
| 324 int32 process_id, unsigned int target) { | 327 int32 process_id, unsigned int target) { |
| 325 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); | 328 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); |
| 326 if (rph) { | 329 if (rph) { |
| 327 rph->OnAddSubscription(target); | 330 rph->OnAddSubscription(target); |
| 328 } | 331 } |
| 329 } | 332 } |
| 330 | 333 |
| 331 void GpuProcessHostUIShim::OnRemoveSubscription( | 334 void GpuProcessHostUIShim::OnRemoveSubscription( |
| 332 int32 process_id, unsigned int target) { | 335 int32 process_id, unsigned int target) { |
| 333 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); | 336 RenderProcessHost* rph = RenderProcessHost::FromID(process_id); |
| 334 if (rph) { | 337 if (rph) { |
| 335 rph->OnRemoveSubscription(target); | 338 rph->OnRemoveSubscription(target); |
| 336 } | 339 } |
| 337 } | 340 } |
| 338 | 341 |
| 339 } // namespace content | 342 } // namespace content |
| OLD | NEW |