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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 if (!compositor->GetRendererSettings().disable_display_vsync) { | 440 if (!compositor->GetRendererSettings().disable_display_vsync) { |
441 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 441 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
442 base::MakeUnique<cc::DelayBasedTimeSource>( | 442 base::MakeUnique<cc::DelayBasedTimeSource>( |
443 compositor->task_runner().get()))); | 443 compositor->task_runner().get()))); |
444 } else { | 444 } else { |
445 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( | 445 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( |
446 base::MakeUnique<cc::DelayBasedTimeSource>( | 446 base::MakeUnique<cc::DelayBasedTimeSource>( |
447 compositor->task_runner().get()))); | 447 compositor->task_runner().get()))); |
448 } | 448 } |
449 | 449 |
| 450 BrowserCompositorOutputSurface::UpdateVSyncParametersCallback vsync_callback = |
| 451 base::Bind(&ui::Compositor::SetDisplayVSyncParameters, compositor); |
| 452 |
450 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; | 453 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; |
451 #if defined(ENABLE_VULKAN) | 454 #if defined(ENABLE_VULKAN) |
452 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | 455 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
453 if (vulkan_context_provider) { | 456 if (vulkan_context_provider) { |
454 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | 457 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
455 vulkan_context_provider, compositor->vsync_manager(), | 458 vulkan_context_provider, vsync_callback)); |
456 begin_frame_source.get())); | |
457 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | 459 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
458 vulkan_surface->Destroy(); | 460 vulkan_surface->Destroy(); |
459 vulkan_surface.reset(); | 461 vulkan_surface.reset(); |
460 } else { | 462 } else { |
461 display_output_surface = std::move(vulkan_surface); | 463 display_output_surface = std::move(vulkan_surface); |
462 } | 464 } |
463 } | 465 } |
464 #endif | 466 #endif |
465 | 467 |
466 if (!display_output_surface) { | 468 if (!display_output_surface) { |
467 if (!create_gpu_output_surface) { | 469 if (!create_gpu_output_surface) { |
468 display_output_surface = | 470 display_output_surface = |
469 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( | 471 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( |
470 CreateSoftwareOutputDevice(compositor.get()), | 472 CreateSoftwareOutputDevice(compositor.get()), vsync_callback, |
471 compositor->vsync_manager(), begin_frame_source.get(), | |
472 compositor->task_runner()); | 473 compositor->task_runner()); |
473 } else { | 474 } else { |
474 DCHECK(context_provider); | 475 DCHECK(context_provider); |
475 const auto& capabilities = context_provider->ContextCapabilities(); | 476 const auto& capabilities = context_provider->ContextCapabilities(); |
476 if (data->surface_handle == gpu::kNullSurfaceHandle) { | 477 if (data->surface_handle == gpu::kNullSurfaceHandle) { |
477 display_output_surface = | 478 display_output_surface = |
478 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( | 479 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( |
479 context_provider, compositor->vsync_manager(), | 480 context_provider, vsync_callback, |
480 begin_frame_source.get(), | |
481 std::unique_ptr< | 481 std::unique_ptr< |
482 display_compositor::CompositorOverlayCandidateValidator>()); | 482 display_compositor::CompositorOverlayCandidateValidator>()); |
483 } else if (capabilities.surfaceless) { | 483 } else if (capabilities.surfaceless) { |
484 #if defined(OS_MACOSX) | 484 #if defined(OS_MACOSX) |
485 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( | 485 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( |
486 compositor->widget(), context_provider, data->surface_handle, | 486 compositor->widget(), context_provider, data->surface_handle, |
487 compositor->vsync_manager(), begin_frame_source.get(), | 487 vsync_callback, |
488 CreateOverlayCandidateValidator(compositor->widget()), | 488 CreateOverlayCandidateValidator(compositor->widget()), |
489 GetGpuMemoryBufferManager()); | 489 GetGpuMemoryBufferManager()); |
490 #else | 490 #else |
491 display_output_surface = | 491 display_output_surface = |
492 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( | 492 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( |
493 context_provider, data->surface_handle, | 493 context_provider, data->surface_handle, vsync_callback, |
494 compositor->vsync_manager(), begin_frame_source.get(), | |
495 CreateOverlayCandidateValidator(compositor->widget()), | 494 CreateOverlayCandidateValidator(compositor->widget()), |
496 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), | 495 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), |
497 GetGpuMemoryBufferManager()); | 496 GetGpuMemoryBufferManager()); |
498 #endif | 497 #endif |
499 } else { | 498 } else { |
500 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 499 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
501 validator; | 500 validator; |
502 const bool use_mus = IsUsingMus(); | 501 const bool use_mus = IsUsingMus(); |
503 #if !defined(OS_MACOSX) | 502 #if !defined(OS_MACOSX) |
504 // Overlays are only supported on surfaceless output surfaces on Mac. | 503 // Overlays are only supported on surfaceless output surfaces on Mac. |
505 if (!use_mus) | 504 if (!use_mus) |
506 validator = CreateOverlayCandidateValidator(compositor->widget()); | 505 validator = CreateOverlayCandidateValidator(compositor->widget()); |
507 #endif | 506 #endif |
508 if (!use_mus) { | 507 if (!use_mus) { |
509 display_output_surface = | 508 display_output_surface = |
510 base::MakeUnique<GpuBrowserCompositorOutputSurface>( | 509 base::MakeUnique<GpuBrowserCompositorOutputSurface>( |
511 context_provider, compositor->vsync_manager(), | 510 context_provider, vsync_callback, std::move(validator)); |
512 begin_frame_source.get(), std::move(validator)); | |
513 } else { | 511 } else { |
514 #if defined(USE_AURA) | 512 #if defined(USE_AURA) |
515 if (compositor->window()) { | 513 if (compositor->window()) { |
516 // TODO(mfomitchev): Remove this clause once we complete the switch | 514 // TODO(mfomitchev): Remove this clause once we complete the switch |
517 // to Aura-Mus. | 515 // to Aura-Mus. |
518 display_output_surface = | 516 display_output_surface = |
519 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 517 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
520 compositor->window(), context_provider, | 518 compositor->window(), context_provider, |
521 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 519 GetGpuMemoryBufferManager(), vsync_callback, |
522 begin_frame_source.get(), std::move(validator)); | 520 std::move(validator)); |
523 } else { | 521 } else { |
524 aura::WindowTreeHost* host = | 522 aura::WindowTreeHost* host = |
525 aura::WindowTreeHost::GetForAcceleratedWidget( | 523 aura::WindowTreeHost::GetForAcceleratedWidget( |
526 compositor->widget()); | 524 compositor->widget()); |
527 display_output_surface = | 525 display_output_surface = |
528 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 526 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
529 host->window(), context_provider, | 527 host->window(), context_provider, |
530 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 528 GetGpuMemoryBufferManager(), vsync_callback, |
531 begin_frame_source.get(), std::move(validator)); | 529 std::move(validator)); |
532 } | 530 } |
533 #else | 531 #else |
534 NOTREACHED(); | 532 NOTREACHED(); |
535 #endif | 533 #endif |
536 } | 534 } |
537 } | 535 } |
538 } | 536 } |
539 } | 537 } |
540 | 538 |
541 data->display_output_surface = display_output_surface.get(); | 539 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) { | 605 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
608 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 606 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
609 if (it == per_compositor_data_.end()) | 607 if (it == per_compositor_data_.end()) |
610 return; | 608 return; |
611 PerCompositorData* data = it->second.get(); | 609 PerCompositorData* data = it->second.get(); |
612 DCHECK(data); | 610 DCHECK(data); |
613 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 611 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
614 if (data->surface_handle) | 612 if (data->surface_handle) |
615 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 613 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
616 #endif | 614 #endif |
| 615 |
617 per_compositor_data_.erase(it); | 616 per_compositor_data_.erase(it); |
618 if (per_compositor_data_.empty()) { | 617 if (per_compositor_data_.empty()) { |
619 // Destroying the GLHelper may cause some async actions to be cancelled, | 618 // 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 | 619 // 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() | 620 // 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 | 621 // on the |gl_helper_| variable directly. So instead we call reset() on a |
623 // local std::unique_ptr. | 622 // local std::unique_ptr. |
624 std::unique_ptr<display_compositor::GLHelper> helper = | 623 std::unique_ptr<display_compositor::GLHelper> helper = |
625 std::move(gl_helper_); | 624 std::move(gl_helper_); |
626 | 625 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 shared_vulkan_context_provider_ = | 880 shared_vulkan_context_provider_ = |
882 cc::VulkanInProcessContextProvider::Create(); | 881 cc::VulkanInProcessContextProvider::Create(); |
883 } | 882 } |
884 | 883 |
885 shared_vulkan_context_provider_initialized_ = true; | 884 shared_vulkan_context_provider_initialized_ = true; |
886 } | 885 } |
887 return shared_vulkan_context_provider_; | 886 return shared_vulkan_context_provider_; |
888 } | 887 } |
889 | 888 |
890 } // namespace content | 889 } // namespace content |
OLD | NEW |