| 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/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/threading/simple_thread.h" | 17 #include "base/threading/simple_thread.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "cc/base/histograms.h" | 21 #include "cc/base/histograms.h" |
| 22 #include "cc/ipc/display_compositor.mojom.h" |
| 22 #include "cc/output/texture_mailbox_deleter.h" | 23 #include "cc/output/texture_mailbox_deleter.h" |
| 23 #include "cc/output/vulkan_in_process_context_provider.h" | 24 #include "cc/output/vulkan_in_process_context_provider.h" |
| 24 #include "cc/raster/single_thread_task_graph_runner.h" | 25 #include "cc/raster/single_thread_task_graph_runner.h" |
| 25 #include "cc/raster/task_graph_runner.h" | 26 #include "cc/raster/task_graph_runner.h" |
| 26 #include "cc/scheduler/begin_frame_source.h" | 27 #include "cc/scheduler/begin_frame_source.h" |
| 27 #include "cc/scheduler/delay_based_time_source.h" | 28 #include "cc/scheduler/delay_based_time_source.h" |
| 28 #include "cc/surfaces/direct_compositor_frame_sink.h" | 29 #include "cc/surfaces/direct_compositor_frame_sink.h" |
| 29 #include "cc/surfaces/display.h" | 30 #include "cc/surfaces/display.h" |
| 30 #include "cc/surfaces/display_scheduler.h" | 31 #include "cc/surfaces/display_scheduler.h" |
| 32 #include "cc/surfaces/surface_info.h" |
| 31 #include "cc/surfaces/surface_manager.h" | 33 #include "cc/surfaces/surface_manager.h" |
| 32 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" | 34 #include "components/display_compositor/compositor_overlay_candidate_validator.h
" |
| 35 #include "components/display_compositor/display_compositor.h" |
| 33 #include "components/display_compositor/gl_helper.h" | 36 #include "components/display_compositor/gl_helper.h" |
| 34 #include "content/browser/compositor/browser_compositor_output_surface.h" | 37 #include "content/browser/compositor/browser_compositor_output_surface.h" |
| 35 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" | 38 #include "content/browser/compositor/gpu_browser_compositor_output_surface.h" |
| 36 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" | 39 #include "content/browser/compositor/gpu_surfaceless_browser_compositor_output_s
urface.h" |
| 37 #include "content/browser/compositor/offscreen_browser_compositor_output_surface
.h" | 40 #include "content/browser/compositor/offscreen_browser_compositor_output_surface
.h" |
| 38 #include "content/browser/compositor/reflector_impl.h" | 41 #include "content/browser/compositor/reflector_impl.h" |
| 39 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" | 42 #include "content/browser/compositor/software_browser_compositor_output_surface.
h" |
| 40 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 43 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 41 #include "content/browser/gpu/gpu_data_manager_impl.h" | 44 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 42 #include "content/browser/renderer_host/render_widget_host_impl.h" | 45 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 struct GpuProcessTransportFactory::PerCompositorData { | 171 struct GpuProcessTransportFactory::PerCompositorData { |
| 169 gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; | 172 gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; |
| 170 BrowserCompositorOutputSurface* display_output_surface = nullptr; | 173 BrowserCompositorOutputSurface* display_output_surface = nullptr; |
| 171 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source; | 174 std::unique_ptr<cc::SyntheticBeginFrameSource> begin_frame_source; |
| 172 ReflectorImpl* reflector = nullptr; | 175 ReflectorImpl* reflector = nullptr; |
| 173 std::unique_ptr<cc::Display> display; | 176 std::unique_ptr<cc::Display> display; |
| 174 bool output_is_secure = false; | 177 bool output_is_secure = false; |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 GpuProcessTransportFactory::GpuProcessTransportFactory() | 180 GpuProcessTransportFactory::GpuProcessTransportFactory() |
| 178 : task_graph_runner_(new cc::SingleThreadTaskGraphRunner), | 181 : display_compositor_client_binding_(this), |
| 182 task_graph_runner_(new cc::SingleThreadTaskGraphRunner), |
| 179 callback_factory_(this) { | 183 callback_factory_(this) { |
| 180 cc::SetClientNameForMetrics("Browser"); | 184 cc::SetClientNameForMetrics("Browser"); |
| 181 | 185 |
| 182 surface_manager_ = base::WrapUnique(new cc::SurfaceManager); | 186 display_compositor_ = base::MakeUnique<display_compositor::DisplayCompositor>( |
| 187 MakeRequest(&display_compositor_ptr_), |
| 188 display_compositor_client_binding_.CreateInterfacePtrAndBind()); |
| 183 | 189 |
| 184 task_graph_runner_->Start("CompositorTileWorker1", | 190 task_graph_runner_->Start("CompositorTileWorker1", |
| 185 base::SimpleThread::Options()); | 191 base::SimpleThread::Options()); |
| 186 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
| 187 software_backing_.reset(new OutputDeviceBacking); | 193 software_backing_.reset(new OutputDeviceBacking); |
| 188 #endif | 194 #endif |
| 189 } | 195 } |
| 190 | 196 |
| 191 GpuProcessTransportFactory::~GpuProcessTransportFactory() { | 197 GpuProcessTransportFactory::~GpuProcessTransportFactory() { |
| 192 DCHECK(per_compositor_data_.empty()); | 198 DCHECK(per_compositor_data_.empty()); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 // Note that we are careful not to destroy a prior |data->begin_frame_source| | 587 // Note that we are careful not to destroy a prior |data->begin_frame_source| |
| 582 // until we have reset |data->display|. | 588 // until we have reset |data->display|. |
| 583 data->begin_frame_source = std::move(synthetic_begin_frame_source); | 589 data->begin_frame_source = std::move(synthetic_begin_frame_source); |
| 584 | 590 |
| 585 // The |delegated_output_surface| is given back to the compositor, it | 591 // The |delegated_output_surface| is given back to the compositor, it |
| 586 // delegates to the Display as its root surface. Importantly, it shares the | 592 // delegates to the Display as its root surface. Importantly, it shares the |
| 587 // same ContextProvider as the Display's output surface. | 593 // same ContextProvider as the Display's output surface. |
| 588 auto compositor_frame_sink = | 594 auto compositor_frame_sink = |
| 589 vulkan_context_provider | 595 vulkan_context_provider |
| 590 ? base::MakeUnique<cc::DirectCompositorFrameSink>( | 596 ? base::MakeUnique<cc::DirectCompositorFrameSink>( |
| 591 compositor->frame_sink_id(), surface_manager_.get(), | 597 compositor->frame_sink_id(), |
| 592 data->display.get(), | 598 display_compositor_->surface_manager(), data->display.get(), |
| 593 static_cast<scoped_refptr<cc::VulkanContextProvider>>( | 599 static_cast<scoped_refptr<cc::VulkanContextProvider>>( |
| 594 vulkan_context_provider)) | 600 vulkan_context_provider)) |
| 595 : base::MakeUnique<cc::DirectCompositorFrameSink>( | 601 : base::MakeUnique<cc::DirectCompositorFrameSink>( |
| 596 compositor->frame_sink_id(), surface_manager_.get(), | 602 compositor->frame_sink_id(), |
| 597 data->display.get(), context_provider, | 603 display_compositor_->surface_manager(), data->display.get(), |
| 598 shared_worker_context_provider_, GetGpuMemoryBufferManager(), | 604 context_provider, shared_worker_context_provider_, |
| 605 GetGpuMemoryBufferManager(), |
| 599 HostSharedBitmapManager::current()); | 606 HostSharedBitmapManager::current()); |
| 600 data->display->Resize(compositor->size()); | 607 data->display->Resize(compositor->size()); |
| 601 data->display->SetOutputIsSecure(data->output_is_secure); | 608 data->display->SetOutputIsSecure(data->output_is_secure); |
| 602 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 609 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| 603 } | 610 } |
| 604 | 611 |
| 605 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 612 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
| 606 ui::Compositor* source_compositor, | 613 ui::Compositor* source_compositor, |
| 607 ui::Layer* target_layer) { | 614 ui::Layer* target_layer) { |
| 608 PerCompositorData* source_data = | 615 PerCompositorData* source_data = |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 ui::ContextFactoryObserver* observer) { | 783 ui::ContextFactoryObserver* observer) { |
| 777 observer_list_.AddObserver(observer); | 784 observer_list_.AddObserver(observer); |
| 778 } | 785 } |
| 779 | 786 |
| 780 void GpuProcessTransportFactory::RemoveObserver( | 787 void GpuProcessTransportFactory::RemoveObserver( |
| 781 ui::ContextFactoryObserver* observer) { | 788 ui::ContextFactoryObserver* observer) { |
| 782 observer_list_.RemoveObserver(observer); | 789 observer_list_.RemoveObserver(observer); |
| 783 } | 790 } |
| 784 | 791 |
| 785 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { | 792 cc::SurfaceManager* GpuProcessTransportFactory::GetSurfaceManager() { |
| 786 return surface_manager_.get(); | 793 return display_compositor_->surface_manager(); |
| 794 } |
| 795 |
| 796 display_compositor::DisplayCompositor* |
| 797 GpuProcessTransportFactory::GetDisplayCompositor() { |
| 798 return display_compositor_.get(); |
| 787 } | 799 } |
| 788 | 800 |
| 789 display_compositor::GLHelper* GpuProcessTransportFactory::GetGLHelper() { | 801 display_compositor::GLHelper* GpuProcessTransportFactory::GetGLHelper() { |
| 790 if (!gl_helper_ && !per_compositor_data_.empty()) { | 802 if (!gl_helper_ && !per_compositor_data_.empty()) { |
| 791 scoped_refptr<cc::ContextProvider> provider = | 803 scoped_refptr<cc::ContextProvider> provider = |
| 792 SharedMainThreadContextProvider(); | 804 SharedMainThreadContextProvider(); |
| 793 if (provider.get()) | 805 if (provider.get()) |
| 794 gl_helper_.reset(new display_compositor::GLHelper( | 806 gl_helper_.reset(new display_compositor::GLHelper( |
| 795 provider->ContextGL(), provider->ContextSupport())); | 807 provider->ContextGL(), provider->ContextSupport())); |
| 796 } | 808 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 810 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 822 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 811 if (it == per_compositor_data_.end()) | 823 if (it == per_compositor_data_.end()) |
| 812 return; | 824 return; |
| 813 PerCompositorData* data = it->second.get(); | 825 PerCompositorData* data = it->second.get(); |
| 814 DCHECK(data); | 826 DCHECK(data); |
| 815 if (data->display_output_surface) | 827 if (data->display_output_surface) |
| 816 data->display_output_surface->SetSurfaceSuspendedForRecycle(suspended); | 828 data->display_output_surface->SetSurfaceSuspendedForRecycle(suspended); |
| 817 } | 829 } |
| 818 #endif | 830 #endif |
| 819 | 831 |
| 832 void GpuProcessTransportFactory::OnSurfaceCreated( |
| 833 const cc::SurfaceInfo& surface_info) { |
| 834 // TODO(fsamuel): Implement this. |
| 835 } |
| 836 |
| 820 scoped_refptr<cc::ContextProvider> | 837 scoped_refptr<cc::ContextProvider> |
| 821 GpuProcessTransportFactory::SharedMainThreadContextProvider() { | 838 GpuProcessTransportFactory::SharedMainThreadContextProvider() { |
| 822 if (shared_main_thread_contexts_) | 839 if (shared_main_thread_contexts_) |
| 823 return shared_main_thread_contexts_; | 840 return shared_main_thread_contexts_; |
| 824 | 841 |
| 825 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) | 842 if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor()) |
| 826 return nullptr; | 843 return nullptr; |
| 827 | 844 |
| 828 DCHECK(gpu_channel_factory_); | 845 DCHECK(gpu_channel_factory_); |
| 829 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = | 846 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 shared_vulkan_context_provider_ = | 931 shared_vulkan_context_provider_ = |
| 915 cc::VulkanInProcessContextProvider::Create(); | 932 cc::VulkanInProcessContextProvider::Create(); |
| 916 } | 933 } |
| 917 | 934 |
| 918 shared_vulkan_context_provider_initialized_ = true; | 935 shared_vulkan_context_provider_initialized_ = true; |
| 919 } | 936 } |
| 920 return shared_vulkan_context_provider_; | 937 return shared_vulkan_context_provider_; |
| 921 } | 938 } |
| 922 | 939 |
| 923 } // namespace content | 940 } // namespace content |
| OLD | NEW |