| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 shared_context_provider, type)); | 150 shared_context_provider, type)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 #if defined(OS_MACOSX) | 153 #if defined(OS_MACOSX) |
| 154 bool IsCALayersDisabledFromCommandLine() { | 154 bool IsCALayersDisabledFromCommandLine() { |
| 155 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 155 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 156 return command_line->HasSwitch(switches::kDisableMacOverlays); | 156 return command_line->HasSwitch(switches::kDisableMacOverlays); |
| 157 } | 157 } |
| 158 #endif | 158 #endif |
| 159 | 159 |
| 160 void UpdateVSyncParameters(base::WeakPtr<ui::Compositor> compositor, |
| 161 base::TimeTicks timebase, |
| 162 base::TimeDelta interval) { |
| 163 DCHECK(!!compositor); |
| 164 compositor->SetDisplayVSyncParameters(timebase, interval); |
| 165 } |
| 166 |
| 160 } // namespace | 167 } // namespace |
| 161 | 168 |
| 162 namespace content { | 169 namespace content { |
| 163 | 170 |
| 164 struct GpuProcessTransportFactory::PerCompositorData { | 171 struct GpuProcessTransportFactory::PerCompositorData { |
| 165 gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; | 172 gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; |
| 166 BrowserCompositorOutputSurface* display_output_surface = nullptr; | 173 BrowserCompositorOutputSurface* display_output_surface = nullptr; |
| 167 cc::SyntheticBeginFrameSource* begin_frame_source = nullptr; | 174 cc::SyntheticBeginFrameSource* begin_frame_source = nullptr; |
| 168 ReflectorImpl* reflector = nullptr; | 175 ReflectorImpl* reflector = nullptr; |
| 169 std::unique_ptr<cc::Display> display; | 176 std::unique_ptr<cc::Display> display; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 if (!compositor->GetRendererSettings().disable_display_vsync) { | 447 if (!compositor->GetRendererSettings().disable_display_vsync) { |
| 441 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 448 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
| 442 base::MakeUnique<cc::DelayBasedTimeSource>( | 449 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 443 compositor->task_runner().get()))); | 450 compositor->task_runner().get()))); |
| 444 } else { | 451 } else { |
| 445 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( | 452 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( |
| 446 base::MakeUnique<cc::DelayBasedTimeSource>( | 453 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 447 compositor->task_runner().get()))); | 454 compositor->task_runner().get()))); |
| 448 } | 455 } |
| 449 | 456 |
| 457 BrowserCompositorOutputSurface::UpdateVSyncParametersCallback vsync_callback = |
| 458 base::Bind(&UpdateVSyncParameters, compositor); |
| 459 |
| 450 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; | 460 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; |
| 451 #if defined(ENABLE_VULKAN) | 461 #if defined(ENABLE_VULKAN) |
| 452 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | 462 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
| 453 if (vulkan_context_provider) { | 463 if (vulkan_context_provider) { |
| 454 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | 464 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
| 455 vulkan_context_provider, compositor->vsync_manager(), | 465 vulkan_context_provider, vsync_callback)); |
| 456 begin_frame_source.get())); | |
| 457 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | 466 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
| 458 vulkan_surface->Destroy(); | 467 vulkan_surface->Destroy(); |
| 459 vulkan_surface.reset(); | 468 vulkan_surface.reset(); |
| 460 } else { | 469 } else { |
| 461 display_output_surface = std::move(vulkan_surface); | 470 display_output_surface = std::move(vulkan_surface); |
| 462 } | 471 } |
| 463 } | 472 } |
| 464 #endif | 473 #endif |
| 465 | 474 |
| 466 if (!display_output_surface) { | 475 if (!display_output_surface) { |
| 467 if (!create_gpu_output_surface) { | 476 if (!create_gpu_output_surface) { |
| 468 display_output_surface = | 477 display_output_surface = |
| 469 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( | 478 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( |
| 470 CreateSoftwareOutputDevice(compositor.get()), | 479 CreateSoftwareOutputDevice(compositor.get()), vsync_callback, |
| 471 compositor->vsync_manager(), begin_frame_source.get(), | |
| 472 compositor->task_runner()); | 480 compositor->task_runner()); |
| 473 } else { | 481 } else { |
| 474 DCHECK(context_provider); | 482 DCHECK(context_provider); |
| 475 const auto& capabilities = context_provider->ContextCapabilities(); | 483 const auto& capabilities = context_provider->ContextCapabilities(); |
| 476 if (data->surface_handle == gpu::kNullSurfaceHandle) { | 484 if (data->surface_handle == gpu::kNullSurfaceHandle) { |
| 477 display_output_surface = | 485 display_output_surface = |
| 478 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( | 486 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( |
| 479 context_provider, compositor->vsync_manager(), | 487 context_provider, vsync_callback, |
| 480 begin_frame_source.get(), | |
| 481 std::unique_ptr< | 488 std::unique_ptr< |
| 482 display_compositor::CompositorOverlayCandidateValidator>()); | 489 display_compositor::CompositorOverlayCandidateValidator>()); |
| 483 } else if (capabilities.surfaceless) { | 490 } else if (capabilities.surfaceless) { |
| 484 #if defined(OS_MACOSX) | 491 #if defined(OS_MACOSX) |
| 485 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( | 492 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( |
| 486 compositor->widget(), context_provider, data->surface_handle, | 493 compositor->widget(), context_provider, data->surface_handle, |
| 487 compositor->vsync_manager(), begin_frame_source.get(), | 494 vsync_callback, |
| 488 CreateOverlayCandidateValidator(compositor->widget()), | 495 CreateOverlayCandidateValidator(compositor->widget()), |
| 489 GetGpuMemoryBufferManager()); | 496 GetGpuMemoryBufferManager()); |
| 490 #else | 497 #else |
| 491 display_output_surface = | 498 display_output_surface = |
| 492 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( | 499 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( |
| 493 context_provider, data->surface_handle, | 500 context_provider, data->surface_handle, vsync_callback, |
| 494 compositor->vsync_manager(), begin_frame_source.get(), | |
| 495 CreateOverlayCandidateValidator(compositor->widget()), | 501 CreateOverlayCandidateValidator(compositor->widget()), |
| 496 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), | 502 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), |
| 497 GetGpuMemoryBufferManager()); | 503 GetGpuMemoryBufferManager()); |
| 498 #endif | 504 #endif |
| 499 } else { | 505 } else { |
| 500 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 506 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| 501 validator; | 507 validator; |
| 502 const bool use_mus = IsUsingMus(); | 508 const bool use_mus = IsUsingMus(); |
| 503 #if !defined(OS_MACOSX) | 509 #if !defined(OS_MACOSX) |
| 504 // Overlays are only supported on surfaceless output surfaces on Mac. | 510 // Overlays are only supported on surfaceless output surfaces on Mac. |
| 505 if (!use_mus) | 511 if (!use_mus) |
| 506 validator = CreateOverlayCandidateValidator(compositor->widget()); | 512 validator = CreateOverlayCandidateValidator(compositor->widget()); |
| 507 #endif | 513 #endif |
| 508 if (!use_mus) { | 514 if (!use_mus) { |
| 509 display_output_surface = | 515 display_output_surface = |
| 510 base::MakeUnique<GpuBrowserCompositorOutputSurface>( | 516 base::MakeUnique<GpuBrowserCompositorOutputSurface>( |
| 511 context_provider, compositor->vsync_manager(), | 517 context_provider, vsync_callback, std::move(validator)); |
| 512 begin_frame_source.get(), std::move(validator)); | |
| 513 } else { | 518 } else { |
| 514 #if defined(USE_AURA) | 519 #if defined(USE_AURA) |
| 515 if (compositor->window()) { | 520 if (compositor->window()) { |
| 516 // TODO(mfomitchev): Remove this clause once we complete the switch | 521 // TODO(mfomitchev): Remove this clause once we complete the switch |
| 517 // to Aura-Mus. | 522 // to Aura-Mus. |
| 518 display_output_surface = | 523 display_output_surface = |
| 519 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 524 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 520 compositor->window(), context_provider, | 525 compositor->window(), context_provider, |
| 521 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 526 GetGpuMemoryBufferManager(), vsync_callback, |
| 522 begin_frame_source.get(), std::move(validator)); | 527 std::move(validator)); |
| 523 } else { | 528 } else { |
| 524 aura::WindowTreeHost* host = | 529 aura::WindowTreeHost* host = |
| 525 aura::WindowTreeHost::GetForAcceleratedWidget( | 530 aura::WindowTreeHost::GetForAcceleratedWidget( |
| 526 compositor->widget()); | 531 compositor->widget()); |
| 527 display_output_surface = | 532 display_output_surface = |
| 528 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 533 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 529 host->window(), context_provider, | 534 host->window(), context_provider, |
| 530 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 535 GetGpuMemoryBufferManager(), vsync_callback, |
| 531 begin_frame_source.get(), std::move(validator)); | 536 std::move(validator)); |
| 532 } | 537 } |
| 533 #else | 538 #else |
| 534 NOTREACHED(); | 539 NOTREACHED(); |
| 535 #endif | 540 #endif |
| 536 } | 541 } |
| 537 } | 542 } |
| 538 } | 543 } |
| 539 } | 544 } |
| 540 | 545 |
| 541 data->display_output_surface = display_output_surface.get(); | 546 data->display_output_surface = display_output_surface.get(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { | 612 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 608 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 613 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 609 if (it == per_compositor_data_.end()) | 614 if (it == per_compositor_data_.end()) |
| 610 return; | 615 return; |
| 611 PerCompositorData* data = it->second.get(); | 616 PerCompositorData* data = it->second.get(); |
| 612 DCHECK(data); | 617 DCHECK(data); |
| 613 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 618 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 614 if (data->surface_handle) | 619 if (data->surface_handle) |
| 615 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 620 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
| 616 #endif | 621 #endif |
| 622 |
| 617 per_compositor_data_.erase(it); | 623 per_compositor_data_.erase(it); |
| 618 if (per_compositor_data_.empty()) { | 624 if (per_compositor_data_.empty()) { |
| 619 // Destroying the GLHelper may cause some async actions to be cancelled, | 625 // Destroying the GLHelper may cause some async actions to be cancelled, |
| 620 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 626 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
| 621 // GLHelper created in this case would be lost/leaked if we just reset() | 627 // GLHelper created in this case would be lost/leaked if we just reset() |
| 622 // on the |gl_helper_| variable directly. So instead we call reset() on a | 628 // on the |gl_helper_| variable directly. So instead we call reset() on a |
| 623 // local std::unique_ptr. | 629 // local std::unique_ptr. |
| 624 std::unique_ptr<display_compositor::GLHelper> helper = | 630 std::unique_ptr<display_compositor::GLHelper> helper = |
| 625 std::move(gl_helper_); | 631 std::move(gl_helper_); |
| 626 | 632 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 shared_vulkan_context_provider_ = | 887 shared_vulkan_context_provider_ = |
| 882 cc::VulkanInProcessContextProvider::Create(); | 888 cc::VulkanInProcessContextProvider::Create(); |
| 883 } | 889 } |
| 884 | 890 |
| 885 shared_vulkan_context_provider_initialized_ = true; | 891 shared_vulkan_context_provider_initialized_ = true; |
| 886 } | 892 } |
| 887 return shared_vulkan_context_provider_; | 893 return shared_vulkan_context_provider_; |
| 888 } | 894 } |
| 889 | 895 |
| 890 } // namespace content | 896 } // namespace content |
| OLD | NEW |