Chromium Code Reviews| Index: content/browser/renderer_host/context_provider_factory_impl_android.cc |
| diff --git a/content/browser/renderer_host/context_provider_factory_impl_android.cc b/content/browser/renderer_host/context_provider_factory_impl_android.cc |
| index 3751eaa10620509fb4f15059da87caf98b12b978..a9c1b3a98a8ade18db082eb628256b0008c84f34 100644 |
| --- a/content/browser/renderer_host/context_provider_factory_impl_android.cc |
| +++ b/content/browser/renderer_host/context_provider_factory_impl_android.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/auto_reset.h" |
| #include "base/command_line.h" |
| #include "base/lazy_instance.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/singleton.h" |
| #include "cc/output/context_provider.h" |
| #include "cc/output/vulkan_in_process_context_provider.h" |
| @@ -72,24 +73,11 @@ ContextProviderFactoryImpl::ContextProviderFactoryImpl( |
| ContextProviderFactoryImpl::~ContextProviderFactoryImpl() { |
| in_shutdown_ = true; |
| - if (!context_provider_requests_.empty()) |
| + if (!gpu_channel_requests_.empty()) |
| HandlePendingRequests(nullptr, |
| - ContextCreationResult::FAILURE_FACTORY_SHUTDOWN); |
| + GpuChannelHostResult::FAILURE_FACTORY_SHUTDOWN); |
| } |
| -ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest() |
| - : context_type(command_buffer_metrics::CONTEXT_TYPE_UNKNOWN), |
| - surface_handle(gpu::kNullSurfaceHandle), |
| - support_locking(false), |
| - automatic_flushes(false), |
| - shared_context_provider(nullptr) {} |
| - |
| -ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest( |
| - const ContextProvidersRequest& other) = default; |
| - |
| -ContextProviderFactoryImpl::ContextProvidersRequest:: |
| - ~ContextProvidersRequest() = default; |
| - |
| scoped_refptr<cc::VulkanContextProvider> |
| ContextProviderFactoryImpl::GetSharedVulkanContextProvider() { |
| if (!shared_vulkan_context_provider_) |
| @@ -99,36 +87,45 @@ ContextProviderFactoryImpl::GetSharedVulkanContextProvider() { |
| return shared_vulkan_context_provider_.get(); |
| } |
| -void ContextProviderFactoryImpl::CreateDisplayContextProvider( |
| +void ContextProviderFactoryImpl::RequestGpuChannelHost( |
| + GpuChannelHostCallback callback) { |
| + DCHECK(!in_shutdown_) |
| + << "The factory is shutting down, can't handle new requests"; |
| + |
| + gpu_channel_requests_.push_back(callback); |
| + // If the channel is available, the factory will run the callback |
| + // synchronously so we'll handle this request there. |
| + EstablishGpuChannel(); |
| +} |
| + |
| +scoped_refptr<cc::ContextProvider> |
| +ContextProviderFactoryImpl::CreateDisplayContextProvider( |
| gpu::SurfaceHandle surface_handle, |
| gpu::SharedMemoryLimits shared_memory_limits, |
| gpu::gles2::ContextCreationAttribHelper attributes, |
| bool support_locking, |
| bool automatic_flushes, |
| - ContextProviderCallback result_callback) { |
| - DCHECK(!in_shutdown_) |
| - << "The factory is shutting down, can't handle new requests"; |
| + gpu::GpuChannelHost* gpu_channel_host) { |
| DCHECK(surface_handle != gpu::kNullSurfaceHandle); |
| - CreateContextProviderInternal( |
| + return CreateContextProviderInternal( |
| command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT, |
| surface_handle, shared_memory_limits, attributes, support_locking, |
| - automatic_flushes, nullptr, result_callback); |
| + automatic_flushes, nullptr, gpu_channel_host); |
| } |
| -void ContextProviderFactoryImpl::CreateOffscreenContextProvider( |
| +scoped_refptr<cc::ContextProvider> |
| +ContextProviderFactoryImpl::CreateOffscreenContextProvider( |
| ContextType context_type, |
| gpu::SharedMemoryLimits shared_memory_limits, |
| gpu::gles2::ContextCreationAttribHelper attributes, |
| bool support_locking, |
| bool automatic_flushes, |
| cc::ContextProvider* shared_context_provider, |
| - ContextProviderCallback result_callback) { |
| - DCHECK(!in_shutdown_) |
| - << "The factory is shutting down, can't handle new requests"; |
| - CreateContextProviderInternal(ToCommandBufferContextType(context_type), |
| - gpu::kNullSurfaceHandle, shared_memory_limits, |
| - attributes, support_locking, automatic_flushes, |
| - shared_context_provider, result_callback); |
| + gpu::GpuChannelHost* gpu_channel_host) { |
| + return CreateContextProviderInternal( |
| + ToCommandBufferContextType(context_type), gpu::kNullSurfaceHandle, |
| + shared_memory_limits, attributes, support_locking, automatic_flushes, |
| + shared_context_provider, gpu_channel_host); |
| } |
| cc::SurfaceManager* ContextProviderFactoryImpl::GetSurfaceManager() { |
| @@ -151,7 +148,8 @@ ContextProviderFactoryImpl::GetGpuMemoryBufferManager() { |
| return BrowserGpuMemoryBufferManager::current(); |
| } |
| -void ContextProviderFactoryImpl::CreateContextProviderInternal( |
| +scoped_refptr<cc::ContextProvider> |
| +ContextProviderFactoryImpl::CreateContextProviderInternal( |
| command_buffer_metrics::ContextType context_type, |
| gpu::SurfaceHandle surface_handle, |
| gpu::SharedMemoryLimits shared_memory_limits, |
| @@ -159,33 +157,24 @@ void ContextProviderFactoryImpl::CreateContextProviderInternal( |
| bool support_locking, |
| bool automatic_flushes, |
| cc::ContextProvider* shared_context_provider, |
| - ContextProviderCallback result_callback) { |
| - DCHECK(!result_callback.is_null()); |
| - |
| - ContextProvidersRequest context_request; |
| - context_request.context_type = context_type; |
| - context_request.surface_handle = surface_handle; |
| - context_request.shared_memory_limits = shared_memory_limits; |
| - context_request.attributes = attributes; |
| - context_request.support_locking = support_locking; |
| - context_request.automatic_flushes = automatic_flushes; |
| - context_request.shared_context_provider = shared_context_provider; |
| - context_request.result_callback = result_callback; |
| - |
| - context_provider_requests_.push_back(context_request); |
| - |
| - // If the channel is available, the factory will run the callback |
| - // synchronously so we'll handle this request there. |
| - EstablishGpuChannel(); |
| + gpu::GpuChannelHost* gpu_channel_host) { |
| + return make_scoped_refptr(new ContextProviderCommandBuffer( |
| + gpu_channel_host, gpu::GPU_STREAM_DEFAULT, gpu::GpuStreamPriority::NORMAL, |
|
danakj
2016/09/01 23:35:19
this gpu_channel_host is an implicit conversion to
Khushal
2016/09/02 00:24:33
Didn't see that it was a refptr. Done.
|
| + surface_handle, |
| + GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") + |
| + std::string("CompositorContextProvider")), |
| + automatic_flushes, support_locking, shared_memory_limits, attributes, |
| + static_cast<ContextProviderCommandBuffer*>(shared_context_provider), |
| + context_type)); |
| } |
| void ContextProviderFactoryImpl::HandlePendingRequests( |
| scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| - ContextCreationResult result) { |
| - DCHECK(!context_provider_requests_.empty()) |
| + GpuChannelHostResult result) { |
| + DCHECK(!gpu_channel_requests_.empty()) |
| << "We don't have any pending requests?"; |
| - // Failure to initialize the context could result in new requests. Handle |
| + // Failure to initialize the channel could result in new requests. Handle |
| // them after going through the current list. |
| if (in_handle_pending_requests_) |
| return; |
| @@ -194,48 +183,17 @@ void ContextProviderFactoryImpl::HandlePendingRequests( |
| base::AutoReset<bool> auto_reset_in_handle_requests( |
| &in_handle_pending_requests_, true); |
| - std::list<ContextProvidersRequest> context_requests = |
| - context_provider_requests_; |
| - context_provider_requests_.clear(); |
| - |
| - for (ContextProvidersRequest& context_request : context_requests) { |
| - scoped_refptr<cc::ContextProvider> context_provider; |
| - ContextCreationResult result_to_report = result; |
| - |
| - const bool create_onscreen_context = |
| - context_request.surface_handle != gpu::kNullSurfaceHandle; |
| - |
| - // Is the request for an onscreen context? Make sure the surface is |
| - // still valid in that case. |
| - if (create_onscreen_context && |
| - !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle( |
| - context_request.surface_handle)) { |
| - // Choose what to report based on severity, factory shutdown trumps |
| - // everything, otherwise report GpuSurfaceHandle loss. |
| - result_to_report = |
| - result_to_report == ContextCreationResult::FAILURE_FACTORY_SHUTDOWN |
| - ? result_to_report |
| - : ContextCreationResult::FAILURE_GPU_SURFACE_HANDLE_LOST; |
| - } else if (gpu_channel_host) { |
| - DCHECK_EQ(ContextCreationResult::SUCCESS, result); |
| - |
| - context_provider = new ContextProviderCommandBuffer( |
| - gpu_channel_host, gpu::GPU_STREAM_DEFAULT, |
| - gpu::GpuStreamPriority::NORMAL, context_request.surface_handle, |
| - GURL(std::string("chrome://gpu/ContextProviderFactoryImpl::") + |
| - std::string("CompositorContextProvider")), |
| - context_request.automatic_flushes, context_request.support_locking, |
| - context_request.shared_memory_limits, context_request.attributes, |
| - static_cast<ContextProviderCommandBuffer*>( |
| - context_request.shared_context_provider), |
| - context_request.context_type); |
| - } |
| - |
| - context_request.result_callback.Run(context_provider, result_to_report); |
| + std::list<GpuChannelHostCallback> gpu_channel_requests = |
|
danakj
2016/09/01 23:35:19
Normally I'd see this written as
std::list<T> req
Khushal
2016/09/02 00:24:33
Much better. Done.
|
| + gpu_channel_requests_; |
| + gpu_channel_requests_.clear(); |
| + |
| + for (GpuChannelHostCallback& gpu_channel_request : gpu_channel_requests) { |
| + DCHECK(gpu_channel_host || result != GpuChannelHostResult::SUCCESS); |
| + gpu_channel_request.Run(gpu_channel_host, result); |
| } |
| } |
| - if (!context_provider_requests_.empty()) |
| + if (!gpu_channel_requests_.empty()) |
| EstablishGpuChannel(); |
| } |
| @@ -265,16 +223,16 @@ void ContextProviderFactoryImpl::OnGpuChannelEstablished( |
| // We can queue the Gpu Channel initialization requests multiple times as |
| // we get context requests. So we might have already handled any pending |
| // requests when this callback runs. |
| - if (context_provider_requests_.empty()) |
| + if (gpu_channel_requests_.empty()) |
| return; |
| if (gpu_channel) { |
| HandlePendingRequests(std::move(gpu_channel), |
| - ContextCreationResult::SUCCESS); |
| + GpuChannelHostResult::SUCCESS); |
| } else { |
| HandlePendingRequests( |
| nullptr, |
| - ContextCreationResult::FAILURE_GPU_PROCESS_INITIALIZATION_FAILED); |
| + GpuChannelHostResult::FAILURE_GPU_PROCESS_INITIALIZATION_FAILED); |
| } |
| } |