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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor(); | 276 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void GpuProcessTransportFactory::CreateCompositorFrameSink( | 279 void GpuProcessTransportFactory::CreateCompositorFrameSink( |
| 280 base::WeakPtr<ui::Compositor> compositor) { | 280 base::WeakPtr<ui::Compositor> compositor) { |
| 281 DCHECK(!!compositor); | 281 DCHECK(!!compositor); |
| 282 PerCompositorData* data = per_compositor_data_[compositor.get()].get(); | 282 PerCompositorData* data = per_compositor_data_[compositor.get()].get(); |
| 283 if (!data) { | 283 if (!data) { |
| 284 data = CreatePerCompositorData(compositor.get()); | 284 data = CreatePerCompositorData(compositor.get()); |
| 285 } else { | 285 } else { |
| 286 // TODO: is this the right place to remove data->begin_frame_source from | |
| 287 // the compositor VSync manager? | |
| 288 if (data->begin_frame_source) | |
| 289 compositor->vsync_manager()->RemoveObserver(data->begin_frame_source); | |
| 290 | |
| 286 // TODO(danakj): We can destroy the |data->display| here when the compositor | 291 // TODO(danakj): We can destroy the |data->display| here when the compositor |
| 287 // destroys its CompositorFrameSink before calling back here. | 292 // destroys its CompositorFrameSink before calling back here. |
| 288 data->display_output_surface = nullptr; | 293 data->display_output_surface = nullptr; |
| 289 data->begin_frame_source = nullptr; | 294 data->begin_frame_source = nullptr; |
| 290 } | 295 } |
| 291 | 296 |
| 292 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
| 293 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( | 298 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( |
| 294 compositor->widget()); | 299 compositor->widget()); |
| 295 #endif | 300 #endif |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 if (!compositor->GetRendererSettings().disable_display_vsync) { | 445 if (!compositor->GetRendererSettings().disable_display_vsync) { |
| 441 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 446 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
| 442 base::MakeUnique<cc::DelayBasedTimeSource>( | 447 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 443 compositor->task_runner().get()))); | 448 compositor->task_runner().get()))); |
| 444 } else { | 449 } else { |
| 445 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( | 450 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( |
| 446 base::MakeUnique<cc::DelayBasedTimeSource>( | 451 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 447 compositor->task_runner().get()))); | 452 compositor->task_runner().get()))); |
| 448 } | 453 } |
| 449 | 454 |
| 455 compositor->vsync_manager()->AddObserver(begin_frame_source.get()); | |
|
danakj
2016/11/21 22:32:11
I think there are at least 3 ways to do this:
1.
stanisc
2016/11/21 22:52:31
Thanks for the suggestion! The idea was that a new
danakj
2016/11/21 23:06:36
Ok so one problem with this approach is that we're
stanisc
2016/11/22 19:55:43
How about passing a pointer to VSyncObserver to Br
| |
| 456 | |
| 450 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; | 457 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; |
| 451 #if defined(ENABLE_VULKAN) | 458 #if defined(ENABLE_VULKAN) |
| 452 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | 459 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
| 453 if (vulkan_context_provider) { | 460 if (vulkan_context_provider) { |
| 454 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | 461 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
| 455 vulkan_context_provider, compositor->vsync_manager(), | 462 vulkan_context_provider, compositor->vsync_manager())); |
| 456 begin_frame_source.get())); | |
| 457 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | 463 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
| 458 vulkan_surface->Destroy(); | 464 vulkan_surface->Destroy(); |
| 459 vulkan_surface.reset(); | 465 vulkan_surface.reset(); |
| 460 } else { | 466 } else { |
| 461 display_output_surface = std::move(vulkan_surface); | 467 display_output_surface = std::move(vulkan_surface); |
| 462 } | 468 } |
| 463 } | 469 } |
| 464 #endif | 470 #endif |
| 465 | 471 |
| 466 if (!display_output_surface) { | 472 if (!display_output_surface) { |
| 467 if (!create_gpu_output_surface) { | 473 if (!create_gpu_output_surface) { |
| 468 display_output_surface = | 474 display_output_surface = |
| 469 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( | 475 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( |
| 470 CreateSoftwareOutputDevice(compositor.get()), | 476 CreateSoftwareOutputDevice(compositor.get()), |
| 471 compositor->vsync_manager(), begin_frame_source.get(), | 477 compositor->vsync_manager(), compositor->task_runner()); |
| 472 compositor->task_runner()); | |
| 473 } else { | 478 } else { |
| 474 DCHECK(context_provider); | 479 DCHECK(context_provider); |
| 475 const auto& capabilities = context_provider->ContextCapabilities(); | 480 const auto& capabilities = context_provider->ContextCapabilities(); |
| 476 if (data->surface_handle == gpu::kNullSurfaceHandle) { | 481 if (data->surface_handle == gpu::kNullSurfaceHandle) { |
| 477 display_output_surface = | 482 display_output_surface = |
| 478 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( | 483 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( |
| 479 context_provider, compositor->vsync_manager(), | 484 context_provider, compositor->vsync_manager(), |
| 480 begin_frame_source.get(), | |
| 481 std::unique_ptr< | 485 std::unique_ptr< |
| 482 display_compositor::CompositorOverlayCandidateValidator>()); | 486 display_compositor::CompositorOverlayCandidateValidator>()); |
| 483 } else if (capabilities.surfaceless) { | 487 } else if (capabilities.surfaceless) { |
| 484 #if defined(OS_MACOSX) | 488 #if defined(OS_MACOSX) |
| 485 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( | 489 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( |
| 486 compositor->widget(), context_provider, data->surface_handle, | 490 compositor->widget(), context_provider, data->surface_handle, |
| 487 compositor->vsync_manager(), begin_frame_source.get(), | 491 compositor->vsync_manager(), |
| 488 CreateOverlayCandidateValidator(compositor->widget()), | 492 CreateOverlayCandidateValidator(compositor->widget()), |
| 489 GetGpuMemoryBufferManager()); | 493 GetGpuMemoryBufferManager()); |
| 490 #else | 494 #else |
| 491 display_output_surface = | 495 display_output_surface = |
| 492 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( | 496 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( |
| 493 context_provider, data->surface_handle, | 497 context_provider, data->surface_handle, |
| 494 compositor->vsync_manager(), begin_frame_source.get(), | 498 compositor->vsync_manager(), |
| 495 CreateOverlayCandidateValidator(compositor->widget()), | 499 CreateOverlayCandidateValidator(compositor->widget()), |
| 496 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), | 500 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), |
| 497 GetGpuMemoryBufferManager()); | 501 GetGpuMemoryBufferManager()); |
| 498 #endif | 502 #endif |
| 499 } else { | 503 } else { |
| 500 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 504 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
| 501 validator; | 505 validator; |
| 502 const bool use_mus = IsUsingMus(); | 506 const bool use_mus = IsUsingMus(); |
| 503 #if !defined(OS_MACOSX) | 507 #if !defined(OS_MACOSX) |
| 504 // Overlays are only supported on surfaceless output surfaces on Mac. | 508 // Overlays are only supported on surfaceless output surfaces on Mac. |
| 505 if (!use_mus) | 509 if (!use_mus) |
| 506 validator = CreateOverlayCandidateValidator(compositor->widget()); | 510 validator = CreateOverlayCandidateValidator(compositor->widget()); |
| 507 #endif | 511 #endif |
| 508 if (!use_mus) { | 512 if (!use_mus) { |
| 509 display_output_surface = | 513 display_output_surface = |
| 510 base::MakeUnique<GpuBrowserCompositorOutputSurface>( | 514 base::MakeUnique<GpuBrowserCompositorOutputSurface>( |
| 511 context_provider, compositor->vsync_manager(), | 515 context_provider, compositor->vsync_manager(), |
| 512 begin_frame_source.get(), std::move(validator)); | 516 std::move(validator)); |
| 513 } else { | 517 } else { |
| 514 #if defined(USE_AURA) | 518 #if defined(USE_AURA) |
| 515 if (compositor->window()) { | 519 if (compositor->window()) { |
| 516 // TODO(mfomitchev): Remove this clause once we complete the switch | 520 // TODO(mfomitchev): Remove this clause once we complete the switch |
| 517 // to Aura-Mus. | 521 // to Aura-Mus. |
| 518 display_output_surface = | 522 display_output_surface = |
| 519 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 523 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 520 compositor->window(), context_provider, | 524 compositor->window(), context_provider, |
| 521 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 525 GetGpuMemoryBufferManager(), compositor->vsync_manager(), |
| 522 begin_frame_source.get(), std::move(validator)); | 526 std::move(validator)); |
| 523 } else { | 527 } else { |
| 524 aura::WindowTreeHost* host = | 528 aura::WindowTreeHost* host = |
| 525 aura::WindowTreeHost::GetForAcceleratedWidget( | 529 aura::WindowTreeHost::GetForAcceleratedWidget( |
| 526 compositor->widget()); | 530 compositor->widget()); |
| 527 display_output_surface = | 531 display_output_surface = |
| 528 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 532 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
| 529 host->window(), context_provider, | 533 host->window(), context_provider, |
| 530 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 534 GetGpuMemoryBufferManager(), compositor->vsync_manager(), |
| 531 begin_frame_source.get(), std::move(validator)); | 535 std::move(validator)); |
| 532 } | 536 } |
| 533 #else | 537 #else |
| 534 NOTREACHED(); | 538 NOTREACHED(); |
| 535 #endif | 539 #endif |
| 536 } | 540 } |
| 537 } | 541 } |
| 538 } | 542 } |
| 539 } | 543 } |
| 540 | 544 |
| 541 data->display_output_surface = display_output_surface.get(); | 545 data->display_output_surface = display_output_surface.get(); |
| 546 // TODO: is this still needed? | |
| 542 data->begin_frame_source = begin_frame_source.get(); | 547 data->begin_frame_source = begin_frame_source.get(); |
| 543 if (data->reflector) | 548 if (data->reflector) |
| 544 data->reflector->OnSourceSurfaceReady(data->display_output_surface); | 549 data->reflector->OnSourceSurfaceReady(data->display_output_surface); |
| 545 | 550 |
| 546 #if defined(OS_WIN) | 551 #if defined(OS_WIN) |
| 547 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( | 552 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( |
| 548 compositor->widget()); | 553 compositor->widget()); |
| 549 #endif | 554 #endif |
| 550 | 555 |
| 551 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 556 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| (...skipping 55 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 | |
| 623 // TODO: is this the right place to remove data->begin_frame_source from | |
| 624 // the compositor VSync manager? | |
| 625 if (data->begin_frame_source) | |
| 626 compositor->vsync_manager()->RemoveObserver(data->begin_frame_source); | |
| 627 | |
| 617 per_compositor_data_.erase(it); | 628 per_compositor_data_.erase(it); |
| 618 if (per_compositor_data_.empty()) { | 629 if (per_compositor_data_.empty()) { |
| 619 // Destroying the GLHelper may cause some async actions to be cancelled, | 630 // 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 | 631 // 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() | 632 // 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 | 633 // on the |gl_helper_| variable directly. So instead we call reset() on a |
| 623 // local std::unique_ptr. | 634 // local std::unique_ptr. |
| 624 std::unique_ptr<display_compositor::GLHelper> helper = | 635 std::unique_ptr<display_compositor::GLHelper> helper = |
| 625 std::move(gl_helper_); | 636 std::move(gl_helper_); |
| 626 | 637 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 shared_vulkan_context_provider_ = | 892 shared_vulkan_context_provider_ = |
| 882 cc::VulkanInProcessContextProvider::Create(); | 893 cc::VulkanInProcessContextProvider::Create(); |
| 883 } | 894 } |
| 884 | 895 |
| 885 shared_vulkan_context_provider_initialized_ = true; | 896 shared_vulkan_context_provider_initialized_ = true; |
| 886 } | 897 } |
| 887 return shared_vulkan_context_provider_; | 898 return shared_vulkan_context_provider_; |
| 888 } | 899 } |
| 889 | 900 |
| 890 } // namespace content | 901 } // namespace content |
| OLD | NEW |