| 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.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 DIED_SECOND_TIME, | 151 DIED_SECOND_TIME, |
| 152 DIED_THIRD_TIME, | 152 DIED_THIRD_TIME, |
| 153 DIED_FOURTH_TIME, | 153 DIED_FOURTH_TIME, |
| 154 GPU_PROCESS_LIFETIME_EVENT_MAX = 100 | 154 GPU_PROCESS_LIFETIME_EVENT_MAX = 100 |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 // Indexed by GpuProcessKind. There is one of each kind maximum. This array may | 157 // Indexed by GpuProcessKind. There is one of each kind maximum. This array may |
| 158 // only be accessed from the IO thread. | 158 // only be accessed from the IO thread. |
| 159 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; | 159 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; |
| 160 | 160 |
| 161 | |
| 162 void SendGpuProcessMessage(GpuProcessHost::GpuProcessKind kind, | 161 void SendGpuProcessMessage(GpuProcessHost::GpuProcessKind kind, |
| 163 CauseForGpuLaunch cause, | 162 gpu::CauseForGpuLaunch cause, |
| 164 IPC::Message* message) { | 163 IPC::Message* message) { |
| 165 GpuProcessHost* host = GpuProcessHost::Get(kind, cause); | 164 GpuProcessHost* host = GpuProcessHost::Get(kind, cause); |
| 166 if (host) { | 165 if (host) { |
| 167 host->Send(message); | 166 host->Send(message); |
| 168 } else { | 167 } else { |
| 169 delete message; | 168 delete message; |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 | 171 |
| 173 // NOTE: changes to this class need to be reviewed by the security team. | 172 // NOTE: changes to this class need to be reviewed by the security team. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 !GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()))) { | 302 !GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()))) { |
| 304 return true; | 303 return true; |
| 305 } | 304 } |
| 306 | 305 |
| 307 host->ForceShutdown(); | 306 host->ForceShutdown(); |
| 308 return false; | 307 return false; |
| 309 } | 308 } |
| 310 | 309 |
| 311 // static | 310 // static |
| 312 GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind, | 311 GpuProcessHost* GpuProcessHost::Get(GpuProcessKind kind, |
| 313 CauseForGpuLaunch cause) { | 312 gpu::CauseForGpuLaunch cause) { |
| 314 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 313 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 315 | 314 |
| 316 // Don't grant further access to GPU if it is not allowed. | 315 // Don't grant further access to GPU if it is not allowed. |
| 317 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); | 316 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); |
| 318 DCHECK(gpu_data_manager); | 317 DCHECK(gpu_data_manager); |
| 319 if (!gpu_data_manager->GpuAccessAllowed(NULL)) | 318 if (!gpu_data_manager->GpuAccessAllowed(NULL)) |
| 320 return NULL; | 319 return NULL; |
| 321 | 320 |
| 322 if (g_gpu_process_hosts[kind] && ValidateHost(g_gpu_process_hosts[kind])) | 321 if (g_gpu_process_hosts[kind] && ValidateHost(g_gpu_process_hosts[kind])) |
| 323 return g_gpu_process_hosts[kind]; | 322 return g_gpu_process_hosts[kind]; |
| 324 | 323 |
| 325 if (cause == CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH) | 324 if (cause == gpu::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH) |
| 326 return NULL; | 325 return NULL; |
| 327 | 326 |
| 328 static int last_host_id = 0; | 327 static int last_host_id = 0; |
| 329 int host_id; | 328 int host_id; |
| 330 host_id = ++last_host_id; | 329 host_id = ++last_host_id; |
| 331 | 330 |
| 332 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLaunchCause", | 331 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLaunchCause", cause, |
| 333 cause, | 332 gpu::CAUSE_FOR_GPU_LAUNCH_MAX_ENUM); |
| 334 CAUSE_FOR_GPU_LAUNCH_MAX_ENUM); | |
| 335 | 333 |
| 336 GpuProcessHost* host = new GpuProcessHost(host_id, kind); | 334 GpuProcessHost* host = new GpuProcessHost(host_id, kind); |
| 337 if (host->Init()) | 335 if (host->Init()) |
| 338 return host; | 336 return host; |
| 339 | 337 |
| 340 // TODO(sievers): Revisit this behavior. It's not really a crash, but we also | 338 // TODO(sievers): Revisit this behavior. It's not really a crash, but we also |
| 341 // want the fallback-to-sw behavior if we cannot initialize the GPU. | 339 // want the fallback-to-sw behavior if we cannot initialize the GPU. |
| 342 host->RecordProcessCrash(); | 340 host->RecordProcessCrash(); |
| 343 | 341 |
| 344 delete host; | 342 delete host; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 363 handles.push_back(host->process_->GetProcess().Handle()); | 361 handles.push_back(host->process_->GetProcess().Handle()); |
| 364 } | 362 } |
| 365 BrowserThread::PostTask( | 363 BrowserThread::PostTask( |
| 366 BrowserThread::UI, | 364 BrowserThread::UI, |
| 367 FROM_HERE, | 365 FROM_HERE, |
| 368 base::Bind(callback, handles)); | 366 base::Bind(callback, handles)); |
| 369 } | 367 } |
| 370 | 368 |
| 371 // static | 369 // static |
| 372 void GpuProcessHost::SendOnIO(GpuProcessKind kind, | 370 void GpuProcessHost::SendOnIO(GpuProcessKind kind, |
| 373 CauseForGpuLaunch cause, | 371 gpu::CauseForGpuLaunch cause, |
| 374 IPC::Message* message) { | 372 IPC::Message* message) { |
| 375 if (!BrowserThread::PostTask( | 373 if (!BrowserThread::PostTask( |
| 376 BrowserThread::IO, FROM_HERE, | 374 BrowserThread::IO, FROM_HERE, |
| 377 base::Bind( | 375 base::Bind( |
| 378 &SendGpuProcessMessage, kind, cause, message))) { | 376 &SendGpuProcessMessage, kind, cause, message))) { |
| 379 delete message; | 377 delete message; |
| 380 } | 378 } |
| 381 } | 379 } |
| 382 | 380 |
| 383 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; | 381 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1162 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1165 ClientIdToShaderCacheMap::iterator iter = | 1163 ClientIdToShaderCacheMap::iterator iter = |
| 1166 client_id_to_shader_cache_.find(client_id); | 1164 client_id_to_shader_cache_.find(client_id); |
| 1167 // If the cache doesn't exist then this is an off the record profile. | 1165 // If the cache doesn't exist then this is an off the record profile. |
| 1168 if (iter == client_id_to_shader_cache_.end()) | 1166 if (iter == client_id_to_shader_cache_.end()) |
| 1169 return; | 1167 return; |
| 1170 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1168 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1171 } | 1169 } |
| 1172 | 1170 |
| 1173 } // namespace content | 1171 } // namespace content |
| OLD | NEW |