Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "gpu/GLES2/gl2extchromium.h" | 45 #include "gpu/GLES2/gl2extchromium.h" |
| 46 #include "gpu/command_buffer/client/gles2_interface.h" | 46 #include "gpu/command_buffer/client/gles2_interface.h" |
| 47 #include "gpu/command_buffer/client/shared_memory_limits.h" | 47 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 48 #include "gpu/command_buffer/common/mailbox.h" | 48 #include "gpu/command_buffer/common/mailbox.h" |
| 49 #include "gpu/ipc/client/gpu_channel_host.h" | 49 #include "gpu/ipc/client/gpu_channel_host.h" |
| 50 #include "services/service_manager/runner/common/client_util.h" | 50 #include "services/service_manager/runner/common/client_util.h" |
| 51 #include "third_party/khronos/GLES2/gl2.h" | 51 #include "third_party/khronos/GLES2/gl2.h" |
| 52 #include "ui/compositor/compositor.h" | 52 #include "ui/compositor/compositor.h" |
| 53 #include "ui/compositor/compositor_constants.h" | 53 #include "ui/compositor/compositor_constants.h" |
| 54 #include "ui/compositor/compositor_switches.h" | 54 #include "ui/compositor/compositor_switches.h" |
| 55 #include "ui/compositor/compositor_vsync_manager.h" | |
| 55 #include "ui/compositor/layer.h" | 56 #include "ui/compositor/layer.h" |
| 56 #include "ui/display/types/display_snapshot.h" | 57 #include "ui/display/types/display_snapshot.h" |
| 57 #include "ui/gfx/geometry/size.h" | 58 #include "ui/gfx/geometry/size.h" |
| 58 | 59 |
| 59 #if defined(USE_AURA) | 60 #if defined(USE_AURA) |
| 60 #include "content/browser/compositor/mus_browser_compositor_output_surface.h" | 61 #include "content/browser/compositor/mus_browser_compositor_output_surface.h" |
| 61 #include "content/public/common/service_manager_connection.h" | 62 #include "content/public/common/service_manager_connection.h" |
| 62 #include "ui/aura/window_tree_host.h" | 63 #include "ui/aura/window_tree_host.h" |
| 63 #endif | 64 #endif |
| 64 | 65 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 if (!compositor->GetRendererSettings().disable_display_vsync) { | 441 if (!compositor->GetRendererSettings().disable_display_vsync) { |
| 441 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 442 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
| 442 base::MakeUnique<cc::DelayBasedTimeSource>( | 443 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 443 compositor->task_runner().get()))); | 444 compositor->task_runner().get()))); |
| 444 } else { | 445 } else { |
| 445 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( | 446 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( |
| 446 base::MakeUnique<cc::DelayBasedTimeSource>( | 447 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 447 compositor->task_runner().get()))); | 448 compositor->task_runner().get()))); |
| 448 } | 449 } |
| 449 | 450 |
| 451 BrowserCompositorOutputSurface::UpdateVSyncParametersCallback vsync_callback = | |
| 452 base::Bind(&GpuProcessTransportFactory::UpdateVSyncParametersFromGpu, | |
| 453 base::Unretained(this), compositor); | |
| 454 | |
| 450 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; | 455 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; |
| 451 #if defined(ENABLE_VULKAN) | 456 #if defined(ENABLE_VULKAN) |
| 452 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | 457 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
| 453 if (vulkan_context_provider) { | 458 if (vulkan_context_provider) { |
| 454 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | 459 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
| 455 vulkan_context_provider, compositor->vsync_manager(), | 460 vulkan_context_provider, vsync_callback)); |
| 456 begin_frame_source.get())); | |
| 457 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | 461 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
| 458 vulkan_surface->Destroy(); | 462 vulkan_surface->Destroy(); |
| 459 vulkan_surface.reset(); | 463 vulkan_surface.reset(); |
| 460 } else { | 464 } else { |
| 461 display_output_surface = std::move(vulkan_surface); | 465 display_output_surface = std::move(vulkan_surface); |
| 462 } | 466 } |
| 463 } | 467 } |
| 464 #endif | 468 #endif |
| 465 | 469 |
| 466 if (!display_output_surface) { | 470 if (!display_output_surface) { |
| 467 if (!create_gpu_output_surface) { | 471 if (!create_gpu_output_surface) { |
| 468 display_output_surface = | 472 display_output_surface = |
| 469 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( | 473 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( |
| 470 CreateSoftwareOutputDevice(compositor.get()), | 474 CreateSoftwareOutputDevice(compositor.get()), vsync_callback, |
| 471 compositor->vsync_manager(), begin_frame_source.get(), | |
| 472 compositor->task_runner()); | 475 compositor->task_runner()); |
| 473 } else { | 476 } else { |
| 474 DCHECK(context_provider); | 477 DCHECK(context_provider); |
| 475 const auto& capabilities = context_provider->ContextCapabilities(); | 478 const auto& capabilities = context_provider->ContextCapabilities(); |
| 476 if (data->surface_handle == gpu::kNullSurfaceHandle) { | 479 if (data->surface_handle == gpu::kNullSurfaceHandle) { |
| 477 display_output_surface = | 480 display_output_surface = |
| 478 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( | 481 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( |
| 479 context_provider, compositor->vsync_manager(), | 482 context_provider, vsync_callback, |
| 480 begin_frame_source.get(), | |
| 481 std::unique_ptr< | 483 std::unique_ptr< |
| 482 display_compositor::CompositorOverlayCandidateValidator>()); | 484 display_compositor::CompositorOverlayCandidateValidator>()); |
| 483 } else if (capabilities.surfaceless) { | 485 } else if (capabilities.surfaceless) { |
| 484 #if defined(OS_MACOSX) | 486 #if defined(OS_MACOSX) |
| 485 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( | 487 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( |
| 486 compositor->widget(), context_provider, data->surface_handle, | 488 compositor->widget(), context_provider, data->surface_handle, |
| 487 compositor->vsync_manager(), begin_frame_source.get(), | 489 vsync_callback, |
| 488 CreateOverlayCandidateValidator(compositor->widget()), | 490 CreateOverlayCandidateValidator(compositor->widget()), |
| 489 GetGpuMemoryBufferManager()); | 491 GetGpuMemoryBufferManager()); |
| 490 #else | 492 #else |
| 491 display_output_surface = | 493 display_output_surface = |
| 492 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( | 494 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( |
| 493 context_provider, data->surface_handle, | 495 context_provider, data->surface_handle, vsync_callback, |
| 494 compositor->vsync_manager(), begin_frame_source.get(), | |
| 495 CreateOverlayCandidateValidator(compositor->widget()), | 496 CreateOverlayCandidateValidator(compositor->widget()), |
| 496 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), | 497 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), |
| 497 GetGpuMemoryBufferManager()); | 498 GetGpuMemoryBufferManager()); |
| 498 #endif | 499 #endif |
| 499 } else { | 500 } else { |
| 500 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 501 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| 501 validator; | 502 validator; |
| 502 const bool use_mus = IsUsingMus(); | 503 const bool use_mus = IsUsingMus(); |
| 503 #if !defined(OS_MACOSX) | 504 #if !defined(OS_MACOSX) |
| 504 // Overlays are only supported on surfaceless output surfaces on Mac. | 505 // Overlays are only supported on surfaceless output surfaces on Mac. |
| 505 if (!use_mus) | 506 if (!use_mus) |
| 506 validator = CreateOverlayCandidateValidator(compositor->widget()); | 507 validator = CreateOverlayCandidateValidator(compositor->widget()); |
| 507 #endif | 508 #endif |
| 508 if (!use_mus) { | 509 if (!use_mus) { |
| 509 display_output_surface = | 510 display_output_surface = |
| 510 base::MakeUnique<GpuBrowserCompositorOutputSurface>( | 511 base::MakeUnique<GpuBrowserCompositorOutputSurface>( |
| 511 context_provider, compositor->vsync_manager(), | 512 context_provider, vsync_callback, std::move(validator)); |
| 512 begin_frame_source.get(), std::move(validator)); | |
| 513 } else { | 513 } else { |
| 514 #if defined(USE_AURA) | 514 #if defined(USE_AURA) |
| 515 if (compositor->window()) { | 515 if (compositor->window()) { |
| 516 // TODO(mfomitchev): Remove this clause once we complete the switch | 516 // TODO(mfomitchev): Remove this clause once we complete the switch |
| 517 // to Aura-Mus. | 517 // to Aura-Mus. |
| 518 display_output_surface = | 518 display_output_surface = |
| 519 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 519 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 520 compositor->window(), context_provider, | 520 compositor->window(), context_provider, |
| 521 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 521 GetGpuMemoryBufferManager(), vsync_callback, |
| 522 begin_frame_source.get(), std::move(validator)); | 522 std::move(validator)); |
| 523 } else { | 523 } else { |
| 524 aura::WindowTreeHost* host = | 524 aura::WindowTreeHost* host = |
| 525 aura::WindowTreeHost::GetForAcceleratedWidget( | 525 aura::WindowTreeHost::GetForAcceleratedWidget( |
| 526 compositor->widget()); | 526 compositor->widget()); |
| 527 display_output_surface = | 527 display_output_surface = |
| 528 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 528 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 529 host->window(), context_provider, | 529 host->window(), context_provider, |
| 530 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 530 GetGpuMemoryBufferManager(), vsync_callback, |
| 531 begin_frame_source.get(), std::move(validator)); | 531 std::move(validator)); |
| 532 } | 532 } |
| 533 #else | 533 #else |
| 534 NOTREACHED(); | 534 NOTREACHED(); |
| 535 #endif | 535 #endif |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 data->display_output_surface = display_output_surface.get(); | 541 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) { | 607 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 608 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 608 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 609 if (it == per_compositor_data_.end()) | 609 if (it == per_compositor_data_.end()) |
| 610 return; | 610 return; |
| 611 PerCompositorData* data = it->second.get(); | 611 PerCompositorData* data = it->second.get(); |
| 612 DCHECK(data); | 612 DCHECK(data); |
| 613 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 613 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 614 if (data->surface_handle) | 614 if (data->surface_handle) |
| 615 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 615 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
| 616 #endif | 616 #endif |
| 617 | |
| 617 per_compositor_data_.erase(it); | 618 per_compositor_data_.erase(it); |
| 618 if (per_compositor_data_.empty()) { | 619 if (per_compositor_data_.empty()) { |
| 619 // Destroying the GLHelper may cause some async actions to be cancelled, | 620 // 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 | 621 // 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() | 622 // 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 | 623 // on the |gl_helper_| variable directly. So instead we call reset() on a |
| 623 // local std::unique_ptr. | 624 // local std::unique_ptr. |
| 624 std::unique_ptr<display_compositor::GLHelper> helper = | 625 std::unique_ptr<display_compositor::GLHelper> helper = |
| 625 std::move(gl_helper_); | 626 std::move(gl_helper_); |
| 626 | 627 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 base::TimeDelta interval) { | 721 base::TimeDelta interval) { |
| 721 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 722 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 722 if (it == per_compositor_data_.end()) | 723 if (it == per_compositor_data_.end()) |
| 723 return; | 724 return; |
| 724 PerCompositorData* data = it->second.get(); | 725 PerCompositorData* data = it->second.get(); |
| 725 DCHECK(data); | 726 DCHECK(data); |
| 726 if (data->begin_frame_source) | 727 if (data->begin_frame_source) |
| 727 data->begin_frame_source->OnUpdateVSyncParameters(timebase, interval); | 728 data->begin_frame_source->OnUpdateVSyncParameters(timebase, interval); |
| 728 } | 729 } |
| 729 | 730 |
| 731 void GpuProcessTransportFactory::UpdateVSyncParametersFromGpu( | |
| 732 base::WeakPtr<ui::Compositor> compositor, | |
| 733 base::TimeTicks timebase, | |
| 734 base::TimeDelta interval) { | |
| 735 if (!compositor) | |
| 736 return; | |
| 737 | |
| 738 SetDisplayVSyncParameters(compositor.get(), timebase, interval); | |
|
enne (OOO)
2016/11/29 21:25:03
I think UpdateVSyncParametersFromGPU and SetDispla
stanisc
2016/11/29 21:38:44
I tried binding SetDisplayVSyncParameters directly
| |
| 739 compositor->vsync_manager()->UpdateVSyncParameters(timebase, interval); | |
| 740 } | |
| 741 | |
| 730 void GpuProcessTransportFactory::SetOutputIsSecure(ui::Compositor* compositor, | 742 void GpuProcessTransportFactory::SetOutputIsSecure(ui::Compositor* compositor, |
| 731 bool secure) { | 743 bool secure) { |
| 732 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 744 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 733 if (it == per_compositor_data_.end()) | 745 if (it == per_compositor_data_.end()) |
| 734 return; | 746 return; |
| 735 PerCompositorData* data = it->second.get(); | 747 PerCompositorData* data = it->second.get(); |
| 736 DCHECK(data); | 748 DCHECK(data); |
| 737 data->output_is_secure = secure; | 749 data->output_is_secure = secure; |
| 738 if (data->display) | 750 if (data->display) |
| 739 data->display->SetOutputIsSecure(secure); | 751 data->display->SetOutputIsSecure(secure); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 shared_vulkan_context_provider_ = | 893 shared_vulkan_context_provider_ = |
| 882 cc::VulkanInProcessContextProvider::Create(); | 894 cc::VulkanInProcessContextProvider::Create(); |
| 883 } | 895 } |
| 884 | 896 |
| 885 shared_vulkan_context_provider_initialized_ = true; | 897 shared_vulkan_context_provider_initialized_ = true; |
| 886 } | 898 } |
| 887 return shared_vulkan_context_provider_; | 899 return shared_vulkan_context_provider_; |
| 888 } | 900 } |
| 889 | 901 |
| 890 } // namespace content | 902 } // namespace content |
| OLD | NEW |