| 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..3751eaa10620509fb4f15059da87caf98b12b978 100644
|
| --- a/content/browser/renderer_host/context_provider_factory_impl_android.cc
|
| +++ b/content/browser/renderer_host/context_provider_factory_impl_android.cc
|
| @@ -11,7 +11,6 @@
|
| #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"
|
| @@ -39,19 +38,44 @@ command_buffer_metrics::ContextType ToCommandBufferContextType(
|
| 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 base::Singleton<ContextProviderFactoryImpl>::get();
|
| + return instance;
|
| }
|
|
|
| -ContextProviderFactoryImpl::ContextProviderFactoryImpl()
|
| - : in_handle_pending_requests_(false),
|
| +ContextProviderFactoryImpl::ContextProviderFactoryImpl(
|
| + gpu::GpuChannelEstablishFactory* gpu_channel_factory)
|
| + : gpu_channel_factory_(gpu_channel_factory),
|
| + in_handle_pending_requests_(false),
|
| + in_shutdown_(false),
|
| surface_client_id_(0),
|
| - weak_factory_(this) {}
|
| + weak_factory_(this) {
|
| + DCHECK(gpu_channel_factory_);
|
| +}
|
|
|
| -ContextProviderFactoryImpl::~ContextProviderFactoryImpl() {}
|
| +ContextProviderFactoryImpl::~ContextProviderFactoryImpl() {
|
| + in_shutdown_ = true;
|
| + if (!context_provider_requests_.empty())
|
| + HandlePendingRequests(nullptr,
|
| + ContextCreationResult::FAILURE_FACTORY_SHUTDOWN);
|
| +}
|
|
|
| ContextProviderFactoryImpl::ContextProvidersRequest::ContextProvidersRequest()
|
| : context_type(command_buffer_metrics::CONTEXT_TYPE_UNKNOWN),
|
| @@ -82,6 +106,8 @@ void ContextProviderFactoryImpl::CreateDisplayContextProvider(
|
| 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,
|
| @@ -97,6 +123,8 @@ void ContextProviderFactoryImpl::CreateOffscreenContextProvider(
|
| 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,
|
| @@ -145,10 +173,15 @@ void ContextProviderFactoryImpl::CreateContextProviderInternal(
|
| context_request.result_callback = result_callback;
|
|
|
| context_provider_requests_.push_back(context_request);
|
| - HandlePendingRequests();
|
| +
|
| + // If the channel is available, the factory will run the callback
|
| + // synchronously so we'll handle this request there.
|
| + EstablishGpuChannel();
|
| }
|
|
|
| -void ContextProviderFactoryImpl::HandlePendingRequests() {
|
| +void ContextProviderFactoryImpl::HandlePendingRequests(
|
| + scoped_refptr<gpu::GpuChannelHost> gpu_channel_host,
|
| + ContextCreationResult result) {
|
| DCHECK(!context_provider_requests_.empty())
|
| << "We don't have any pending requests?";
|
|
|
| @@ -161,53 +194,52 @@ 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();
|
|
|
| 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. DO NOT run the callback if we don't have a
|
| - // valid surface.
|
| + // still valid in that case.
|
| if (create_onscreen_context &&
|
| !GpuSurfaceTracker::GetInstance()->IsValidSurfaceHandle(
|
| context_request.surface_handle)) {
|
| - continue;
|
| + // 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_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);
|
| + context_request.result_callback.Run(context_provider, result_to_report);
|
| }
|
| }
|
|
|
| if (!context_provider_requests_.empty())
|
| - HandlePendingRequests();
|
| + EstablishGpuChannel();
|
| }
|
|
|
| -gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() {
|
| +void ContextProviderFactoryImpl::EstablishGpuChannel() {
|
| #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
|
| defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
|
| const int64_t kGpuChannelTimeoutInSeconds = 40;
|
| @@ -215,36 +247,35 @@ gpu::GpuChannelHost* ContextProviderFactoryImpl::EnsureGpuChannelEstablished() {
|
| const int64_t kGpuChannelTimeoutInSeconds = 10;
|
| #endif
|
|
|
| - BrowserGpuChannelHostFactory* factory =
|
| - BrowserGpuChannelHostFactory::instance();
|
| -
|
| - if (factory->GetGpuChannel())
|
| - return factory->GetGpuChannel();
|
| -
|
| - factory->EstablishGpuChannel(
|
| - base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished,
|
| - weak_factory_.GetWeakPtr()));
|
| + // Start the timer first, if the result comes synchronously, we want it to
|
| + // stop in the callback.
|
| establish_gpu_channel_timeout_.Start(
|
| FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
|
| this, &ContextProviderFactoryImpl::OnGpuChannelTimeout);
|
|
|
| - return nullptr;
|
| + gpu_channel_factory_->EstablishGpuChannel(
|
| + base::Bind(&ContextProviderFactoryImpl::OnGpuChannelEstablished,
|
| + weak_factory_.GetWeakPtr()));
|
| }
|
|
|
| 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),
|
| + ContextCreationResult::SUCCESS);
|
| + } else {
|
| + HandlePendingRequests(
|
| + nullptr,
|
| + ContextCreationResult::FAILURE_GPU_PROCESS_INITIALIZATION_FAILED);
|
| + }
|
| }
|
|
|
| void ContextProviderFactoryImpl::OnGpuChannelTimeout() {
|
|
|