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 if (!compositor) | |
danakj
2016/11/30 23:49:05
How does the compositor be gone but the output sur
stanisc
2016/12/01 00:16:27
Honestly I don't know. Why was it WeakPtr<Composit
danakj
2016/12/01 00:26:34
EstablishedGpuChannel is called from the GpuChanne
stanisc
2016/12/02 19:50:43
OK, I've replaced this with a DCHECK. I think I st
| |
164 return; | |
165 | |
166 compositor->SetDisplayVSyncParameters(timebase, interval); | |
167 } | |
168 | |
160 } // namespace | 169 } // namespace |
161 | 170 |
162 namespace content { | 171 namespace content { |
163 | 172 |
164 struct GpuProcessTransportFactory::PerCompositorData { | 173 struct GpuProcessTransportFactory::PerCompositorData { |
165 gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; | 174 gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; |
166 BrowserCompositorOutputSurface* display_output_surface = nullptr; | 175 BrowserCompositorOutputSurface* display_output_surface = nullptr; |
167 cc::SyntheticBeginFrameSource* begin_frame_source = nullptr; | 176 cc::SyntheticBeginFrameSource* begin_frame_source = nullptr; |
168 ReflectorImpl* reflector = nullptr; | 177 ReflectorImpl* reflector = nullptr; |
169 std::unique_ptr<cc::Display> display; | 178 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) { | 449 if (!compositor->GetRendererSettings().disable_display_vsync) { |
441 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( | 450 begin_frame_source.reset(new cc::DelayBasedBeginFrameSource( |
442 base::MakeUnique<cc::DelayBasedTimeSource>( | 451 base::MakeUnique<cc::DelayBasedTimeSource>( |
443 compositor->task_runner().get()))); | 452 compositor->task_runner().get()))); |
444 } else { | 453 } else { |
445 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( | 454 begin_frame_source.reset(new cc::BackToBackBeginFrameSource( |
446 base::MakeUnique<cc::DelayBasedTimeSource>( | 455 base::MakeUnique<cc::DelayBasedTimeSource>( |
447 compositor->task_runner().get()))); | 456 compositor->task_runner().get()))); |
448 } | 457 } |
449 | 458 |
459 BrowserCompositorOutputSurface::UpdateVSyncParametersCallback vsync_callback = | |
460 base::Bind(&UpdateVSyncParameters, compositor); | |
461 | |
450 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; | 462 std::unique_ptr<BrowserCompositorOutputSurface> display_output_surface; |
451 #if defined(ENABLE_VULKAN) | 463 #if defined(ENABLE_VULKAN) |
452 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; | 464 std::unique_ptr<VulkanBrowserCompositorOutputSurface> vulkan_surface; |
453 if (vulkan_context_provider) { | 465 if (vulkan_context_provider) { |
454 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( | 466 vulkan_surface.reset(new VulkanBrowserCompositorOutputSurface( |
455 vulkan_context_provider, compositor->vsync_manager(), | 467 vulkan_context_provider, vsync_callback)); |
456 begin_frame_source.get())); | |
457 if (!vulkan_surface->Initialize(compositor.get()->widget())) { | 468 if (!vulkan_surface->Initialize(compositor.get()->widget())) { |
458 vulkan_surface->Destroy(); | 469 vulkan_surface->Destroy(); |
459 vulkan_surface.reset(); | 470 vulkan_surface.reset(); |
460 } else { | 471 } else { |
461 display_output_surface = std::move(vulkan_surface); | 472 display_output_surface = std::move(vulkan_surface); |
462 } | 473 } |
463 } | 474 } |
464 #endif | 475 #endif |
465 | 476 |
466 if (!display_output_surface) { | 477 if (!display_output_surface) { |
467 if (!create_gpu_output_surface) { | 478 if (!create_gpu_output_surface) { |
468 display_output_surface = | 479 display_output_surface = |
469 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( | 480 base::MakeUnique<SoftwareBrowserCompositorOutputSurface>( |
470 CreateSoftwareOutputDevice(compositor.get()), | 481 CreateSoftwareOutputDevice(compositor.get()), vsync_callback, |
471 compositor->vsync_manager(), begin_frame_source.get(), | |
472 compositor->task_runner()); | 482 compositor->task_runner()); |
473 } else { | 483 } else { |
474 DCHECK(context_provider); | 484 DCHECK(context_provider); |
475 const auto& capabilities = context_provider->ContextCapabilities(); | 485 const auto& capabilities = context_provider->ContextCapabilities(); |
476 if (data->surface_handle == gpu::kNullSurfaceHandle) { | 486 if (data->surface_handle == gpu::kNullSurfaceHandle) { |
477 display_output_surface = | 487 display_output_surface = |
478 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( | 488 base::MakeUnique<OffscreenBrowserCompositorOutputSurface>( |
479 context_provider, compositor->vsync_manager(), | 489 context_provider, vsync_callback, |
480 begin_frame_source.get(), | |
481 std::unique_ptr< | 490 std::unique_ptr< |
482 display_compositor::CompositorOverlayCandidateValidator>()); | 491 display_compositor::CompositorOverlayCandidateValidator>()); |
483 } else if (capabilities.surfaceless) { | 492 } else if (capabilities.surfaceless) { |
484 #if defined(OS_MACOSX) | 493 #if defined(OS_MACOSX) |
485 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( | 494 display_output_surface = base::MakeUnique<GpuOutputSurfaceMac>( |
486 compositor->widget(), context_provider, data->surface_handle, | 495 compositor->widget(), context_provider, data->surface_handle, |
487 compositor->vsync_manager(), begin_frame_source.get(), | 496 vsync_callback, |
488 CreateOverlayCandidateValidator(compositor->widget()), | 497 CreateOverlayCandidateValidator(compositor->widget()), |
489 GetGpuMemoryBufferManager()); | 498 GetGpuMemoryBufferManager()); |
490 #else | 499 #else |
491 display_output_surface = | 500 display_output_surface = |
492 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( | 501 base::MakeUnique<GpuSurfacelessBrowserCompositorOutputSurface>( |
493 context_provider, data->surface_handle, | 502 context_provider, data->surface_handle, vsync_callback, |
494 compositor->vsync_manager(), begin_frame_source.get(), | |
495 CreateOverlayCandidateValidator(compositor->widget()), | 503 CreateOverlayCandidateValidator(compositor->widget()), |
496 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), | 504 GL_TEXTURE_2D, GL_RGB, ui::DisplaySnapshot::PrimaryFormat(), |
497 GetGpuMemoryBufferManager()); | 505 GetGpuMemoryBufferManager()); |
498 #endif | 506 #endif |
499 } else { | 507 } else { |
500 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> | 508 std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> |
501 validator; | 509 validator; |
502 const bool use_mus = IsUsingMus(); | 510 const bool use_mus = IsUsingMus(); |
503 #if !defined(OS_MACOSX) | 511 #if !defined(OS_MACOSX) |
504 // Overlays are only supported on surfaceless output surfaces on Mac. | 512 // Overlays are only supported on surfaceless output surfaces on Mac. |
505 if (!use_mus) | 513 if (!use_mus) |
506 validator = CreateOverlayCandidateValidator(compositor->widget()); | 514 validator = CreateOverlayCandidateValidator(compositor->widget()); |
507 #endif | 515 #endif |
508 if (!use_mus) { | 516 if (!use_mus) { |
509 display_output_surface = | 517 display_output_surface = |
510 base::MakeUnique<GpuBrowserCompositorOutputSurface>( | 518 base::MakeUnique<GpuBrowserCompositorOutputSurface>( |
511 context_provider, compositor->vsync_manager(), | 519 context_provider, vsync_callback, std::move(validator)); |
512 begin_frame_source.get(), std::move(validator)); | |
513 } else { | 520 } else { |
514 #if defined(USE_AURA) | 521 #if defined(USE_AURA) |
515 if (compositor->window()) { | 522 if (compositor->window()) { |
516 // TODO(mfomitchev): Remove this clause once we complete the switch | 523 // TODO(mfomitchev): Remove this clause once we complete the switch |
517 // to Aura-Mus. | 524 // to Aura-Mus. |
518 display_output_surface = | 525 display_output_surface = |
519 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 526 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
520 compositor->window(), context_provider, | 527 compositor->window(), context_provider, |
521 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 528 GetGpuMemoryBufferManager(), vsync_callback, |
522 begin_frame_source.get(), std::move(validator)); | 529 std::move(validator)); |
523 } else { | 530 } else { |
524 aura::WindowTreeHost* host = | 531 aura::WindowTreeHost* host = |
525 aura::WindowTreeHost::GetForAcceleratedWidget( | 532 aura::WindowTreeHost::GetForAcceleratedWidget( |
526 compositor->widget()); | 533 compositor->widget()); |
527 display_output_surface = | 534 display_output_surface = |
528 base::MakeUnique<MusBrowserCompositorOutputSurface>( | 535 base::MakeUnique<MusBrowserCompositorOutputSurface>( |
529 host->window(), context_provider, | 536 host->window(), context_provider, |
530 GetGpuMemoryBufferManager(), compositor->vsync_manager(), | 537 GetGpuMemoryBufferManager(), vsync_callback, |
531 begin_frame_source.get(), std::move(validator)); | 538 std::move(validator)); |
532 } | 539 } |
533 #else | 540 #else |
534 NOTREACHED(); | 541 NOTREACHED(); |
535 #endif | 542 #endif |
536 } | 543 } |
537 } | 544 } |
538 } | 545 } |
539 } | 546 } |
540 | 547 |
541 data->display_output_surface = display_output_surface.get(); | 548 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) { | 614 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
608 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 615 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
609 if (it == per_compositor_data_.end()) | 616 if (it == per_compositor_data_.end()) |
610 return; | 617 return; |
611 PerCompositorData* data = it->second.get(); | 618 PerCompositorData* data = it->second.get(); |
612 DCHECK(data); | 619 DCHECK(data); |
613 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 620 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
614 if (data->surface_handle) | 621 if (data->surface_handle) |
615 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 622 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
616 #endif | 623 #endif |
624 | |
617 per_compositor_data_.erase(it); | 625 per_compositor_data_.erase(it); |
618 if (per_compositor_data_.empty()) { | 626 if (per_compositor_data_.empty()) { |
619 // Destroying the GLHelper may cause some async actions to be cancelled, | 627 // 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 | 628 // 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() | 629 // 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 | 630 // on the |gl_helper_| variable directly. So instead we call reset() on a |
623 // local std::unique_ptr. | 631 // local std::unique_ptr. |
624 std::unique_ptr<display_compositor::GLHelper> helper = | 632 std::unique_ptr<display_compositor::GLHelper> helper = |
625 std::move(gl_helper_); | 633 std::move(gl_helper_); |
626 | 634 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 shared_vulkan_context_provider_ = | 889 shared_vulkan_context_provider_ = |
882 cc::VulkanInProcessContextProvider::Create(); | 890 cc::VulkanInProcessContextProvider::Create(); |
883 } | 891 } |
884 | 892 |
885 shared_vulkan_context_provider_initialized_ = true; | 893 shared_vulkan_context_provider_initialized_ = true; |
886 } | 894 } |
887 return shared_vulkan_context_provider_; | 895 return shared_vulkan_context_provider_; |
888 } | 896 } |
889 | 897 |
890 } // namespace content | 898 } // namespace content |
OLD | NEW |