| 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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 // Destroying the GLHelper may cause some async actions to be cancelled, | 582 // Destroying the GLHelper may cause some async actions to be cancelled, |
| 583 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 583 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
| 584 // GLHelper created in this case would be lost/leaked if we just reset() | 584 // GLHelper created in this case would be lost/leaked if we just reset() |
| 585 // on the |gl_helper_| variable directly. So instead we call reset() on a | 585 // on the |gl_helper_| variable directly. So instead we call reset() on a |
| 586 // local std::unique_ptr. | 586 // local std::unique_ptr. |
| 587 std::unique_ptr<display_compositor::GLHelper> helper = | 587 std::unique_ptr<display_compositor::GLHelper> helper = |
| 588 std::move(gl_helper_); | 588 std::move(gl_helper_); |
| 589 | 589 |
| 590 // If there are any observer left at this point, make sure they clean up | 590 // If there are any observer left at this point, make sure they clean up |
| 591 // before we destroy the GLHelper. | 591 // before we destroy the GLHelper. |
| 592 FOR_EACH_OBSERVER( | 592 FOR_EACH_OBSERVER(ui::ContextFactoryObserver, observer_list_, |
| 593 ImageTransportFactoryObserver, observer_list_, OnLostResources()); | 593 OnLostResources()); |
| 594 | 594 |
| 595 helper.reset(); | 595 helper.reset(); |
| 596 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " | 596 DCHECK(!gl_helper_) << "Destroying the GLHelper should not cause a new " |
| 597 "GLHelper to be created."; | 597 "GLHelper to be created."; |
| 598 } | 598 } |
| 599 #if defined(OS_WIN) | 599 #if defined(OS_WIN) |
| 600 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( | 600 gfx::RenderingWindowManager::GetInstance()->UnregisterParent( |
| 601 compositor->widget()); | 601 compositor->widget()); |
| 602 #endif | 602 #endif |
| 603 } | 603 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 664 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 665 if (it == per_compositor_data_.end()) | 665 if (it == per_compositor_data_.end()) |
| 666 return; | 666 return; |
| 667 PerCompositorData* data = it->second; | 667 PerCompositorData* data = it->second; |
| 668 DCHECK(data); | 668 DCHECK(data); |
| 669 data->output_is_secure = secure; | 669 data->output_is_secure = secure; |
| 670 if (data->display) | 670 if (data->display) |
| 671 data->display->SetOutputIsSecure(secure); | 671 data->display->SetOutputIsSecure(secure); |
| 672 } | 672 } |
| 673 | 673 |
| 674 void GpuProcessTransportFactory::AddObserver( |
| 675 ui::ContextFactoryObserver* observer) { |
| 676 observer_list_.AddObserver(observer); |
| 677 } |
| 678 |
| 679 void GpuProcessTransportFactory::RemoveObserver( |
| 680 ui::ContextFactoryObserver* observer) { |
| 681 observer_list_.RemoveObserver(observer); |
| 682 } |
| 683 |
| 674 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { | 684 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { |
| 675 return surface_manager_.get(); | 685 return surface_manager_.get(); |
| 676 } | 686 } |
| 677 | 687 |
| 678 display_compositor::GLHelper* GpuProcessTransportFactory::GetGLHelper() { | 688 display_compositor::GLHelper* GpuProcessTransportFactory::GetGLHelper() { |
| 679 if (!gl_helper_ && !per_compositor_data_.empty()) { | 689 if (!gl_helper_ && !per_compositor_data_.empty()) { |
| 680 scoped_refptr<cc::ContextProvider> provider = | 690 scoped_refptr<cc::ContextProvider> provider = |
| 681 SharedMainThreadContextProvider(); | 691 SharedMainThreadContextProvider(); |
| 682 if (provider.get()) | 692 if (provider.get()) |
| 683 gl_helper_.reset(new display_compositor::GLHelper( | 693 gl_helper_.reset(new display_compositor::GLHelper( |
| 684 provider->ContextGL(), provider->ContextSupport())); | 694 provider->ContextGL(), provider->ContextSupport())); |
| 685 } | 695 } |
| 686 return gl_helper_.get(); | 696 return gl_helper_.get(); |
| 687 } | 697 } |
| 688 | 698 |
| 689 void GpuProcessTransportFactory::AddObserver( | |
| 690 ImageTransportFactoryObserver* observer) { | |
| 691 observer_list_.AddObserver(observer); | |
| 692 } | |
| 693 | |
| 694 void GpuProcessTransportFactory::RemoveObserver( | |
| 695 ImageTransportFactoryObserver* observer) { | |
| 696 observer_list_.RemoveObserver(observer); | |
| 697 } | |
| 698 | |
| 699 #if defined(OS_MACOSX) | 699 #if defined(OS_MACOSX) |
| 700 void GpuProcessTransportFactory::SetCompositorSuspendedForRecycle( | 700 void GpuProcessTransportFactory::SetCompositorSuspendedForRecycle( |
| 701 ui::Compositor* compositor, | 701 ui::Compositor* compositor, |
| 702 bool suspended) { | 702 bool suspended) { |
| 703 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 703 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 704 if (it == per_compositor_data_.end()) | 704 if (it == per_compositor_data_.end()) |
| 705 return; | 705 return; |
| 706 PerCompositorData* data = it->second; | 706 PerCompositorData* data = it->second; |
| 707 DCHECK(data); | 707 DCHECK(data); |
| 708 if (data->display_output_surface) | 708 if (data->display_output_surface) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 // new resources are created if needed. | 781 // new resources are created if needed. |
| 782 // Kill shared contexts for both threads in tandem so they are always in | 782 // Kill shared contexts for both threads in tandem so they are always in |
| 783 // the same share group. | 783 // the same share group. |
| 784 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = | 784 scoped_refptr<cc::ContextProvider> lost_shared_main_thread_contexts = |
| 785 shared_main_thread_contexts_; | 785 shared_main_thread_contexts_; |
| 786 shared_main_thread_contexts_ = NULL; | 786 shared_main_thread_contexts_ = NULL; |
| 787 | 787 |
| 788 std::unique_ptr<display_compositor::GLHelper> lost_gl_helper = | 788 std::unique_ptr<display_compositor::GLHelper> lost_gl_helper = |
| 789 std::move(gl_helper_); | 789 std::move(gl_helper_); |
| 790 | 790 |
| 791 FOR_EACH_OBSERVER(ImageTransportFactoryObserver, | 791 FOR_EACH_OBSERVER(ui::ContextFactoryObserver, observer_list_, |
| 792 observer_list_, | |
| 793 OnLostResources()); | 792 OnLostResources()); |
| 794 | 793 |
| 795 // Kill things that use the shared context before killing the shared context. | 794 // Kill things that use the shared context before killing the shared context. |
| 796 lost_gl_helper.reset(); | 795 lost_gl_helper.reset(); |
| 797 lost_shared_main_thread_contexts = NULL; | 796 lost_shared_main_thread_contexts = NULL; |
| 798 } | 797 } |
| 799 | 798 |
| 800 scoped_refptr<cc::VulkanInProcessContextProvider> | 799 scoped_refptr<cc::VulkanInProcessContextProvider> |
| 801 GpuProcessTransportFactory::SharedVulkanContextProvider() { | 800 GpuProcessTransportFactory::SharedVulkanContextProvider() { |
| 802 if (!shared_vulkan_context_provider_initialized_) { | 801 if (!shared_vulkan_context_provider_initialized_) { |
| 803 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 802 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 804 switches::kEnableVulkan)) { | 803 switches::kEnableVulkan)) { |
| 805 shared_vulkan_context_provider_ = | 804 shared_vulkan_context_provider_ = |
| 806 cc::VulkanInProcessContextProvider::Create(); | 805 cc::VulkanInProcessContextProvider::Create(); |
| 807 } | 806 } |
| 808 | 807 |
| 809 shared_vulkan_context_provider_initialized_ = true; | 808 shared_vulkan_context_provider_initialized_ = true; |
| 810 } | 809 } |
| 811 return shared_vulkan_context_provider_; | 810 return shared_vulkan_context_provider_; |
| 812 } | 811 } |
| 813 | 812 |
| 814 } // namespace content | 813 } // namespace content |
| OLD | NEW |