Commit 1a7a5129 authored by jbauman's avatar jbauman Committed by Commit bot

Make browser GPU channel creation async.

This may help startup time.

Review URL: https://codereview.chromium.org/648413004

Cr-Commit-Position: refs/heads/master@{#301512}
parent 0b8c9d7f
......@@ -97,7 +97,11 @@ GpuProcessTransportFactory::~GpuProcessTransportFactory() {
scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
GpuProcessTransportFactory::CreateOffscreenCommandBufferContext() {
return CreateContextCommon(0);
CauseForGpuLaunch cause =
CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
scoped_refptr<GpuChannelHost> gpu_channel_host(
BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause));
return CreateContextCommon(gpu_channel_host, 0);
}
scoped_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice(
......@@ -135,11 +139,13 @@ scoped_ptr<cc::OverlayCandidateValidator> CreateOverlayCandidateValidator(
return scoped_ptr<cc::OverlayCandidateValidator>();
}
scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
ui::Compositor* compositor, bool software_fallback) {
PerCompositorData* data = per_compositor_data_[compositor];
void GpuProcessTransportFactory::CreateOutputSurface(
base::WeakPtr<ui::Compositor> compositor,
bool software_fallback) {
DCHECK(!!compositor);
PerCompositorData* data = per_compositor_data_[compositor.get()];
if (!data)
data = CreatePerCompositorData(compositor);
data = CreatePerCompositorData(compositor.get());
bool create_software_renderer = software_fallback;
#if defined(OS_CHROMEOS)
......@@ -151,12 +157,37 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
create_software_renderer = true;
}
#endif
scoped_refptr<ContextProviderCommandBuffer> context_provider;
if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor())
create_software_renderer = true;
if (!create_software_renderer) {
CauseForGpuLaunch cause =
CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
cause,
base::Bind(&GpuProcessTransportFactory::EstablishedGpuChannel,
callback_factory_.GetWeakPtr(),
compositor,
create_software_renderer));
} else {
EstablishedGpuChannel(compositor, create_software_renderer);
}
}
void GpuProcessTransportFactory::EstablishedGpuChannel(
base::WeakPtr<ui::Compositor> compositor,
bool create_software_renderer) {
if (!compositor)
return;
PerCompositorData* data = per_compositor_data_[compositor.get()];
DCHECK(data);
scoped_refptr<GpuChannelHost> gpu_channel_host =
BrowserGpuChannelHostFactory::instance()->GetGpuChannel();
scoped_refptr<ContextProviderCommandBuffer> context_provider;
if (gpu_channel_host.get() && !create_software_renderer) {
context_provider = ContextProviderCommandBuffer::Create(
GpuProcessTransportFactory::CreateContextCommon(data->surface_id),
GpuProcessTransportFactory::CreateContextCommon(gpu_channel_host,
data->surface_id),
"Compositor");
}
......@@ -186,14 +217,14 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
display_surface =
make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface(
output_surface_proxy_,
CreateSoftwareOutputDevice(compositor),
per_compositor_data_[compositor]->surface_id,
CreateSoftwareOutputDevice(compositor.get()),
data->surface_id,
&output_surface_map_,
compositor->vsync_manager()));
} else {
display_surface = make_scoped_ptr(new GpuBrowserCompositorOutputSurface(
context_provider,
per_compositor_data_[compositor]->surface_id,
data->surface_id,
&output_surface_map_,
compositor->vsync_manager(),
CreateOverlayCandidateValidator(compositor->widget())));
......@@ -207,7 +238,8 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
display_client->set_surface_output_surface(output_surface.get());
output_surface->set_display_client(display_client.get());
data->display_client = display_client.Pass();
return output_surface.Pass();
compositor->SetOutputSurface(output_surface.Pass());
return;
}
if (!context_provider.get()) {
......@@ -216,12 +248,15 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
" compositing with browser threaded compositing. Aborting.";
}
return make_scoped_ptr(new SoftwareBrowserCompositorOutputSurface(
scoped_ptr<SoftwareBrowserCompositorOutputSurface> surface(
new SoftwareBrowserCompositorOutputSurface(
output_surface_proxy_,
CreateSoftwareOutputDevice(compositor),
per_compositor_data_[compositor]->surface_id,
CreateSoftwareOutputDevice(compositor.get()),
data->surface_id,
&output_surface_map_,
compositor->vsync_manager()));
compositor->SetOutputSurface(surface.Pass());
return;
}
scoped_ptr<BrowserCompositorOutputSurface> surface;
......@@ -229,7 +264,7 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
if (ui::SurfaceFactoryOzone::GetInstance()->CanShowPrimaryPlaneAsOverlay()) {
surface.reset(new GpuSurfacelessBrowserCompositorOutputSurface(
context_provider,
per_compositor_data_[compositor]->surface_id,
data->surface_id,
&output_surface_map_,
compositor->vsync_manager(),
CreateOverlayCandidateValidator(compositor->widget()),
......@@ -240,7 +275,7 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
if (!surface)
surface.reset(new GpuBrowserCompositorOutputSurface(
context_provider,
per_compositor_data_[compositor]->surface_id,
data->surface_id,
&output_surface_map_,
compositor->vsync_manager(),
CreateOverlayCandidateValidator(compositor->widget())));
......@@ -248,7 +283,7 @@ scoped_ptr<cc::OutputSurface> GpuProcessTransportFactory::CreateOutputSurface(
if (data->reflector.get())
data->reflector->ReattachToOutputSurfaceFromMainThread(surface.get());
return surface.Pass();
compositor->SetOutputSurface(surface.Pass());
}
scoped_refptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector(
......@@ -417,7 +452,9 @@ GpuProcessTransportFactory::CreatePerCompositorData(
}
scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
GpuProcessTransportFactory::CreateContextCommon(int surface_id) {
GpuProcessTransportFactory::CreateContextCommon(
scoped_refptr<GpuChannelHost> gpu_channel_host,
int surface_id) {
if (!GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor())
return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
blink::WebGraphicsContext3D::Attributes attrs;
......@@ -427,10 +464,6 @@ GpuProcessTransportFactory::CreateContextCommon(int surface_id) {
attrs.antialias = false;
attrs.noAutomaticFlushes = true;
bool lose_context_when_out_of_memory = true;
CauseForGpuLaunch cause =
CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE;
scoped_refptr<GpuChannelHost> gpu_channel_host(
BrowserGpuChannelHostFactory::instance()->EstablishGpuChannelSync(cause));
if (!gpu_channel_host.get()) {
LOG(ERROR) << "Failed to establish GPU channel.";
return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
......
......@@ -13,6 +13,7 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "content/browser/compositor/image_transport_factory.h"
#include "content/common/gpu/client/gpu_channel_host.h"
#include "ui/compositor/compositor.h"
namespace base {
......@@ -43,8 +44,7 @@ class GpuProcessTransportFactory
CreateOffscreenCommandBufferContext();
// ui::ContextFactory implementation.
scoped_ptr<cc::OutputSurface> CreateOutputSurface(
ui::Compositor* compositor,
void CreateOutputSurface(base::WeakPtr<ui::Compositor> compositor,
bool software_fallback) override;
scoped_refptr<ui::Reflector> CreateReflector(ui::Compositor* source,
ui::Layer* target) override;
......@@ -72,8 +72,11 @@ class GpuProcessTransportFactory
struct PerCompositorData;
PerCompositorData* CreatePerCompositorData(ui::Compositor* compositor);
scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
CreateContextCommon(int surface_id);
void EstablishedGpuChannel(base::WeakPtr<ui::Compositor> compositor,
bool create_software_renderer);
scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateContextCommon(
scoped_refptr<GpuChannelHost> gpu_channel_host,
int surface_id);
void OnLostMainThreadSharedContextInsideCallback();
void OnLostMainThreadSharedContext();
......
......@@ -20,10 +20,10 @@ SurfaceContextFactory::SurfaceContextFactory(Shell* shell, View* view)
SurfaceContextFactory::~SurfaceContextFactory() {
}
scoped_ptr<cc::OutputSurface> SurfaceContextFactory::CreateOutputSurface(
ui::Compositor* compositor,
void SurfaceContextFactory::CreateOutputSurface(
base::WeakPtr<ui::Compositor> compositor,
bool software_fallback) {
return surface_binding_.CreateOutputSurface();
compositor->SetOutputSurface(surface_binding_.CreateOutputSurface());
}
scoped_refptr<ui::Reflector> SurfaceContextFactory::CreateReflector(
......
......@@ -19,8 +19,7 @@ class SurfaceContextFactory : public ui::ContextFactory {
private:
// ContextFactory:
scoped_ptr<cc::OutputSurface> CreateOutputSurface(
ui::Compositor* compositor,
void CreateOutputSurface(base::WeakPtr<ui::Compositor> compositor,
bool software_fallback) override;
scoped_refptr<ui::Reflector> CreateReflector(
ui::Compositor* mirrored_compositor,
......
......@@ -107,7 +107,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget,
draw_on_compositing_end_(false),
swap_state_(SWAP_NONE),
layer_animator_collection_(this),
schedule_draw_factory_(this) {
weak_ptr_factory_(this) {
root_web_layer_ = cc::Layer::Create();
CommandLine* command_line = CommandLine::ForCurrentProcess();
......@@ -200,6 +200,11 @@ Compositor::~Compositor() {
context_factory_->RemoveCompositor(this);
}
void Compositor::SetOutputSurface(
scoped_ptr<cc::OutputSurface> output_surface) {
host_->SetOutputSurface(output_surface.Pass());
}
void Compositor::ScheduleDraw() {
if (compositor_thread_loop_.get()) {
host_->SetNeedsCommit();
......@@ -207,7 +212,7 @@ void Compositor::ScheduleDraw() {
defer_draw_scheduling_ = true;
task_runner_->PostTask(
FROM_HERE,
base::Bind(&Compositor::Draw, schedule_draw_factory_.GetWeakPtr()));
base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr()));
}
}
......@@ -366,8 +371,8 @@ void Compositor::Layout() {
}
void Compositor::RequestNewOutputSurface(bool fallback) {
host_->SetOutputSurface(
context_factory_->CreateOutputSurface(this, fallback));
context_factory_->CreateOutputSurface(weak_ptr_factory_.GetWeakPtr(),
fallback);
}
void Compositor::DidCommit() {
......
......@@ -69,8 +69,8 @@ class COMPOSITOR_EXPORT ContextFactory {
// Creates an output surface for the given compositor. The factory may keep
// per-compositor data (e.g. a shared context), that needs to be cleaned up
// by calling RemoveCompositor when the compositor gets destroyed.
virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface(
Compositor* compositor, bool software_fallback) = 0;
virtual void CreateOutputSurface(base::WeakPtr<Compositor> compositor,
bool software_fallback) = 0;
// Creates a reflector that copies the content of the |mirrored_compositor|
// onto |mirroing_layer|.
......@@ -147,6 +147,8 @@ class COMPOSITOR_EXPORT Compositor
ui::ContextFactory* context_factory() { return context_factory_; }
void SetOutputSurface(scoped_ptr<cc::OutputSurface> surface);
// Schedules a redraw of the layer tree associated with this compositor.
void ScheduleDraw();
......@@ -337,7 +339,7 @@ class COMPOSITOR_EXPORT Compositor
LayerAnimatorCollection layer_animator_collection_;
base::WeakPtrFactory<Compositor> schedule_draw_factory_;
base::WeakPtrFactory<Compositor> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(Compositor);
};
......
......@@ -39,8 +39,8 @@ InProcessContextFactory::InProcessContextFactory()
InProcessContextFactory::~InProcessContextFactory() {}
scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface(
Compositor* compositor,
void InProcessContextFactory::CreateOutputSurface(
base::WeakPtr<Compositor> compositor,
bool software_fallback) {
DCHECK(!software_fallback);
blink::WebGraphicsContext3D::Attributes attrs;
......@@ -60,7 +60,8 @@ scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface(
scoped_refptr<ContextProviderInProcess> context_provider =
ContextProviderInProcess::Create(context3d.Pass(), "UICompositor");
return make_scoped_ptr(new cc::PixelTestOutputSurface(context_provider));
compositor->SetOutputSurface(
make_scoped_ptr(new cc::PixelTestOutputSurface(context_provider)));
}
scoped_refptr<Reflector> InProcessContextFactory::CreateReflector(
......
......@@ -27,8 +27,7 @@ class InProcessContextFactory : public ContextFactory {
~InProcessContextFactory() override;
// ContextFactory implementation
scoped_ptr<cc::OutputSurface> CreateOutputSurface(
Compositor* compositor,
void CreateOutputSurface(base::WeakPtr<Compositor> compositor,
bool software_fallback) override;
scoped_refptr<Reflector> CreateReflector(Compositor* mirrored_compositor,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment