| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/field_trial.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 16 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/simple_thread.h" | 18 #include "base/threading/simple_thread.h" |
| 18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "cc/base/histograms.h" | 22 #include "cc/base/histograms.h" |
| 22 #include "cc/output/texture_mailbox_deleter.h" | 23 #include "cc/output/texture_mailbox_deleter.h" |
| 23 #include "cc/output/vulkan_in_process_context_provider.h" | 24 #include "cc/output/vulkan_in_process_context_provider.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 51 #include "services/service_manager/runner/common/client_util.h" | 52 #include "services/service_manager/runner/common/client_util.h" |
| 52 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 53 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
| 53 #include "third_party/khronos/GLES2/gl2.h" | 54 #include "third_party/khronos/GLES2/gl2.h" |
| 54 #include "ui/compositor/compositor.h" | 55 #include "ui/compositor/compositor.h" |
| 55 #include "ui/compositor/compositor_constants.h" | 56 #include "ui/compositor/compositor_constants.h" |
| 56 #include "ui/compositor/compositor_switches.h" | 57 #include "ui/compositor/compositor_switches.h" |
| 57 #include "ui/compositor/layer.h" | 58 #include "ui/compositor/layer.h" |
| 58 #include "ui/display/types/display_snapshot.h" | 59 #include "ui/display/types/display_snapshot.h" |
| 59 #include "ui/gfx/geometry/size.h" | 60 #include "ui/gfx/geometry/size.h" |
| 60 #include "ui/gfx/switches.h" | 61 #include "ui/gfx/switches.h" |
| 62 #include "ui/gl/gl_switches.h" |
| 61 | 63 |
| 62 #if defined(USE_AURA) | 64 #if defined(USE_AURA) |
| 63 #include "content/browser/compositor/mus_browser_compositor_output_surface.h" | 65 #include "content/browser/compositor/mus_browser_compositor_output_surface.h" |
| 64 #include "content/public/common/service_manager_connection.h" | 66 #include "content/public/common/service_manager_connection.h" |
| 65 #include "ui/aura/window_tree_host.h" | 67 #include "ui/aura/window_tree_host.h" |
| 66 #endif | 68 #endif |
| 67 | 69 |
| 68 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
| 69 #include "content/browser/compositor/software_output_device_win.h" | 71 #include "content/browser/compositor/software_output_device_win.h" |
| 70 #include "ui/gfx/win/rendering_window_manager.h" | 72 #include "ui/gfx/win/rendering_window_manager.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 100 using gpu::gles2::GLES2Interface; | 102 using gpu::gles2::GLES2Interface; |
| 101 | 103 |
| 102 namespace { | 104 namespace { |
| 103 | 105 |
| 104 const int kNumRetriesBeforeSoftwareFallback = 4; | 106 const int kNumRetriesBeforeSoftwareFallback = 4; |
| 105 | 107 |
| 106 bool IsUsingMus() { | 108 bool IsUsingMus() { |
| 107 return service_manager::ServiceManagerIsRemote(); | 109 return service_manager::ServiceManagerIsRemote(); |
| 108 } | 110 } |
| 109 | 111 |
| 112 bool IsGpuVSyncSignalSupported() { |
| 113 #if defined(OS_WIN) |
| 114 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 115 if (command_line->HasSwitch(switches::kUseD3DVSync)) |
| 116 return true; |
| 117 |
| 118 const std::string group_name = |
| 119 base::FieldTrialList::FindFullName("UseD3DVSync"); |
| 120 return group_name == "Enabled"; |
| 121 #else |
| 122 return false; |
| 123 #endif // defined(OS_WIN) |
| 124 } |
| 125 |
| 110 scoped_refptr<ui::ContextProviderCommandBuffer> CreateContextCommon( | 126 scoped_refptr<ui::ContextProviderCommandBuffer> CreateContextCommon( |
| 111 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 127 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 112 gpu::SurfaceHandle surface_handle, | 128 gpu::SurfaceHandle surface_handle, |
| 113 bool need_alpha_channel, | 129 bool need_alpha_channel, |
| 114 bool support_locking, | 130 bool support_locking, |
| 115 ui::ContextProviderCommandBuffer* shared_context_provider, | 131 ui::ContextProviderCommandBuffer* shared_context_provider, |
| 116 ui::command_buffer_metrics::ContextType type) { | 132 ui::command_buffer_metrics::ContextType type) { |
| 117 DCHECK( | 133 DCHECK( |
| 118 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); | 134 content::GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()); |
| 119 DCHECK(gpu_channel_host); | 135 DCHECK(gpu_channel_host); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 gpu::GpuChannelEstablishedCallback callback( | 456 gpu::GpuChannelEstablishedCallback callback( |
| 441 base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, | 457 base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel, |
| 442 callback_factory_.GetWeakPtr(), compositor, | 458 callback_factory_.GetWeakPtr(), compositor, |
| 443 create_gpu_output_surface, num_attempts + 1)); | 459 create_gpu_output_surface, num_attempts + 1)); |
| 444 DCHECK(gpu_channel_factory_); | 460 DCHECK(gpu_channel_factory_); |
| 445 gpu_channel_factory_->EstablishGpuChannel(callback); | 461 gpu_channel_factory_->EstablishGpuChannel(callback); |
| 446 return; | 462 return; |
| 447 } | 463 } |
| 448 } | 464 } |
| 449 | 465 |
| 450 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source; | |
| 451 if (!compositor->GetRendererSettings().disable_display_vsync) { | |
| 452 synthetic_begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | |
| 453 base::MakeUnique<cc::DelayBasedTimeSource>( | |
| 454 compositor->task_runner().get()))); | |
| 455 } else { | |
| 456 synthetic_begin_frame_source.reset(new cc::BackToBackBeginFrameSource( | |
| 457 base::MakeUnique<cc::DelayBasedTimeSource>( | |
| 458 compositor->task_runner().get()))); | |
| 459 } | |
| 460 cc::BeginFrameSource* begin_frame_source = synthetic_begin_frame_source.get(); | |
| 461 | |
| 462 BrowserCompositorOutputSurface::UpdateVSyncParametersCallback vsync_callback = | 466 BrowserCompositorOutputSurface::UpdateVSyncParametersCallback vsync_callback = |
| 463 base::Bind(&ui::Compositor::SetDisplayVSyncParameters, compositor); | 467 base::Bind(&ui::Compositor::SetDisplayVSyncParameters, compositor); |
| 468 cc::BeginFrameSource* begin_frame_source = nullptr; |
| 464 | 469 |
| 465 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; | 470 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; |
| 466 #if defined(ENABLE_VULKAN) | 471 #if defined(ENABLE_VULKAN) |
| 467 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | 472 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
| 468 if (vulkan_context_provider) { | 473 if (vulkan_context_provider) { |
| 469 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | 474 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
| 470 vulkan_context_provider, vsync_callback)); | 475 vulkan_context_provider, vsync_callback)); |
| 471 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | 476 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
| 472 vulkan_surface->Destroy(); | 477 vulkan_surface->Destroy(); |
| 473 vulkan_surface.reset(); | 478 vulkan_surface.reset(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 const bool use_mus = IsUsingMus(); | 519 const bool use_mus = IsUsingMus(); |
| 515 #if !defined(OS_MACOSX) | 520 #if !defined(OS_MACOSX) |
| 516 // Overlays are only supported on surfaceless output surfaces on Mac. | 521 // Overlays are only supported on surfaceless output surfaces on Mac. |
| 517 if (!use_mus) | 522 if (!use_mus) |
| 518 validator = CreateOverlayCandidateValidator(compositor->widget()); | 523 validator = CreateOverlayCandidateValidator(compositor->widget()); |
| 519 #endif | 524 #endif |
| 520 if (!use_mus) { | 525 if (!use_mus) { |
| 521 display_output_surface = | 526 display_output_surface = |
| 522 base::MakeUnique<GpuBrowserCompositorOutputSurface>( | 527 base::MakeUnique<GpuBrowserCompositorOutputSurface>( |
| 523 context_provider, vsync_callback, std::move(validator)); | 528 context_provider, vsync_callback, std::move(validator)); |
| 529 |
| 524 } else { | 530 } else { |
| 525 #if defined(USE_AURA) | 531 #if defined(USE_AURA) |
| 526 std::unique_ptr<MusBrowserCompositorOutputSurface> mus_output_surface; | 532 std::unique_ptr<MusBrowserCompositorOutputSurface> mus_output_surface; |
| 527 if (compositor->window()) { | 533 if (compositor->window()) { |
| 528 // TODO(mfomitchev): Remove this clause once we complete the switch | 534 // TODO(mfomitchev): Remove this clause once we complete the switch |
| 529 // to Aura-Mus. | 535 // to Aura-Mus. |
| 530 mus_output_surface = | 536 mus_output_surface = |
| 531 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 537 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 532 compositor->window(), context_provider, | 538 compositor->window(), context_provider, |
| 533 GetGpuMemoryBufferManager(), vsync_callback, | 539 GetGpuMemoryBufferManager(), vsync_callback, |
| 534 std::move(validator)); | 540 std::move(validator)); |
| 535 } else { | 541 } else { |
| 536 aura::WindowTreeHost* host = | 542 aura::WindowTreeHost* host = |
| 537 aura::WindowTreeHost::GetForAcceleratedWidget( | 543 aura::WindowTreeHost::GetForAcceleratedWidget( |
| 538 compositor->widget()); | 544 compositor->widget()); |
| 539 mus_output_surface = | 545 mus_output_surface = |
| 540 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 546 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 541 host->window(), context_provider, | 547 host->window(), context_provider, |
| 542 GetGpuMemoryBufferManager(), vsync_callback, | 548 GetGpuMemoryBufferManager(), vsync_callback, |
| 543 std::move(validator)); | 549 std::move(validator)); |
| 544 } | 550 } |
| 545 // We use the ExternalBeginFrameSource provided by the output surface | 551 // We use the ExternalBeginFrameSource provided by the output surface |
| 546 // instead of our own synthetic one. | 552 // instead of our own synthetic one. |
| 547 synthetic_begin_frame_source.reset(); | |
| 548 begin_frame_source = mus_output_surface->GetBeginFrameSource(); | 553 begin_frame_source = mus_output_surface->GetBeginFrameSource(); |
| 549 DCHECK(begin_frame_source); | 554 DCHECK(begin_frame_source); |
| 550 display_output_surface = std::move(mus_output_surface); | 555 display_output_surface = std::move(mus_output_surface); |
| 551 #else | 556 #else |
| 552 NOTREACHED(); | 557 NOTREACHED(); |
| 553 #endif | 558 #endif |
| 554 } | 559 } |
| 555 } | 560 } |
| 556 } | 561 } |
| 557 } | 562 } |
| 558 | 563 |
| 559 data->display_output_surface = display_output_surface.get(); | 564 std::unique_ptr<cc::SyntheticBeginFrameSource> synthetic_begin_frame_source; |
| 565 |
| 566 if (!begin_frame_source) { |
| 567 if (!compositor->GetRendererSettings().disable_display_vsync) { |
| 568 GpuVSyncControl* vsync_control = |
| 569 display_output_surface->GetVSyncControl(); |
| 570 if (vsync_control && IsGpuVSyncSignalSupported()) { |
| 571 synthetic_begin_frame_source.reset( |
| 572 new GpuVSyncBeginFrameSource(vsync_control)); |
| 573 } else { |
| 574 synthetic_begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
| 575 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 576 compositor->task_runner().get()))); |
| 577 } |
| 578 } else { |
| 579 synthetic_begin_frame_source.reset(new cc::BackToBackBeginFrameSource( |
| 580 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 581 compositor->task_runner().get()))); |
| 582 } |
| 583 |
| 584 begin_frame_source = synthetic_begin_frame_source.get(); |
| 585 } |
| 586 |
| 560 if (data->reflector) | 587 if (data->reflector) |
| 561 data->reflector->OnSourceSurfaceReady(data->display_output_surface); | 588 data->reflector->OnSourceSurfaceReady(data->display_output_surface); |
| 562 | 589 |
| 563 #if defined(OS_WIN) | 590 #if defined(OS_WIN) |
| 564 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( | 591 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( |
| 565 compositor->widget()); | 592 compositor->widget()); |
| 566 #endif | 593 #endif |
| 567 | 594 |
| 568 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 595 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 569 compositor->task_runner().get(), | 596 compositor->task_runner().get(), |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 shared_vulkan_context_provider_ = | 934 shared_vulkan_context_provider_ = |
| 908 cc::VulkanInProcessContextProvider::Create(); | 935 cc::VulkanInProcessContextProvider::Create(); |
| 909 } | 936 } |
| 910 | 937 |
| 911 shared_vulkan_context_provider_initialized_ = true; | 938 shared_vulkan_context_provider_initialized_ = true; |
| 912 } | 939 } |
| 913 return shared_vulkan_context_provider_; | 940 return shared_vulkan_context_provider_; |
| 914 } | 941 } |
| 915 | 942 |
| 916 } // namespace content | 943 } // namespace content |
| OLD | NEW |