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/browser_gpu_channel_host_factory.h" | 5 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 210 |
211 bool BrowserGpuChannelHostFactory::CanUseForTesting() { | 211 bool BrowserGpuChannelHostFactory::CanUseForTesting() { |
212 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL); | 212 return GpuDataManager::GetInstance()->GpuAccessAllowed(NULL); |
213 } | 213 } |
214 | 214 |
215 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) { | 215 void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) { |
216 DCHECK(!instance_); | 216 DCHECK(!instance_); |
217 instance_ = new BrowserGpuChannelHostFactory(); | 217 instance_ = new BrowserGpuChannelHostFactory(); |
218 if (establish_gpu_channel) { | 218 if (establish_gpu_channel) { |
219 instance_->EstablishGpuChannel(CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP, | 219 instance_->EstablishGpuChannel(CAUSE_FOR_GPU_LAUNCH_BROWSER_STARTUP, |
220 base::Closure()); | 220 gpu::GpuChannelEstablishedCallback()); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void BrowserGpuChannelHostFactory::Terminate() { | 224 void BrowserGpuChannelHostFactory::Terminate() { |
225 DCHECK(instance_); | 225 DCHECK(instance_); |
226 delete instance_; | 226 delete instance_; |
227 instance_ = NULL; | 227 instance_ = NULL; |
228 } | 228 } |
229 | 229 |
230 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() | 230 BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory() |
(...skipping 19 matching lines...) Expand all Loading... |
250 gpu_client_id_, cache_dir)); | 250 gpu_client_id_, cache_dir)); |
251 } | 251 } |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { | 255 BrowserGpuChannelHostFactory::~BrowserGpuChannelHostFactory() { |
256 DCHECK(IsMainThread()); | 256 DCHECK(IsMainThread()); |
257 if (pending_request_.get()) | 257 if (pending_request_.get()) |
258 pending_request_->Cancel(); | 258 pending_request_->Cancel(); |
259 for (size_t n = 0; n < established_callbacks_.size(); n++) | 259 for (size_t n = 0; n < established_callbacks_.size(); n++) |
260 established_callbacks_[n].Run(); | 260 established_callbacks_[n].Run(nullptr); |
261 shutdown_event_->Signal(); | 261 shutdown_event_->Signal(); |
262 if (gpu_channel_) { | 262 if (gpu_channel_) { |
263 gpu_channel_->DestroyChannel(); | 263 gpu_channel_->DestroyChannel(); |
264 gpu_channel_ = NULL; | 264 gpu_channel_ = NULL; |
265 } | 265 } |
266 } | 266 } |
267 | 267 |
268 bool BrowserGpuChannelHostFactory::IsMainThread() { | 268 bool BrowserGpuChannelHostFactory::IsMainThread() { |
269 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 269 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
270 } | 270 } |
(...skipping 11 matching lines...) Expand all Loading... |
282 return shm; | 282 return shm; |
283 } | 283 } |
284 | 284 |
285 // Blocking the UI thread to open a GPU channel is not supported on Android. | 285 // Blocking the UI thread to open a GPU channel is not supported on Android. |
286 // (Opening the initial channel to a child process involves handling a reply | 286 // (Opening the initial channel to a child process involves handling a reply |
287 // task on the UI thread first, so we cannot block here.) | 287 // task on the UI thread first, so we cannot block here.) |
288 #if !defined(OS_ANDROID) | 288 #if !defined(OS_ANDROID) |
289 scoped_refptr<gpu::GpuChannelHost> | 289 scoped_refptr<gpu::GpuChannelHost> |
290 BrowserGpuChannelHostFactory::EstablishGpuChannelSync( | 290 BrowserGpuChannelHostFactory::EstablishGpuChannelSync( |
291 CauseForGpuLaunch cause_for_gpu_launch) { | 291 CauseForGpuLaunch cause_for_gpu_launch) { |
292 EstablishGpuChannel(cause_for_gpu_launch, base::Closure()); | 292 EstablishGpuChannel(cause_for_gpu_launch, |
| 293 gpu::GpuChannelEstablishedCallback()); |
293 | 294 |
294 if (pending_request_.get()) | 295 if (pending_request_.get()) |
295 pending_request_->Wait(); | 296 pending_request_->Wait(); |
296 | 297 |
297 return gpu_channel_; | 298 return gpu_channel_; |
298 } | 299 } |
299 #endif | 300 #endif |
300 | 301 |
301 void BrowserGpuChannelHostFactory::EstablishGpuChannel( | 302 void BrowserGpuChannelHostFactory::EstablishGpuChannel( |
302 CauseForGpuLaunch cause_for_gpu_launch, | 303 CauseForGpuLaunch cause_for_gpu_launch, |
303 const base::Closure& callback) { | 304 const gpu::GpuChannelEstablishedCallback& callback) { |
304 #if defined(MOJO_RUNNER_CLIENT) | 305 #if defined(MOJO_RUNNER_CLIENT) |
305 DCHECK(!shell::ShellIsRemote()); | 306 DCHECK(!shell::ShellIsRemote()); |
306 #endif | 307 #endif |
307 if (gpu_channel_.get() && gpu_channel_->IsLost()) { | 308 if (gpu_channel_.get() && gpu_channel_->IsLost()) { |
308 DCHECK(!pending_request_.get()); | 309 DCHECK(!pending_request_.get()); |
309 // Recreate the channel if it has been lost. | 310 // Recreate the channel if it has been lost. |
310 gpu_channel_->DestroyChannel(); | 311 gpu_channel_->DestroyChannel(); |
311 gpu_channel_ = NULL; | 312 gpu_channel_ = NULL; |
312 } | 313 } |
313 | 314 |
314 if (!gpu_channel_.get() && !pending_request_.get()) { | 315 if (!gpu_channel_.get() && !pending_request_.get()) { |
315 // We should only get here if the context was lost. | 316 // We should only get here if the context was lost. |
316 pending_request_ = EstablishRequest::Create( | 317 pending_request_ = EstablishRequest::Create( |
317 cause_for_gpu_launch, gpu_client_id_, | 318 cause_for_gpu_launch, gpu_client_id_, |
318 gpu_client_tracing_id_, | 319 gpu_client_tracing_id_, |
319 gpu_host_id_); | 320 gpu_host_id_); |
320 } | 321 } |
321 | 322 |
322 if (!callback.is_null()) { | 323 if (!callback.is_null()) { |
323 if (gpu_channel_.get()) | 324 if (gpu_channel_.get()) |
324 callback.Run(); | 325 callback.Run(gpu_channel_); |
325 else | 326 else |
326 established_callbacks_.push_back(callback); | 327 established_callbacks_.push_back(callback); |
327 } | 328 } |
328 } | 329 } |
329 | 330 |
330 gpu::GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { | 331 gpu::GpuChannelHost* BrowserGpuChannelHostFactory::GetGpuChannel() { |
331 if (gpu_channel_.get() && !gpu_channel_->IsLost()) | 332 if (gpu_channel_.get() && !gpu_channel_->IsLost()) |
332 return gpu_channel_.get(); | 333 return gpu_channel_.get(); |
333 | 334 |
334 return NULL; | 335 return NULL; |
(...skipping 19 matching lines...) Expand all Loading... |
354 gpu_host_id_ = pending_request_->gpu_host_id(); | 355 gpu_host_id_ = pending_request_->gpu_host_id(); |
355 pending_request_ = NULL; | 356 pending_request_ = NULL; |
356 | 357 |
357 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466866 is | 358 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/466866 is |
358 // fixed. | 359 // fixed. |
359 tracked_objects::ScopedTracker tracking_profile2( | 360 tracked_objects::ScopedTracker tracking_profile2( |
360 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 361 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
361 "466866 BrowserGpuChannelHostFactory::GpuChannelEstablished2")); | 362 "466866 BrowserGpuChannelHostFactory::GpuChannelEstablished2")); |
362 | 363 |
363 for (size_t n = 0; n < established_callbacks_.size(); n++) | 364 for (size_t n = 0; n < established_callbacks_.size(); n++) |
364 established_callbacks_[n].Run(); | 365 established_callbacks_[n].Run(gpu_channel_); |
365 | 366 |
366 established_callbacks_.clear(); | 367 established_callbacks_.clear(); |
367 } | 368 } |
368 | 369 |
369 // static | 370 // static |
370 void BrowserGpuChannelHostFactory::AddFilterOnIO( | 371 void BrowserGpuChannelHostFactory::AddFilterOnIO( |
371 int host_id, | 372 int host_id, |
372 scoped_refptr<IPC::MessageFilter> filter) { | 373 scoped_refptr<IPC::MessageFilter> filter) { |
373 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 374 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
374 | 375 |
375 GpuProcessHost* host = GpuProcessHost::FromID(host_id); | 376 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
376 if (host) | 377 if (host) |
377 host->AddFilter(filter.get()); | 378 host->AddFilter(filter.get()); |
378 } | 379 } |
379 | 380 |
380 // static | 381 // static |
381 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( | 382 void BrowserGpuChannelHostFactory::InitializeShaderDiskCacheOnIO( |
382 int gpu_client_id, | 383 int gpu_client_id, |
383 const base::FilePath& cache_dir) { | 384 const base::FilePath& cache_dir) { |
384 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir); | 385 ShaderCacheFactory::GetInstance()->SetCacheInfo(gpu_client_id, cache_dir); |
385 } | 386 } |
386 | 387 |
387 } // namespace content | 388 } // namespace content |
OLD | NEW |