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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/threading/simple_thread.h" | 16 #include "base/threading/simple_thread.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "cc/base/histograms.h" | 19 #include "cc/base/histograms.h" |
20 #include "cc/output/compositor_frame.h" | 20 #include "cc/output/compositor_frame.h" |
21 #include "cc/output/output_surface.h" | 21 #include "cc/output/output_surface.h" |
22 #include "cc/output/vulkan_in_process_context_provider.h" | 22 #include "cc/output/vulkan_in_process_context_provider.h" |
23 #include "cc/raster/single_thread_task_graph_runner.h" | 23 #include "cc/raster/single_thread_task_graph_runner.h" |
24 #include "cc/raster/task_graph_runner.h" | 24 #include "cc/raster/task_graph_runner.h" |
25 #include "cc/surfaces/onscreen_display_client.h" | 25 #include "cc/surfaces/onscreen_display_client.h" |
26 #include "cc/surfaces/surface_display_output_surface.h" | 26 #include "cc/surfaces/surface_display_output_surface.h" |
27 #include "cc/surfaces/surface_manager.h" | 27 #include "cc/surfaces/surface_manager.h" |
28 #include "components/display_compositor/gl_helper.h" | |
29 #include "content/browser/compositor/browser_compositor_output_surface.h" | 28 #include "content/browser/compositor/browser_compositor_output_surface.h" |
30 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" | 29 #include "content/browser/compositor/browser_compositor_overlay_candidate_valida
tor.h" |
| 30 #include "content/browser/compositor/gl_helper.h" |
31 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 31 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
32 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" | 32 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" |
33 #include "content/browser/compositor/offscreen_browser_compositor_output_surface
.h" | 33 #include "content/browser/compositor/offscreen_browser_compositor_output_surface
.h" |
34 #include "content/browser/compositor/reflector_impl.h" | 34 #include "content/browser/compositor/reflector_impl.h" |
35 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" | 35 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" |
36 #include "content/browser/compositor/software_output_device_mus.h" | 36 #include "content/browser/compositor/software_output_device_mus.h" |
37 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 37 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
38 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 38 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
39 #include "content/browser/gpu/gpu_data_manager_impl.h" | 39 #include "content/browser/gpu/gpu_data_manager_impl.h" |
40 #include "content/browser/gpu/gpu_surface_tracker.h" | 40 #include "content/browser/gpu/gpu_surface_tracker.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 if (data->surface_id) | 513 if (data->surface_id) |
514 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); | 514 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_id); |
515 delete data; | 515 delete data; |
516 per_compositor_data_.erase(it); | 516 per_compositor_data_.erase(it); |
517 if (per_compositor_data_.empty()) { | 517 if (per_compositor_data_.empty()) { |
518 // Destroying the GLHelper may cause some async actions to be cancelled, | 518 // Destroying the GLHelper may cause some async actions to be cancelled, |
519 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 519 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
520 // GLHelper created in this case would be lost/leaked if we just reset() | 520 // GLHelper created in this case would be lost/leaked if we just reset() |
521 // on the |gl_helper_| variable directly. So instead we call reset() on a | 521 // on the |gl_helper_| variable directly. So instead we call reset() on a |
522 // local std::unique_ptr. | 522 // local std::unique_ptr. |
523 std::unique_ptr<display_compositor::GLHelper> helper = | 523 std::unique_ptr<GLHelper> helper = std::move(gl_helper_); |
524 std::move(gl_helper_); | |
525 | 524 |
526 // If there are any observer left at this point, make sure they clean up | 525 // If there are any observer left at this point, make sure they clean up |
527 // before we destroy the GLHelper. | 526 // before we destroy the GLHelper. |
528 FOR_EACH_OBSERVER( | 527 FOR_EACH_OBSERVER( |
529 ImageTransportFactoryObserver, observer_list_, OnLostResources()); | 528 ImageTransportFactoryObserver, observer_list_, OnLostResources()); |
530 | 529 |
531 helper.reset(); | 530 helper.reset(); |
532 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " | 531 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " |
533 "GLHelper to be created."; | 532 "GLHelper to be created."; |
534 } | 533 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 PerCompositorData* data = it->second; | 579 PerCompositorData* data = it->second; |
581 DCHECK(data); | 580 DCHECK(data); |
582 if (data->display_client) | 581 if (data->display_client) |
583 data->display_client->display()->Resize(size); | 582 data->display_client->display()->Resize(size); |
584 } | 583 } |
585 | 584 |
586 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { | 585 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { |
587 return surface_manager_.get(); | 586 return surface_manager_.get(); |
588 } | 587 } |
589 | 588 |
590 display_compositor::GLHelper* GpuProcessTransportFactory::GetGLHelper() { | 589 GLHelper* GpuProcessTransportFactory::GetGLHelper() { |
591 if (!gl_helper_ && !per_compositor_data_.empty()) { | 590 if (!gl_helper_ && !per_compositor_data_.empty()) { |
592 scoped_refptr<cc::ContextProvider> provider = | 591 scoped_refptr<cc::ContextProvider> provider = |
593 SharedMainThreadContextProvider(); | 592 SharedMainThreadContextProvider(); |
594 if (provider.get()) | 593 if (provider.get()) |
595 gl_helper_.reset(new display_compositor::GLHelper( | 594 gl_helper_.reset(new GLHelper(provider->ContextGL(), |
596 provider->ContextGL(), provider->ContextSupport())); | 595 provider->ContextSupport())); |
597 } | 596 } |
598 return gl_helper_.get(); | 597 return gl_helper_.get(); |
599 } | 598 } |
600 | 599 |
601 void GpuProcessTransportFactory::AddObserver( | 600 void GpuProcessTransportFactory::AddObserver( |
602 ImageTransportFactoryObserver* observer) { | 601 ImageTransportFactoryObserver* observer) { |
603 observer_list_.AddObserver(observer); | 602 observer_list_.AddObserver(observer); |
604 } | 603 } |
605 | 604 |
606 void GpuProcessTransportFactory::RemoveObserver( | 605 void GpuProcessTransportFactory::RemoveObserver( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 LOG(ERROR) << "Lost UI shared context."; | 702 LOG(ERROR) << "Lost UI shared context."; |
704 | 703 |
705 // Keep old resources around while we call the observers, but ensure that | 704 // Keep old resources around while we call the observers, but ensure that |
706 // new resources are created if needed. | 705 // new resources are created if needed. |
707 // Kill shared contexts for both threads in tandem so they are always in | 706 // Kill shared contexts for both threads in tandem so they are always in |
708 // the same share group. | 707 // the same share group. |
709 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = | 708 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = |
710 shared_main_thread_contexts_; | 709 shared_main_thread_contexts_; |
711 shared_main_thread_contexts_ = NULL; | 710 shared_main_thread_contexts_ = NULL; |
712 | 711 |
713 std::unique_ptr<display_compositor::GLHelper> lost_gl_helper = | 712 std::unique_ptr<GLHelper> lost_gl_helper = std::move(gl_helper_); |
714 std::move(gl_helper_); | |
715 | 713 |
716 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 714 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, |
717 observer_list_, | 715 observer_list_, |
718 OnLostResources()); | 716 OnLostResources()); |
719 | 717 |
720 // Kill things that use the shared context before killing the shared context. | 718 // Kill things that use the shared context before killing the shared context. |
721 lost_gl_helper.reset(); | 719 lost_gl_helper.reset(); |
722 lost_shared_main_thread_contexts = NULL; | 720 lost_shared_main_thread_contexts = NULL; |
723 } | 721 } |
724 | 722 |
725 scoped_refptr<cc::VulkanInProcessContextProvider> | 723 scoped_refptr<cc::VulkanInProcessContextProvider> |
726 GpuProcessTransportFactory::SharedVulkanContextProvider() { | 724 GpuProcessTransportFactory::SharedVulkanContextProvider() { |
727 if (!shared_vulkan_context_provider_initialized_) { | 725 if (!shared_vulkan_context_provider_initialized_) { |
728 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 726 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
729 switches::kEnableVulkan)) { | 727 switches::kEnableVulkan)) { |
730 shared_vulkan_context_provider_ = | 728 shared_vulkan_context_provider_ = |
731 cc::VulkanInProcessContextProvider::Create(); | 729 cc::VulkanInProcessContextProvider::Create(); |
732 } | 730 } |
733 | 731 |
734 shared_vulkan_context_provider_initialized_ = true; | 732 shared_vulkan_context_provider_initialized_ = true; |
735 } | 733 } |
736 return shared_vulkan_context_provider_; | 734 return shared_vulkan_context_provider_; |
737 } | 735 } |
738 | 736 |
739 } // namespace content | 737 } // namespace content |
OLD | NEW |