Chromium Code Reviews| Index: content/browser/renderer_host/compositor_impl_android.cc |
| diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc |
| index 49abcb2ce93af4880932990c093b24aec42ed6a5..eeb542c48f7e13e76bfa2d39bb9f7ebf54aca97a 100644 |
| --- a/content/browser/renderer_host/compositor_impl_android.cc |
| +++ b/content/browser/renderer_host/compositor_impl_android.cc |
| @@ -47,9 +47,9 @@ |
| #include "cc/trees/layer_tree_settings.h" |
| #include "components/display_compositor/compositor_overlay_candidate_validator_android.h" |
| #include "components/display_compositor/gl_helper.h" |
| +#include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| #include "content/browser/gpu/compositor_util.h" |
| -#include "content/browser/renderer_host/context_provider_factory_impl_android.h" |
| #include "content/browser/renderer_host/render_widget_host_impl.h" |
| #include "content/common/host_shared_bitmap_manager.h" |
| #include "content/public/browser/android/compositor.h" |
| @@ -78,8 +78,32 @@ namespace content { |
| namespace { |
| +base::LazyInstance<cc::SurfaceManager> g_surface_manager = |
|
boliu
2017/02/10 22:23:02
all the global state should be shoved into a singl
Khushal
2017/02/13 21:07:13
Good idea. Done.
|
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +uint32_t g_next_sink_id = 1u; |
| + |
| const unsigned int kMaxDisplaySwapBuffers = 1U; |
| +#if defined(ENABLE_VULKAN) |
| + |
| +base::LazyInstance<scoped_refptr<cc::VulkanContextProvider>> |
| + g_shared_vulkan_context_provider = LAZY_INSTANCE_INITIALIZER; |
| + |
| +scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() { |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableVulkan)) { |
| + scoped_refptr<cc::VulkanContextProvider>* context_provider = |
| + g_shared_vulkan_context_provider.Pointer(); |
| + if (!*context_provider) |
| + *context_provider = cc::VulkanInProcessContextProvider::Create(); |
| + return *context_provider; |
| + } |
| + return nullptr; |
| +} |
| + |
| +#endif |
| + |
| gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits( |
| gfx::NativeWindow window) { |
| constexpr size_t kBytesPerPixel = 4; |
| @@ -320,14 +344,23 @@ void Compositor::Initialize() { |
| } |
| // static |
| +cc::SurfaceManager* CompositorImpl::GetSurfaceManager() { |
| + return g_surface_manager.Pointer(); |
| +} |
| + |
| +// static |
| +cc::FrameSinkId CompositorImpl::AllocateFrameSinkId() { |
| + return cc::FrameSinkId(0 /* client_id */, g_next_sink_id++); |
|
boliu
2017/02/10 22:23:02
copy over the comment about being unique
Khushal
2017/02/13 21:07:13
Done.
|
| +} |
| + |
| +// static |
| bool CompositorImpl::IsInitialized() { |
| return g_initialized; |
| } |
| CompositorImpl::CompositorImpl(CompositorClient* client, |
| gfx::NativeWindow root_window) |
| - : frame_sink_id_( |
| - ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), |
| + : frame_sink_id_(AllocateFrameSinkId()), |
| resource_manager_(root_window), |
| window_(NULL), |
| surface_handle_(gpu::kNullSurfaceHandle), |
| @@ -338,9 +371,7 @@ CompositorImpl::CompositorImpl(CompositorClient* client, |
| num_successive_context_creation_failures_(0), |
| compositor_frame_sink_request_pending_(false), |
| weak_factory_(this) { |
| - ui::ContextProviderFactory::GetInstance() |
| - ->GetSurfaceManager() |
| - ->RegisterFrameSinkId(frame_sink_id_); |
| + GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); |
| DCHECK(client); |
| DCHECK(root_window); |
| DCHECK(root_window->GetLayer() == nullptr); |
| @@ -358,9 +389,7 @@ CompositorImpl::~CompositorImpl() { |
| root_window_->SetLayer(nullptr); |
| // Clean-up any surface references. |
| SetSurface(NULL); |
| - ui::ContextProviderFactory::GetInstance() |
| - ->GetSurfaceManager() |
| - ->InvalidateFrameSinkId(frame_sink_id_); |
| + GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| } |
| ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
| @@ -560,7 +589,7 @@ void CompositorImpl::HandlePendingCompositorFrameSinkRequest() { |
| #endif |
| DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); |
| - ContextProviderFactoryImpl::GetInstance()->RequestGpuChannelHost(base::Bind( |
| + BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(base::Bind( |
|
boliu
2017/02/10 22:23:02
the gpu timeout got dropped afaict?
Khushal
2017/02/13 21:07:13
Oops, sorry. Added back here.
|
| &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); |
| } |
| @@ -571,8 +600,7 @@ void CompositorImpl::CreateVulkanOutputSurface() { |
| return; |
| scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| - ui::ContextProviderFactory::GetInstance() |
| - ->GetSharedVulkanContextProvider(); |
| + GetSharedVulkanContextProvider(); |
| if (!vulkan_context_provider) |
| return; |
| @@ -587,56 +615,53 @@ void CompositorImpl::CreateVulkanOutputSurface() { |
| #endif |
| void CompositorImpl::OnGpuChannelEstablished( |
| - scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| - ui::ContextProviderFactory::GpuChannelHostResult result) { |
| + scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| // We might end up queing multiple GpuChannel requests for the same |
| // CompositorFrameSink request as the visibility of the compositor changes, so |
| // the CompositorFrameSink request could have been handled already. |
| if (!compositor_frame_sink_request_pending_) |
| return; |
| - switch (result) { |
| - // Don't retry if we are shutting down. |
| - case ui::ContextProviderFactory::GpuChannelHostResult:: |
| - FAILURE_FACTORY_SHUTDOWN: |
| - break; |
| - case ui::ContextProviderFactory::GpuChannelHostResult:: |
| - FAILURE_GPU_PROCESS_INITIALIZATION_FAILED: |
| - HandlePendingCompositorFrameSinkRequest(); |
| - break; |
| - case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS: |
| - // We don't need the context anymore if we are invisible. |
| - if (!host_->IsVisible()) |
| - return; |
| - |
| - DCHECK(window_); |
| - DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); |
| - scoped_refptr<cc::ContextProvider> context_provider = |
| - ContextProviderFactoryImpl::GetInstance() |
| - ->CreateDisplayContextProvider( |
| - surface_handle_, |
| - GetCompositorContextSharedMemoryLimits(root_window_), |
| - GetCompositorContextAttributes(has_transparent_background_), |
| - false /*support_locking*/, false /*automatic_flushes*/, |
| - std::move(gpu_channel_host)); |
| - if (!context_provider->BindToCurrentThread()) { |
| - LOG(ERROR) << "Failed to init ContextProvider for compositor."; |
| - LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) |
| - << "Too many context creation failures. Giving up... "; |
| - HandlePendingCompositorFrameSinkRequest(); |
| - break; |
| - } |
| - |
| - scoped_refptr<ui::ContextProviderCommandBuffer> |
| - context_provider_command_buffer = |
| - static_cast<ui::ContextProviderCommandBuffer*>( |
| - context_provider.get()); |
| - auto display_output_surface = base::MakeUnique<AndroidOutputSurface>( |
| - std::move(context_provider_command_buffer)); |
| - InitializeDisplay(std::move(display_output_surface), nullptr, |
| - std::move(context_provider)); |
| - break; |
| + if (!gpu_channel_host) { |
| + HandlePendingCompositorFrameSinkRequest(); |
| + return; |
| } |
| + |
| + // We don't need the context anymore if we are invisible. |
| + if (!host_->IsVisible()) |
| + return; |
| + |
| + DCHECK(window_); |
| + DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); |
| + bool support_locking = false; |
|
boliu
2017/02/10 22:23:02
nit: constexpr
Khushal
2017/02/13 21:07:13
Done.
|
| + bool automatic_flushes = false; |
| + ui::ContextProviderCommandBuffer* shared_context = nullptr; |
| + scoped_refptr<cc::ContextProvider> context_provider = |
| + new ui::ContextProviderCommandBuffer( |
| + std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, |
| + gpu::GpuStreamPriority::NORMAL, surface_handle_, |
| + GURL(std::string("chrome://gpu/CompositorImpl::") + |
| + std::string("CompositorContextProvider")), |
| + automatic_flushes, support_locking, |
| + GetCompositorContextSharedMemoryLimits(root_window_), |
| + GetCompositorContextAttributes(has_transparent_background_), |
| + shared_context, |
| + ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
| + if (!context_provider->BindToCurrentThread()) { |
| + LOG(ERROR) << "Failed to init ContextProvider for compositor."; |
| + LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) |
| + << "Too many context creation failures. Giving up... "; |
| + HandlePendingCompositorFrameSinkRequest(); |
| + } |
| + |
| + scoped_refptr<ui::ContextProviderCommandBuffer> |
| + context_provider_command_buffer = |
| + static_cast<ui::ContextProviderCommandBuffer*>( |
|
boliu
2017/02/10 22:23:02
just declare context_provider as the subtype, so d
Khushal
2017/02/13 21:07:13
Done.
|
| + context_provider.get()); |
| + auto display_output_surface = base::MakeUnique<AndroidOutputSurface>( |
| + std::move(context_provider_command_buffer)); |
| + InitializeDisplay(std::move(display_output_surface), nullptr, |
| + std::move(context_provider)); |
| } |
| void CompositorImpl::InitializeDisplay( |
| @@ -654,8 +679,7 @@ void CompositorImpl::InitializeDisplay( |
| // TODO(danakj): Populate gpu_capabilities_ for VulkanContextProvider. |
| } |
| - cc::SurfaceManager* manager = |
| - ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); |
| + cc::SurfaceManager* manager = GetSurfaceManager(); |
| auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); |
| std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| task_runner, display_output_surface->capabilities().max_frames_pending)); |
| @@ -744,9 +768,8 @@ cc::FrameSinkId CompositorImpl::GetFrameSinkId() { |
| void CompositorImpl::AddChildFrameSink(const cc::FrameSinkId& frame_sink_id) { |
| if (has_compositor_frame_sink_) { |
| - ui::ContextProviderFactory::GetInstance() |
| - ->GetSurfaceManager() |
| - ->RegisterFrameSinkHierarchy(frame_sink_id_, frame_sink_id); |
| + GetSurfaceManager()->RegisterFrameSinkHierarchy(frame_sink_id_, |
| + frame_sink_id); |
| } else { |
| pending_child_frame_sink_ids_.insert(frame_sink_id); |
| } |
| @@ -759,9 +782,8 @@ void CompositorImpl::RemoveChildFrameSink( |
| pending_child_frame_sink_ids_.erase(it); |
| return; |
| } |
| - ui::ContextProviderFactory::GetInstance() |
| - ->GetSurfaceManager() |
| - ->UnregisterFrameSinkHierarchy(frame_sink_id_, frame_sink_id); |
| + GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| + frame_sink_id); |
| } |
| bool CompositorImpl::HavePendingReadbacks() { |