Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: content/browser/renderer_host/context_provider_factory_impl_android.cc

Issue 2250473005: content: Fix Context creation logic in ContextProviderFactoryImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 40cc97c1a4a271837d53117c4d92b6822012aae8..703e00894f7aff180b546a21c682f382a0a18bde 100644
--- a/content/browser/renderer_host/context_provider_factory_impl_android.cc
+++ b/content/browser/renderer_host/context_provider_factory_impl_android.cc
@@ -39,6 +39,21 @@ command_buffer_metrics::ContextType ToCommandBufferContextType(
return command_buffer_metrics::CONTEXT_TYPE_UNKNOWN;
}
+bool IsGpuChannelHostFactoryAvailable() {
+ return BrowserGpuChannelHostFactory::instance() != nullptr;
+}
+
+gpu::GpuChannelHost* IsGpuChannelAvailable() {
+ BrowserGpuChannelHostFactory* factory =
+ BrowserGpuChannelHostFactory::instance();
+ DCHECK(factory);
+
+ if (factory->GetGpuChannel())
+ return factory->GetGpuChannel();
+ else
+ return nullptr;
+}
+
} // namespace
// static
@@ -145,10 +160,30 @@ void ContextProviderFactoryImpl::CreateContextProviderInternal(
context_request.result_callback = result_callback;
context_provider_requests_.push_back(context_request);
- HandlePendingRequests();
+ CheckCanHandlePendingRequests();
}
-void ContextProviderFactoryImpl::HandlePendingRequests() {
+void ContextProviderFactoryImpl::CheckCanHandlePendingRequests() {
+ DCHECK(!context_provider_requests_.empty())
+ << "We don't have any pending requests?";
+ if (!IsGpuChannelHostFactoryAvailable()) {
+ HandlePendingRequests(nullptr,
+ ContextCreationFailureReason::BROWSER_SHUTDOWN);
+ return;
+ }
+
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(IsGpuChannelAvailable());
+ if (gpu_channel_host) {
+ HandlePendingRequests(gpu_channel_host,
+ ContextCreationFailureReason::FAILURE_NONE);
+ } else {
+ EstablishGpuChannel();
+ }
+}
+
+void ContextProviderFactoryImpl::HandlePendingRequests(
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
+ ContextCreationFailureReason reason) {
DCHECK(!context_provider_requests_.empty())
<< "We don't have any pending requests?";
@@ -161,15 +196,6 @@ void ContextProviderFactoryImpl::HandlePendingRequests() {
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();
@@ -186,9 +212,17 @@ void ContextProviderFactoryImpl::HandlePendingRequests() {
if (create_onscreen_context &&
!GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle(
context_request.surface_handle)) {
- continue;
+ // GPU Surface handle loss trumps other context creation failure
+ // reasons.
+ context_request.result_callback.Run(
+ nullptr, ContextCreationFailureReason::GPU_SURFACE_HANDLE_LOST);
}
+ if (!gpu_channel_host)
+ context_request.result_callback.Run(nullptr, reason);
+
+ DCHECK_EQ(ContextCreationFailureReason::FAILURE_NONE, reason);
+
context_provider = new ContextProviderCommandBuffer(
gpu_channel_host, gpu::GPU_STREAM_DEFAULT,
gpu::GpuStreamPriority::NORMAL, context_request.surface_handle,
@@ -199,15 +233,15 @@ void ContextProviderFactoryImpl::HandlePendingRequests() {
static_cast<ContextProviderCommandBuffer*>(
context_request.shared_context_provider),
context_request.context_type);
- context_request.result_callback.Run(context_provider);
+ context_request.result_callback.Run(context_provider, reason);
}
}
if (!context_provider_requests_.empty())
- HandlePendingRequests();
+ CheckCanHandlePendingRequests();
}
-gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() {
+void ContextProviderFactoryImpl::EstablishGpuChannel() {
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
const int64_t kGpuChannelTimeoutInSeconds = 40;
@@ -217,9 +251,7 @@ gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() {
BrowserGpuChannelHostFactory* factory =
BrowserGpuChannelHostFactory::instance();
-
- if (factory->GetGpuChannel())
- return factory->GetGpuChannel();
+ DCHECK(factory);
factory->EstablishGpuChannel(
base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished,
@@ -227,24 +259,29 @@ gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() {
establish_gpu_channel_timeout_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
this, &ContextProviderFactoryImpl::OnGpuChannelTimeout);
-
- 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())
- HandlePendingRequests();
+ if (context_provider_requests_.empty())
+ return;
+
+ if (gpu_channel) {
+ HandlePendingRequests(std::move(gpu_channel),
+ ContextCreationFailureReason::FAILURE_NONE);
+ } else if (IsGpuChannelHostFactoryAvailable()) {
+ HandlePendingRequests(
+ nullptr,
+ ContextCreationFailureReason::GPU_PROCESS_INITIALIZATION_FAILURE);
+ } else {
+ HandlePendingRequests(nullptr,
+ ContextCreationFailureReason::BROWSER_SHUTDOWN);
+ }
}
void ContextProviderFactoryImpl::OnGpuChannelTimeout() {

Powered by Google App Engine
This is Rietveld 408576698