OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/gpu_process_transport_factory.h" | 5 #include "content/browser/compositor/gpu_process_transport_factory.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 data->display_output_surface = nullptr; | 296 data->display_output_surface = nullptr; |
297 data->begin_frame_source = nullptr; | 297 data->begin_frame_source = nullptr; |
298 } | 298 } |
299 | 299 |
300 #if defined(OS_WIN) | 300 #if defined(OS_WIN) |
301 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( | 301 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( |
302 compositor->widget()); | 302 compositor->widget()); |
303 #endif | 303 #endif |
304 | 304 |
305 const bool use_vulkan = static_cast<bool>(SharedVulkanContextProvider()); | 305 const bool use_vulkan = static_cast<bool>(SharedVulkanContextProvider()); |
306 const bool use_mus = IsUsingMus(); | |
307 const bool create_gpu_output_surface = | 306 const bool create_gpu_output_surface = |
308 ShouldCreateGpuOutputSurface(compositor.get()); | 307 ShouldCreateGpuOutputSurface(compositor.get()); |
309 if (create_gpu_output_surface && !use_vulkan) { | 308 if (create_gpu_output_surface && !use_vulkan) { |
310 base::Closure callback( | 309 gpu::GpuChannelEstablishedCallback callback( |
311 base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 310 base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
312 callback_factory_.GetWeakPtr(), compositor, | 311 callback_factory_.GetWeakPtr(), compositor, |
313 create_gpu_output_surface, 0)); | 312 create_gpu_output_surface, 0)); |
314 if (!use_mus) { | 313 auto* factory = gpu::GpuChannelEstablishFactory::GetInstance(); |
| 314 if (factory) { |
| 315 factory->EstablishGpuChannel(callback); |
| 316 } else { |
315 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 317 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( |
316 CAUSE_FOR_GPU_LAUNCH_SHARED_WORKER_THREAD_CONTEXT, callback); | 318 CAUSE_FOR_GPU_LAUNCH_SHARED_WORKER_THREAD_CONTEXT, callback); |
317 } else { | |
318 #if defined(MOJO_RUNNER_CLIENT) | |
319 ui::GpuService::GetInstance()->EstablishGpuChannel(callback); | |
320 #else | |
321 NOTREACHED(); | |
322 #endif | |
323 } | 319 } |
324 } else { | 320 } else { |
325 EstablishedGpuChannel(compositor, create_gpu_output_surface, 0); | 321 EstablishedGpuChannel(compositor, create_gpu_output_surface, 0, nullptr); |
326 } | 322 } |
327 } | 323 } |
328 | 324 |
329 void GpuProcessTransportFactory::EstablishedGpuChannel( | 325 void GpuProcessTransportFactory::EstablishedGpuChannel( |
330 base::WeakPtr<ui::Compositor> compositor, | 326 base::WeakPtr<ui::Compositor> compositor, |
331 bool create_gpu_output_surface, | 327 bool create_gpu_output_surface, |
332 int num_attempts) { | 328 int num_attempts, |
| 329 scoped_refptr<gpu::GpuChannelHost> established_channel_host) { |
333 if (!compositor) | 330 if (!compositor) |
334 return; | 331 return; |
335 | 332 |
336 // The widget might have been released in the meantime. | 333 // The widget might have been released in the meantime. |
337 PerCompositorDataMap::iterator it = | 334 PerCompositorDataMap::iterator it = |
338 per_compositor_data_.find(compositor.get()); | 335 per_compositor_data_.find(compositor.get()); |
339 if (it == per_compositor_data_.end()) | 336 if (it == per_compositor_data_.end()) |
340 return; | 337 return; |
341 | 338 |
342 PerCompositorData* data = it->second; | 339 PerCompositorData* data = it->second; |
343 DCHECK(data); | 340 DCHECK(data); |
344 | 341 |
345 if (num_attempts > kNumRetriesBeforeSoftwareFallback) { | 342 if (num_attempts > kNumRetriesBeforeSoftwareFallback) { |
346 #if defined(OS_CHROMEOS) | 343 #if defined(OS_CHROMEOS) |
347 LOG(FATAL) << "Unable to create a UI graphics context, and cannot use " | 344 LOG(FATAL) << "Unable to create a UI graphics context, and cannot use " |
348 << "software compositing on ChromeOS."; | 345 << "software compositing on ChromeOS."; |
349 #endif | 346 #endif |
350 create_gpu_output_surface = false; | 347 create_gpu_output_surface = false; |
351 } | 348 } |
352 | 349 |
353 #if defined(OS_WIN) | 350 #if defined(OS_WIN) |
354 gfx::RenderingWindowManager::GetInstance()->RegisterParent( | 351 gfx::RenderingWindowManager::GetInstance()->RegisterParent( |
355 compositor->widget()); | 352 compositor->widget()); |
356 #endif | 353 #endif |
357 | 354 |
358 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = | 355 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
359 SharedVulkanContextProvider(); | 356 SharedVulkanContextProvider(); |
360 const bool use_mus = IsUsingMus(); | |
361 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 357 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
362 if (create_gpu_output_surface && !vulkan_context_provider) { | 358 if (create_gpu_output_surface && !vulkan_context_provider) { |
363 // Try to reuse existing worker context provider. | 359 // Try to reuse existing worker context provider. |
364 if (shared_worker_context_provider_) { | 360 if (shared_worker_context_provider_) { |
365 bool lost; | 361 bool lost; |
366 { | 362 { |
367 // Note: If context is lost, we delete reference after releasing the | 363 // Note: If context is lost, we delete reference after releasing the |
368 // lock. | 364 // lock. |
369 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); | 365 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); |
370 lost = shared_worker_context_provider_->ContextGL() | 366 lost = shared_worker_context_provider_->ContextGL() |
371 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 367 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
372 } | 368 } |
373 if (lost) | 369 if (lost) |
374 shared_worker_context_provider_ = nullptr; | 370 shared_worker_context_provider_ = nullptr; |
375 } | 371 } |
376 | 372 |
377 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; | 373 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
378 if (GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) { | 374 if (GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) |
379 // We attempted to do EstablishGpuChannel already, so we just use | 375 gpu_channel_host = std::move(established_channel_host); |
380 // GetGpuChannel() instead of EstablishGpuChannelSync(). | |
381 if (!use_mus) { | |
382 gpu_channel_host = | |
383 BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); | |
384 } else { | |
385 #if defined(MOJO_RUNNER_CLIENT) | |
386 gpu_channel_host = ui::GpuService::GetInstance()->GetGpuChannel(); | |
387 #else | |
388 NOTREACHED(); | |
389 #endif | |
390 } | |
391 } | |
392 | 376 |
393 if (!gpu_channel_host) { | 377 if (!gpu_channel_host) { |
394 shared_worker_context_provider_ = nullptr; | 378 shared_worker_context_provider_ = nullptr; |
395 } else { | 379 } else { |
396 if (!shared_worker_context_provider_) { | 380 if (!shared_worker_context_provider_) { |
397 bool need_alpha_channel = false; | 381 bool need_alpha_channel = false; |
398 const bool support_locking = true; | 382 const bool support_locking = true; |
399 shared_worker_context_provider_ = | 383 shared_worker_context_provider_ = |
400 CreateContextCommon(gpu_channel_host, gpu::kNullSurfaceHandle, | 384 CreateContextCommon(gpu_channel_host, gpu::kNullSurfaceHandle, |
401 need_alpha_channel, support_locking, nullptr, | 385 need_alpha_channel, support_locking, nullptr, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 } | 430 } |
447 | 431 |
448 bool created_gpu_browser_compositor = | 432 bool created_gpu_browser_compositor = |
449 !!context_provider && !!shared_worker_context_provider_; | 433 !!context_provider && !!shared_worker_context_provider_; |
450 | 434 |
451 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", | 435 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", |
452 created_gpu_browser_compositor); | 436 created_gpu_browser_compositor); |
453 | 437 |
454 if (!created_gpu_browser_compositor) { | 438 if (!created_gpu_browser_compositor) { |
455 // Try again. | 439 // Try again. |
456 base::Closure callback( | 440 gpu::GpuChannelEstablishedCallback callback( |
457 base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 441 base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
458 callback_factory_.GetWeakPtr(), compositor, | 442 callback_factory_.GetWeakPtr(), compositor, |
459 create_gpu_output_surface, num_attempts + 1)); | 443 create_gpu_output_surface, num_attempts + 1)); |
460 if (!use_mus) { | 444 auto* factory = gpu::GpuChannelEstablishFactory::GetInstance(); |
| 445 if (factory) { |
| 446 DCHECK(IsUsingMus()); |
| 447 factory->EstablishGpuChannel(callback); |
| 448 } else { |
461 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 449 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( |
462 CAUSE_FOR_GPU_LAUNCH_SHARED_WORKER_THREAD_CONTEXT, callback); | 450 CAUSE_FOR_GPU_LAUNCH_SHARED_WORKER_THREAD_CONTEXT, callback); |
463 } else { | |
464 #if defined(MOJO_RUNNER_CLIENT) | |
465 ui::GpuService::GetInstance()->EstablishGpuChannel(callback); | |
466 #else | |
467 NOTREACHED(); | |
468 #endif | |
469 } | 451 } |
470 return; | 452 return; |
471 } | 453 } |
472 } | 454 } |
473 | 455 |
474 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source; | 456 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source; |
475 if (!compositor->GetRendererSettings().disable_display_vsync) { | 457 if (!compositor->GetRendererSettings().disable_display_vsync) { |
476 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 458 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
477 base::MakeUnique<cc::DelayBasedTimeSource>( | 459 base::MakeUnique<cc::DelayBasedTimeSource>( |
478 compositor->task_runner().get()))); | 460 compositor->task_runner().get()))); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( | 508 base::WrapUnique(new GpuSurfacelessBrowserCompositorOutputSurface( |
527 context_provider, data->surface_handle, | 509 context_provider, data->surface_handle, |
528 compositor->vsync_manager(), begin_frame_source.get(), | 510 compositor->vsync_manager(), begin_frame_source.get(), |
529 CreateOverlayCandidateValidator(compositor->widget()), | 511 CreateOverlayCandidateValidator(compositor->widget()), |
530 GL_TEXTURE_2D, GL_RGB, | 512 GL_TEXTURE_2D, GL_RGB, |
531 BrowserGpuMemoryBufferManager::current())); | 513 BrowserGpuMemoryBufferManager::current())); |
532 #endif | 514 #endif |
533 } else { | 515 } else { |
534 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 516 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
535 validator; | 517 validator; |
| 518 const bool use_mus = IsUsingMus(); |
536 #if !defined(OS_MACOSX) | 519 #if !defined(OS_MACOSX) |
537 // Overlays are only supported on surfaceless output surfaces on Mac. | 520 // Overlays are only supported on surfaceless output surfaces on Mac. |
538 if (!use_mus) | 521 if (!use_mus) |
539 validator = CreateOverlayCandidateValidator(compositor->widget()); | 522 validator = CreateOverlayCandidateValidator(compositor->widget()); |
540 #endif | 523 #endif |
541 if (!use_mus) { | 524 if (!use_mus) { |
542 display_output_surface = | 525 display_output_surface = |
543 base::WrapUnique(new GpuBrowserCompositorOutputSurface( | 526 base::WrapUnique(new GpuBrowserCompositorOutputSurface( |
544 context_provider, compositor->vsync_manager(), | 527 context_provider, compositor->vsync_manager(), |
545 begin_frame_source.get(), std::move(validator))); | 528 begin_frame_source.get(), std::move(validator))); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 #endif | 773 #endif |
791 | 774 |
792 scoped_refptr<cc::ContextProvider> | 775 scoped_refptr<cc::ContextProvider> |
793 GpuProcessTransportFactory::SharedMainThreadContextProvider() { | 776 GpuProcessTransportFactory::SharedMainThreadContextProvider() { |
794 if (shared_main_thread_contexts_) | 777 if (shared_main_thread_contexts_) |
795 return shared_main_thread_contexts_; | 778 return shared_main_thread_contexts_; |
796 | 779 |
797 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) | 780 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) |
798 return nullptr; | 781 return nullptr; |
799 | 782 |
800 const bool use_mus = IsUsingMus(); | |
801 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; | 783 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
802 if (!use_mus) { | 784 auto* factory = gpu::GpuChannelEstablishFactory::GetInstance(); |
| 785 if (factory) { |
| 786 gpu_channel_host = factory->EstablishGpuChannelSync(); |
| 787 } else { |
803 gpu_channel_host = | 788 gpu_channel_host = |
804 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync( | 789 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync( |
805 CAUSE_FOR_GPU_LAUNCH_BROWSER_SHARED_MAIN_THREAD_CONTEXT); | 790 CAUSE_FOR_GPU_LAUNCH_BROWSER_SHARED_MAIN_THREAD_CONTEXT); |
806 } else { | |
807 #if defined(MOJO_RUNNER_CLIENT) | |
808 gpu_channel_host = ui::GpuService::GetInstance()->EstablishGpuChannelSync(); | |
809 #else | |
810 NOTREACHED(); | |
811 #endif | |
812 } | 791 } |
813 | 792 |
814 if (!gpu_channel_host) | 793 if (!gpu_channel_host) |
815 return nullptr; | 794 return nullptr; |
816 | 795 |
817 // We need a separate context from the compositor's so that skia and gl_helper | 796 // We need a separate context from the compositor's so that skia and gl_helper |
818 // don't step on each other. | 797 // don't step on each other. |
819 bool need_alpha_channel = false; | 798 bool need_alpha_channel = false; |
820 bool support_locking = false; | 799 bool support_locking = false; |
821 shared_main_thread_contexts_ = CreateContextCommon( | 800 shared_main_thread_contexts_ = CreateContextCommon( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 shared_vulkan_context_provider_ = | 876 shared_vulkan_context_provider_ = |
898 cc::VulkanInProcessContextProvider::Create(); | 877 cc::VulkanInProcessContextProvider::Create(); |
899 } | 878 } |
900 | 879 |
901 shared_vulkan_context_provider_initialized_ = true; | 880 shared_vulkan_context_provider_initialized_ = true; |
902 } | 881 } |
903 return shared_vulkan_context_provider_; | 882 return shared_vulkan_context_provider_; |
904 } | 883 } |
905 | 884 |
906 } // namespace content | 885 } // namespace content |
OLD | NEW |