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..40cc97c1a4a271837d53117c4d92b6822012aae8 100644 |
--- a/content/browser/renderer_host/context_provider_factory_impl_android.cc |
+++ b/content/browser/renderer_host/context_provider_factory_impl_android.cc |
@@ -11,6 +11,7 @@ |
#include "cc/output/context_provider.h" |
#include "cc/output/vulkan_in_process_context_provider.h" |
#include "cc/surfaces/surface_manager.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/gpu/gpu_surface_tracker.h" |
@@ -38,44 +39,19 @@ |
return command_buffer_metrics::CONTEXT_TYPE_UNKNOWN; |
} |
-ContextProviderFactoryImpl* instance = nullptr; |
- |
} // namespace |
- |
-// static |
-void ContextProviderFactoryImpl::Initialize( |
- gpu::GpuChannelEstablishFactory* gpu_channel_factory) { |
- DCHECK(!instance); |
- instance = new ContextProviderFactoryImpl(gpu_channel_factory); |
-} |
- |
-void ContextProviderFactoryImpl::Terminate() { |
- DCHECK(instance); |
- delete instance; |
- instance = nullptr; |
-} |
// static |
ContextProviderFactoryImpl* ContextProviderFactoryImpl::GetInstance() { |
- return instance; |
-} |
- |
-ContextProviderFactoryImpl::ContextProviderFactoryImpl( |
- gpu::GpuChannelEstablishFactory* gpu_channel_factory) |
- : gpu_channel_factory_(gpu_channel_factory), |
- in_handle_pending_requests_(false), |
- in_shutdown_(false), |
+ return base::Singleton<ContextProviderFactoryImpl>::get(); |
+} |
+ |
+ContextProviderFactoryImpl::ContextProviderFactoryImpl() |
+ : in_handle_pending_requests_(false), |
surface_client_id_(0), |
- weak_factory_(this) { |
- DCHECK(gpu_channel_factory_); |
-} |
- |
-ContextProviderFactoryImpl::~ContextProviderFactoryImpl() { |
- in_shutdown_ = true; |
- if (!context_provider_requests_.empty()) |
- HandlePendingRequests(nullptr, |
- ContextCreationResult::FAILURE_FACTORY_SHUTDOWN); |
-} |
+ weak_factory_(this) {} |
+ |
+ContextProviderFactoryImpl::~ContextProviderFactoryImpl() {} |
ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest() |
: context_type(command_buffer_metrics::CONTEXT_TYPE_UNKNOWN), |
@@ -106,8 +82,6 @@ |
bool support_locking, |
bool automatic_flushes, |
ContextProviderCallback result_callback) { |
- DCHECK(!in_shutdown_) |
- << "The factory is shutting down, can't handle new requests"; |
DCHECK(surface_handle != gpu::kNullSurfaceHandle); |
CreateContextProviderInternal( |
command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT, |
@@ -123,8 +97,6 @@ |
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, |
@@ -173,15 +145,10 @@ |
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(); |
-} |
- |
-void ContextProviderFactoryImpl::HandlePendingRequests( |
- scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
- ContextCreationResult result) { |
+ HandlePendingRequests(); |
+} |
+ |
+void ContextProviderFactoryImpl::HandlePendingRequests() { |
DCHECK(!context_provider_requests_.empty()) |
<< "We don't have any pending requests?"; |
@@ -194,52 +161,53 @@ |
base::AutoReset<bool> auto_reset_in_handle_requests( |
&in_handle_pending_requests_, true); |
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( |
+ EnsureGpuChannelEstablished()); |
+ |
+ // If we don't have a Gpu Channel Host, we will come back here when the Gpu |
+ // channel is established, since OnGpuChannelEstablished triggers handling |
+ // of the requests we couldn't process right now. |
+ if (!gpu_channel_host) |
+ return; |
+ |
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. |
+ // still valid in that case. DO NOT run the callback if we don't have a |
+ // valid surface. |
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); |
+ continue; |
} |
- context_request.result_callback.Run(context_provider, result_to_report); |
+ 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); |
} |
} |
if (!context_provider_requests_.empty()) |
- EstablishGpuChannel(); |
-} |
- |
-void ContextProviderFactoryImpl::EstablishGpuChannel() { |
+ HandlePendingRequests(); |
+} |
+ |
+gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() { |
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ |
defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) |
const int64_t kGpuChannelTimeoutInSeconds = 40; |
@@ -247,35 +215,36 @@ |
const int64_t kGpuChannelTimeoutInSeconds = 10; |
#endif |
- // Start the timer first, if the result comes synchronously, we want it to |
- // stop in the callback. |
+ BrowserGpuChannelHostFactory* factory = |
+ BrowserGpuChannelHostFactory::instance(); |
+ |
+ if (factory->GetGpuChannel()) |
+ return factory->GetGpuChannel(); |
+ |
+ factory->EstablishGpuChannel( |
+ base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished, |
+ weak_factory_.GetWeakPtr())); |
establish_gpu_channel_timeout_.Start( |
FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds), |
this, &ContextProviderFactoryImpl::OnGpuChannelTimeout); |
- gpu_channel_factory_->EstablishGpuChannel( |
- base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished, |
- weak_factory_.GetWeakPtr())); |
+ return nullptr; |
} |
void ContextProviderFactoryImpl::OnGpuChannelEstablished( |
scoped_refptr<gpu::GpuChannelHost> gpu_channel) { |
establish_gpu_channel_timeout_.Stop(); |
+ // This should happen only during shutdown. So early out instead of queuing |
+ // more requests with the factory. |
+ if (!gpu_channel) |
+ return; |
+ |
// 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()) |
- return; |
- |
- if (gpu_channel) { |
- HandlePendingRequests(std::move(gpu_channel), |
- ContextCreationResult::SUCCESS); |
- } else { |
- HandlePendingRequests( |
- nullptr, |
- ContextCreationResult::FAILURE_GPU_PROCESS_INITIALIZATION_FAILED); |
- } |
+ if (!context_provider_requests_.empty()) |
+ HandlePendingRequests(); |
} |
void ContextProviderFactoryImpl::OnGpuChannelTimeout() { |