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

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

Issue 2190033002: content: Add ContextProviderFactory to create a render ContextProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. Created 4 years, 5 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/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 c06a342f3ef292467ccad377375d5cb5d342fec0..10c3f7f6a2c455ad3076bc63fcd5c0069acc7f51 100644
--- a/content/browser/renderer_host/compositor_impl_android.cc
+++ b/content/browser/renderer_host/compositor_impl_android.cc
@@ -44,16 +44,15 @@
#include "cc/surfaces/display_scheduler.h"
#include "cc/surfaces/surface_display_output_surface.h"
#include "cc/surfaces/surface_id_allocator.h"
-#include "cc/surfaces/surface_manager.h"
#include "cc/trees/layer_tree_host.h"
#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/android/child_process_launcher_android.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"
+#include "content/browser/renderer_host/context_provider_factory_impl_android.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
#include "content/common/gpu_process_launch_causes.h"
@@ -288,16 +287,8 @@ class VulkanOutputSurface : public cc::OutputSurface {
};
#endif
-base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>>
- g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER;
-
static bool g_initialized = false;
-base::LazyInstance<cc::SurfaceManager> g_surface_manager =
- LAZY_INSTANCE_INITIALIZER;
-
-int g_surface_client_id = 0;
-
class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
public:
SingleThreadTaskGraphRunner() {
@@ -331,34 +322,11 @@ bool CompositorImpl::IsInitialized() {
return g_initialized;
}
-// static
-cc::SurfaceManager* CompositorImpl::GetSurfaceManager() {
- return g_surface_manager.Pointer();
-}
-
-// static
-uint32_t CompositorImpl::AllocateSurfaceClientId() {
- return ++g_surface_client_id;
-}
-
-// static
-scoped_refptr<cc::VulkanInProcessContextProvider>
-CompositorImpl::SharedVulkanContextProviderAndroid() {
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableVulkan)) {
- scoped_refptr<cc::VulkanInProcessContextProvider>* context_provider =
- g_shared_vulkan_context_provider_android_.Pointer();
- if (!*context_provider)
- *context_provider = cc::VulkanInProcessContextProvider::Create();
- return *context_provider;
- }
- return nullptr;
-}
-
CompositorImpl::CompositorImpl(CompositorClient* client,
gfx::NativeWindow root_window)
: surface_id_allocator_(
- new cc::SurfaceIdAllocator(AllocateSurfaceClientId())),
+ new cc::SurfaceIdAllocator(ui::ContextProviderFactory::GetInstance()
+ ->AllocateSurfaceClientId())),
resource_manager_(root_window),
has_transparent_background_(false),
device_scale_factor_(1),
@@ -372,8 +340,9 @@ CompositorImpl::CompositorImpl(CompositorClient* client,
output_surface_request_pending_(false),
needs_begin_frames_(false),
weak_factory_(this) {
- GetSurfaceManager()->RegisterSurfaceClientId(
- surface_id_allocator_->client_id());
+ ui::ContextProviderFactory::GetInstance()
+ ->GetSurfaceManager()
+ ->RegisterSurfaceClientId(surface_id_allocator_->client_id());
DCHECK(client);
DCHECK(root_window);
DCHECK(root_window->GetLayer() == nullptr);
@@ -388,8 +357,9 @@ CompositorImpl::~CompositorImpl() {
root_window_->SetLayer(nullptr);
// Clean-up any surface references.
SetSurface(NULL);
- GetSurfaceManager()->InvalidateSurfaceClientId(
- surface_id_allocator_->client_id());
+ ui::ContextProviderFactory::GetInstance()
+ ->GetSurfaceManager()
+ ->InvalidateSurfaceClientId(surface_id_allocator_->client_id());
}
ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() {
@@ -491,7 +461,6 @@ void CompositorImpl::SetVisible(bool visible) {
if (!host_->output_surface_lost())
host_->ReleaseOutputSurface();
pending_swapbuffers_ = 0;
- establish_gpu_channel_timeout_.Stop();
no sievers 2016/07/29 19:14:30 Hmm I wonder why this was here, and how we could c
Khushal 2016/07/29 21:30:55 This happens when the surface goes away. Is that r
no sievers 2016/07/29 21:42:41 I don't remember why this is here. It seems to som
display_.reset();
} else {
host_->SetVisible(true);
@@ -539,39 +508,14 @@ void CompositorImpl::UpdateLayerTreeHost() {
}
}
-void CompositorImpl::OnGpuChannelEstablished() {
- establish_gpu_channel_timeout_.Stop();
- CreateOutputSurface();
-}
-
-void CompositorImpl::OnGpuChannelTimeout() {
- LOG(FATAL) << "Timed out waiting for GPU channel.";
+void CompositorImpl::OnGpuChannelEstablished(
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
+ CreateOutputSurface(std::move(gpu_channel_host));
}
void CompositorImpl::RequestNewOutputSurface() {
output_surface_request_pending_ = true;
-
-#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
- defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
- const int64_t kGpuChannelTimeoutInSeconds = 40;
-#else
- const int64_t kGpuChannelTimeoutInSeconds = 10;
-#endif
-
- BrowserGpuChannelHostFactory* factory =
- BrowserGpuChannelHostFactory::instance();
- if (!factory->GetGpuChannel()) {
- factory->EstablishGpuChannel(
- CAUSE_FOR_GPU_LAUNCH_DISPLAY_COMPOSITOR_CONTEXT,
- base::Bind(&CompositorImpl::OnGpuChannelEstablished,
- weak_factory_.GetWeakPtr()));
- establish_gpu_channel_timeout_.Start(
- FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
- this, &CompositorImpl::OnGpuChannelTimeout);
- return;
- }
-
- CreateOutputSurface();
+ CreateOutputSurface(nullptr);
}
void CompositorImpl::DidInitializeOutputSurface() {
@@ -586,7 +530,8 @@ void CompositorImpl::DidFailToInitializeOutputSurface() {
RequestNewOutputSurface();
}
-void CompositorImpl::CreateOutputSurface() {
+void CompositorImpl::CreateOutputSurface(
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
// We might have had a request from a LayerTreeHost that was then
// hidden (and hidden means we don't have a native surface).
// Also make sure we only handle this once.
@@ -595,7 +540,8 @@ void CompositorImpl::CreateOutputSurface() {
scoped_refptr<ContextProviderCommandBuffer> context_provider;
scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider =
- SharedVulkanContextProviderAndroid();
+ ContextProviderFactoryImpl::GetInstance()
+ ->GetSharedVulkanContextProviderAndroid();
std::unique_ptr<cc::OutputSurface> display_output_surface;
#if defined(ENABLE_VULKAN)
std::unique_ptr<VulkanOutputSurface> vulkan_surface;
@@ -611,6 +557,12 @@ void CompositorImpl::CreateOutputSurface() {
}
#endif
+ if (!gpu_channel_host) {
+ ContextProviderFactoryImpl::GetInstance()->RequestGpuChannel(base::Bind(
+ &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr()));
+ return;
+ }
+
if (!display_output_surface) {
// This is used for the browser compositor (offscreen) and for the display
// compositor (onscreen), so ask for capabilities needed by either one.
@@ -647,17 +599,6 @@ void CompositorImpl::CreateOutputSurface() {
DCHECK(window_);
DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle);
- BrowserGpuChannelHostFactory* factory =
- BrowserGpuChannelHostFactory::instance();
- scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
- factory->GetGpuChannel());
- // If the channel was already lost, we'll get null back here and need to
- // try again.
- if (!gpu_channel_host) {
- RequestNewOutputSurface();
- return;
- }
-
GURL url("chrome://gpu/CompositorImpl::CreateOutputSurface");
constexpr bool automatic_flushes = false;
constexpr bool support_locking = false;
@@ -693,7 +634,8 @@ void CompositorImpl::CreateOutputSurface() {
base::Unretained(this))));
}
- cc::SurfaceManager* manager = GetSurfaceManager();
+ cc::SurfaceManager* manager =
+ ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
auto* task_runner = base::ThreadTaskRunnerHandle::Get().get();
std::unique_ptr<ExternalBeginFrameSource> begin_frame_source(
new ExternalBeginFrameSource(this));

Powered by Google App Engine
This is Rietveld 408576698