| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 #include "ui/ozone/public/overlay_candidates_ozone.h" | 68 #include "ui/ozone/public/overlay_candidates_ozone.h" |
| 69 #include "ui/ozone/public/overlay_manager_ozone.h" | 69 #include "ui/ozone/public/overlay_manager_ozone.h" |
| 70 #include "ui/ozone/public/ozone_platform.h" | 70 #include "ui/ozone/public/ozone_platform.h" |
| 71 #include "ui/ozone/public/ozone_switches.h" | 71 #include "ui/ozone/public/ozone_switches.h" |
| 72 #elif defined(USE_X11) | 72 #elif defined(USE_X11) |
| 73 #include "content/browser/compositor/software_output_device_x11.h" | 73 #include "content/browser/compositor/software_output_device_x11.h" |
| 74 #elif defined(OS_MACOSX) | 74 #elif defined(OS_MACOSX) |
| 75 #include "components/display_compositor/compositor_overlay_candidate_validator_m
ac.h" | 75 #include "components/display_compositor/compositor_overlay_candidate_validator_m
ac.h" |
| 76 #include "content/browser/compositor/software_output_device_mac.h" | 76 #include "content/browser/compositor/software_output_device_mac.h" |
| 77 #include "gpu/config/gpu_driver_bug_workaround_type.h" | 77 #include "gpu/config/gpu_driver_bug_workaround_type.h" |
| 78 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" |
| 78 #include "ui/base/cocoa/remote_layer_api.h" | 79 #include "ui/base/cocoa/remote_layer_api.h" |
| 79 #include "ui/base/ui_base_switches.h" | 80 #include "ui/base/ui_base_switches.h" |
| 80 #elif defined(OS_ANDROID) | 81 #elif defined(OS_ANDROID) |
| 81 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" | 82 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" |
| 82 #endif | 83 #endif |
| 83 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 84 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 84 #include "content/browser/gpu/gpu_surface_tracker.h" | 85 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 85 #endif | 86 #endif |
| 86 | 87 |
| 87 #if defined(ENABLE_VULKAN) | 88 #if defined(ENABLE_VULKAN) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor(); | 271 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor(); |
| 271 } | 272 } |
| 272 | 273 |
| 273 void GpuProcessTransportFactory::CreateOutputSurface( | 274 void GpuProcessTransportFactory::CreateOutputSurface( |
| 274 base::WeakPtr<ui::Compositor> compositor) { | 275 base::WeakPtr<ui::Compositor> compositor) { |
| 275 DCHECK(!!compositor); | 276 DCHECK(!!compositor); |
| 276 PerCompositorData* data = per_compositor_data_[compositor.get()]; | 277 PerCompositorData* data = per_compositor_data_[compositor.get()]; |
| 277 if (!data) { | 278 if (!data) { |
| 278 data = CreatePerCompositorData(compositor.get()); | 279 data = CreatePerCompositorData(compositor.get()); |
| 279 } else { | 280 } else { |
| 280 #if defined(OS_MACOSX) | |
| 281 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | |
| 282 // output_surface_map_ here. | |
| 283 output_surface_map_.Remove(data->surface_handle); | |
| 284 #endif | |
| 285 data->surface = nullptr; | 281 data->surface = nullptr; |
| 286 } | 282 } |
| 287 | 283 |
| 288 #if defined(OS_WIN) | 284 #if defined(OS_WIN) |
| 289 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( | 285 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( |
| 290 compositor->widget()); | 286 compositor->widget()); |
| 291 #endif | 287 #endif |
| 292 | 288 |
| 293 const bool use_vulkan = SharedVulkanContextProvider(); | 289 const bool use_vulkan = SharedVulkanContextProvider(); |
| 294 | 290 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 std::move(gpu_channel_host), data->surface_handle, | 385 std::move(gpu_channel_host), data->surface_handle, |
| 390 shared_worker_context_provider_.get(), | 386 shared_worker_context_provider_.get(), |
| 391 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | 387 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
| 392 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is | 388 // TODO(vadimt): Remove ScopedTracker below once crbug.com/125248 is |
| 393 // fixed. Tracking time in BindToCurrentThread. | 389 // fixed. Tracking time in BindToCurrentThread. |
| 394 tracked_objects::ScopedTracker tracking_profile( | 390 tracked_objects::ScopedTracker tracking_profile( |
| 395 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 391 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 396 "125248" | 392 "125248" |
| 397 " GpuProcessTransportFactory::EstablishedGpuChannel" | 393 " GpuProcessTransportFactory::EstablishedGpuChannel" |
| 398 "::Compositor")); | 394 "::Compositor")); |
| 395 #if defined(OS_MACOSX) |
| 396 // On Mac, GpuCommandBufferMsg_SwapBuffersCompleted must be handled in |
| 397 // a nested message loop during resize. |
| 398 context_provider->SetDefaultTaskRunner( |
| 399 ui::WindowResizeHelperMac::Get()->task_runner()); |
| 400 #endif |
| 399 if (!context_provider->BindToCurrentThread()) | 401 if (!context_provider->BindToCurrentThread()) |
| 400 context_provider = nullptr; | 402 context_provider = nullptr; |
| 401 } | 403 } |
| 402 } | 404 } |
| 403 | 405 |
| 404 bool created_gpu_browser_compositor = | 406 bool created_gpu_browser_compositor = |
| 405 !!context_provider && !!shared_worker_context_provider_; | 407 !!context_provider && !!shared_worker_context_provider_; |
| 406 | 408 |
| 407 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", | 409 UMA_HISTOGRAM_BOOLEAN("Aura.CreatedGpuBrowserCompositor", |
| 408 created_gpu_browser_compositor); | 410 created_gpu_browser_compositor); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 validator = CreateOverlayCandidateValidator(compositor->widget()); | 472 validator = CreateOverlayCandidateValidator(compositor->widget()); |
| 471 #endif | 473 #endif |
| 472 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( | 474 surface = base::WrapUnique(new GpuBrowserCompositorOutputSurface( |
| 473 context_provider, shared_worker_context_provider_, | 475 context_provider, shared_worker_context_provider_, |
| 474 compositor->vsync_manager(), compositor->task_runner().get(), | 476 compositor->vsync_manager(), compositor->task_runner().get(), |
| 475 std::move(validator))); | 477 std::move(validator))); |
| 476 } | 478 } |
| 477 } | 479 } |
| 478 } | 480 } |
| 479 | 481 |
| 480 #if defined(OS_MACOSX) | |
| 481 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | |
| 482 // output_surface_map_ here. | |
| 483 output_surface_map_.AddWithID(surface.get(), data->surface_handle); | |
| 484 #endif | |
| 485 data->surface = surface.get(); | 482 data->surface = surface.get(); |
| 486 if (data->reflector) | 483 if (data->reflector) |
| 487 data->reflector->OnSourceSurfaceReady(data->surface); | 484 data->reflector->OnSourceSurfaceReady(data->surface); |
| 488 | 485 |
| 489 #if defined(OS_WIN) | 486 #if defined(OS_WIN) |
| 490 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( | 487 gfx::RenderingWindowManager::GetInstance()->DoSetParentOnChild( |
| 491 compositor->widget()); | 488 compositor->widget()); |
| 492 #endif | 489 #endif |
| 493 | 490 |
| 494 // This gets a bit confusing. Here we have a ContextProvider in the |surface| | 491 // This gets a bit confusing. Here we have a ContextProvider in the |surface| |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 data->reflector->Shutdown(); | 538 data->reflector->Shutdown(); |
| 542 data->reflector = nullptr; | 539 data->reflector = nullptr; |
| 543 } | 540 } |
| 544 | 541 |
| 545 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { | 542 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 546 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 543 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 547 if (it == per_compositor_data_.end()) | 544 if (it == per_compositor_data_.end()) |
| 548 return; | 545 return; |
| 549 PerCompositorData* data = it->second; | 546 PerCompositorData* data = it->second; |
| 550 DCHECK(data); | 547 DCHECK(data); |
| 551 #if defined(OS_MACOSX) | |
| 552 // TODO(piman): Use GpuSurfaceTracker to map ids to surfaces instead of an | |
| 553 // output_surface_map_ here. | |
| 554 if (data->surface) | |
| 555 output_surface_map_.Remove(data->surface_handle); | |
| 556 #endif | |
| 557 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 548 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 558 if (data->surface_handle) | 549 if (data->surface_handle) |
| 559 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 550 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
| 560 #endif | 551 #endif |
| 561 delete data; | 552 delete data; |
| 562 per_compositor_data_.erase(it); | 553 per_compositor_data_.erase(it); |
| 563 if (per_compositor_data_.empty()) { | 554 if (per_compositor_data_.empty()) { |
| 564 // Destroying the GLHelper may cause some async actions to be cancelled, | 555 // Destroying the GLHelper may cause some async actions to be cancelled, |
| 565 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 556 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
| 566 // GLHelper created in this case would be lost/leaked if we just reset() | 557 // GLHelper created in this case would be lost/leaked if we just reset() |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 ui::Compositor* compositor, | 664 ui::Compositor* compositor, |
| 674 bool suspended) { | 665 bool suspended) { |
| 675 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 666 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 676 if (it == per_compositor_data_.end()) | 667 if (it == per_compositor_data_.end()) |
| 677 return; | 668 return; |
| 678 PerCompositorData* data = it->second; | 669 PerCompositorData* data = it->second; |
| 679 DCHECK(data); | 670 DCHECK(data); |
| 680 if (data->surface) | 671 if (data->surface) |
| 681 data->surface->SetSurfaceSuspendedForRecycle(suspended); | 672 data->surface->SetSurfaceSuspendedForRecycle(suspended); |
| 682 } | 673 } |
| 683 | |
| 684 bool GpuProcessTransportFactory:: | |
| 685 SurfaceShouldNotShowFramesAfterSuspendForRecycle( | |
| 686 gpu::SurfaceHandle surface_handle) const { | |
| 687 BrowserCompositorOutputSurface* surface = | |
| 688 output_surface_map_.Lookup(surface_handle); | |
| 689 if (surface) | |
| 690 return surface->SurfaceShouldNotShowFramesAfterSuspendForRecycle(); | |
| 691 return false; | |
| 692 } | |
| 693 #endif | 674 #endif |
| 694 | 675 |
| 695 scoped_refptr<cc::ContextProvider> | 676 scoped_refptr<cc::ContextProvider> |
| 696 GpuProcessTransportFactory::SharedMainThreadContextProvider() { | 677 GpuProcessTransportFactory::SharedMainThreadContextProvider() { |
| 697 if (shared_main_thread_contexts_) | 678 if (shared_main_thread_contexts_) |
| 698 return shared_main_thread_contexts_; | 679 return shared_main_thread_contexts_; |
| 699 | 680 |
| 700 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) | 681 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) |
| 701 return nullptr; | 682 return nullptr; |
| 702 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 683 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 shared_vulkan_context_provider_ = | 767 shared_vulkan_context_provider_ = |
| 787 cc::VulkanInProcessContextProvider::Create(); | 768 cc::VulkanInProcessContextProvider::Create(); |
| 788 } | 769 } |
| 789 | 770 |
| 790 shared_vulkan_context_provider_initialized_ = true; | 771 shared_vulkan_context_provider_initialized_ = true; |
| 791 } | 772 } |
| 792 return shared_vulkan_context_provider_; | 773 return shared_vulkan_context_provider_; |
| 793 } | 774 } |
| 794 | 775 |
| 795 } // namespace content | 776 } // namespace content |
| OLD | NEW |