Commit e36bfd5b authored by Zhenyao Mo's avatar Zhenyao Mo Committed by Commit Bot

[reland] PreEstablish a GPU channel in RenderProcessHostImpl before renderer asks for one.

This CL was originally reviewed in
https://chromium-review.googlesource.com/c/chromium/src/+/773538.

Patchset 1 is exactly the same. Later patches are new fixes.

BUG=783512
TEST=bots
R=piman@chromium.org
TBR=sadrul@chromium.org

Change-Id: If664ad636da5382fad35a49766e3a3162031f1ab
Reviewed-on: https://chromium-review.googlesource.com/801333
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520719}
parent 58eb5351
...@@ -21,6 +21,7 @@ GpuClient::GpuClient(int render_process_id) ...@@ -21,6 +21,7 @@ GpuClient::GpuClient(int render_process_id)
} }
GpuClient::~GpuClient() { GpuClient::~GpuClient() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
bindings_.CloseAllBindings(); bindings_.CloseAllBindings();
OnError(); OnError();
} }
...@@ -30,6 +31,7 @@ void GpuClient::Add(ui::mojom::GpuRequest request) { ...@@ -30,6 +31,7 @@ void GpuClient::Add(ui::mojom::GpuRequest request) {
} }
void GpuClient::OnError() { void GpuClient::OnError() {
ClearCallback();
if (!bindings_.empty()) if (!bindings_.empty())
return; return;
BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager =
...@@ -38,21 +40,43 @@ void GpuClient::OnError() { ...@@ -38,21 +40,43 @@ void GpuClient::OnError() {
gpu_memory_buffer_manager->ProcessRemoved(render_process_id_); gpu_memory_buffer_manager->ProcessRemoved(render_process_id_);
} }
void GpuClient::PreEstablishGpuChannel() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&GpuClient::EstablishGpuChannel, base::Unretained(this),
EstablishGpuChannelCallback()));
}
void GpuClient::OnEstablishGpuChannel( void GpuClient::OnEstablishGpuChannel(
const EstablishGpuChannelCallback& callback,
mojo::ScopedMessagePipeHandle channel_handle, mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info, const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info, const gpu::GpuFeatureInfo& gpu_feature_info,
GpuProcessHost::EstablishChannelStatus status) { GpuProcessHost::EstablishChannelStatus status) {
DCHECK_EQ(channel_handle.is_valid(), DCHECK_EQ(channel_handle.is_valid(),
status == GpuProcessHost::EstablishChannelStatus::SUCCESS); status == GpuProcessHost::EstablishChannelStatus::SUCCESS);
gpu_channel_requested_ = false;
EstablishGpuChannelCallback callback = std::move(callback_);
DCHECK(!callback_);
if (status == GpuProcessHost::EstablishChannelStatus::GPU_HOST_INVALID) { if (status == GpuProcessHost::EstablishChannelStatus::GPU_HOST_INVALID) {
// GPU process may have crashed or been killed. Try again. // GPU process may have crashed or been killed. Try again.
EstablishGpuChannel(callback); EstablishGpuChannel(callback);
return; return;
} }
callback.Run(render_process_id_, std::move(channel_handle), gpu_info, if (callback) {
gpu_feature_info); // A request is waiting.
callback.Run(render_process_id_, std::move(channel_handle), gpu_info,
gpu_feature_info);
return;
}
if (status == GpuProcessHost::EstablishChannelStatus::SUCCESS) {
// This is the case we pre-establish a channel before a request arrives.
// Cache the channel for a future request.
channel_handle_ = std::move(channel_handle);
gpu_info_ = gpu_info;
gpu_feature_info_ = gpu_feature_info;
}
} }
void GpuClient::OnCreateGpuMemoryBuffer( void GpuClient::OnCreateGpuMemoryBuffer(
...@@ -61,17 +85,44 @@ void GpuClient::OnCreateGpuMemoryBuffer( ...@@ -61,17 +85,44 @@ void GpuClient::OnCreateGpuMemoryBuffer(
callback.Run(handle); callback.Run(handle);
} }
void GpuClient::ClearCallback() {
if (!callback_)
return;
EstablishGpuChannelCallback callback = std::move(callback_);
callback.Run(render_process_id_, mojo::ScopedMessagePipeHandle(),
gpu::GPUInfo(), gpu::GpuFeatureInfo());
DCHECK(!callback_);
}
void GpuClient::EstablishGpuChannel( void GpuClient::EstablishGpuChannel(
const EstablishGpuChannelCallback& callback) { const EstablishGpuChannelCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// At most one channel should be requested. So clear previous request first.
ClearCallback();
if (channel_handle_.is_valid()) {
// If a channel has been pre-established and cached,
// 1) if callback is valid, return it right away.
// 2) if callback is empty, it's PreEstablishGpyChannel() being called
// more than once, no need to do anything.
if (callback) {
callback.Run(render_process_id_, std::move(channel_handle_), gpu_info_,
gpu_feature_info_);
DCHECK(!channel_handle_.is_valid());
}
return;
}
GpuProcessHost* host = GpuProcessHost::Get(); GpuProcessHost* host = GpuProcessHost::Get();
if (!host) { if (!host) {
OnEstablishGpuChannel( if (callback) {
callback, mojo::ScopedMessagePipeHandle(), gpu::GPUInfo(), callback.Run(render_process_id_, mojo::ScopedMessagePipeHandle(),
gpu::GpuFeatureInfo(), gpu::GPUInfo(), gpu::GpuFeatureInfo());
GpuProcessHost::EstablishChannelStatus::GPU_ACCESS_DENIED); }
return; return;
} }
callback_ = callback;
if (gpu_channel_requested_)
return;
gpu_channel_requested_ = true;
bool preempts = false; bool preempts = false;
bool allow_view_command_buffers = false; bool allow_view_command_buffers = false;
bool allow_real_time_streams = false; bool allow_real_time_streams = false;
...@@ -80,8 +131,8 @@ void GpuClient::EstablishGpuChannel( ...@@ -80,8 +131,8 @@ void GpuClient::EstablishGpuChannel(
ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(
render_process_id_), render_process_id_),
preempts, allow_view_command_buffers, allow_real_time_streams, preempts, allow_view_command_buffers, allow_real_time_streams,
base::Bind(&GpuClient::OnEstablishGpuChannel, weak_factory_.GetWeakPtr(), base::Bind(&GpuClient::OnEstablishGpuChannel,
callback)); weak_factory_.GetWeakPtr()));
} }
void GpuClient::CreateJpegDecodeAccelerator( void GpuClient::CreateJpegDecodeAccelerator(
......
...@@ -19,15 +19,17 @@ class GpuClient : public ui::mojom::Gpu { ...@@ -19,15 +19,17 @@ class GpuClient : public ui::mojom::Gpu {
void Add(ui::mojom::GpuRequest request); void Add(ui::mojom::GpuRequest request);
void PreEstablishGpuChannel();
private: private:
void OnError(); void OnError();
void OnEstablishGpuChannel(const EstablishGpuChannelCallback& callback, void OnEstablishGpuChannel(mojo::ScopedMessagePipeHandle channel_handle,
mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info, const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info, const gpu::GpuFeatureInfo& gpu_feature_info,
GpuProcessHost::EstablishChannelStatus status); GpuProcessHost::EstablishChannelStatus status);
void OnCreateGpuMemoryBuffer(const CreateGpuMemoryBufferCallback& callback, void OnCreateGpuMemoryBuffer(const CreateGpuMemoryBufferCallback& callback,
const gfx::GpuMemoryBufferHandle& handle); const gfx::GpuMemoryBufferHandle& handle);
void ClearCallback();
// ui::mojom::Gpu overrides: // ui::mojom::Gpu overrides:
void EstablishGpuChannel( void EstablishGpuChannel(
...@@ -48,6 +50,11 @@ class GpuClient : public ui::mojom::Gpu { ...@@ -48,6 +50,11 @@ class GpuClient : public ui::mojom::Gpu {
const int render_process_id_; const int render_process_id_;
mojo::BindingSet<ui::mojom::Gpu> bindings_; mojo::BindingSet<ui::mojom::Gpu> bindings_;
bool gpu_channel_requested_ = false;
EstablishGpuChannelCallback callback_;
mojo::ScopedMessagePipeHandle channel_handle_;
gpu::GPUInfo gpu_info_;
gpu::GpuFeatureInfo gpu_feature_info_;
base::WeakPtrFactory<GpuClient> weak_factory_; base::WeakPtrFactory<GpuClient> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuClient); DISALLOW_COPY_AND_ASSIGN(GpuClient);
......
...@@ -209,6 +209,7 @@ ...@@ -209,6 +209,7 @@
#include "third_party/WebKit/public/public_features.h" #include "third_party/WebKit/public/public_features.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/display/display_switches.h" #include "ui/display/display_switches.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#include "ui/gl/gpu_switching_manager.h" #include "ui/gl/gpu_switching_manager.h"
...@@ -1354,6 +1355,9 @@ RenderProcessHostImpl::RenderProcessHostImpl( ...@@ -1354,6 +1355,9 @@ RenderProcessHostImpl::RenderProcessHostImpl(
AddObserver(indexed_db_factory_.get()); AddObserver(indexed_db_factory_.get());
InitializeChannelProxy(); InitializeChannelProxy();
if (!switches::IsMusHostingViz())
gpu_client_.reset(new GpuClient(GetID()));
} }
// static // static
...@@ -1448,6 +1452,9 @@ bool RenderProcessHostImpl::Init() { ...@@ -1448,6 +1452,9 @@ bool RenderProcessHostImpl::Init() {
if (renderer_path.empty()) if (renderer_path.empty())
return false; return false;
if (gpu_client_)
gpu_client_->PreEstablishGpuChannel();
sent_render_process_ready_ = false; sent_render_process_ready_ = false;
// We may reach Init() during process death notification (e.g. // We may reach Init() during process death notification (e.g.
...@@ -1883,8 +1890,12 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { ...@@ -1883,8 +1890,12 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
base::WrapRefCounted( base::WrapRefCounted(
storage_partition_impl_->GetBackgroundFetchContext()))); storage_partition_impl_->GetBackgroundFetchContext())));
registry->AddInterface(base::Bind(&RenderProcessHostImpl::CreateMusGpuRequest, if (gpu_client_) {
base::Unretained(this))); // |gpu_client_| outlives the registry, because its destruction is posted to
// IO thread from the destructor of |this|.
registry->AddInterface(
base::Bind(&GpuClient::Add, base::Unretained(gpu_client_.get())));
}
registry->AddInterface( registry->AddInterface(
base::Bind( base::Bind(
...@@ -1991,13 +2002,6 @@ void RenderProcessHostImpl::GetBlobURLLoaderFactory( ...@@ -1991,13 +2002,6 @@ void RenderProcessHostImpl::GetBlobURLLoaderFactory(
std::move(request)); std::move(request));
} }
void RenderProcessHostImpl::CreateMusGpuRequest(ui::mojom::GpuRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!gpu_client_)
gpu_client_.reset(new GpuClient(GetID()));
gpu_client_->Add(std::move(request));
}
void RenderProcessHostImpl::CreateOffscreenCanvasProvider( void RenderProcessHostImpl::CreateOffscreenCanvasProvider(
blink::mojom::OffscreenCanvasProviderRequest request) { blink::mojom::OffscreenCanvasProviderRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -460,7 +460,6 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -460,7 +460,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
void BindRouteProvider(mojom::RouteProviderAssociatedRequest request); void BindRouteProvider(mojom::RouteProviderAssociatedRequest request);
void CreateMusGpuRequest(ui::mojom::GpuRequest request);
void CreateOffscreenCanvasProvider( void CreateOffscreenCanvasProvider(
blink::mojom::OffscreenCanvasProviderRequest request); blink::mojom::OffscreenCanvasProviderRequest request);
void BindFrameSinkProvider(mojom::FrameSinkProviderRequest request); void BindFrameSinkProvider(mojom::FrameSinkProviderRequest request);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "gpu/command_buffer/common/scheduling_priority.h" #include "gpu/command_buffer/common/scheduling_priority.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h" #include "mojo/public/cpp/bindings/sync_call_restrictions.h"
...@@ -236,6 +237,7 @@ void Gpu::EstablishGpuChannel( ...@@ -236,6 +237,7 @@ void Gpu::EstablishGpuChannel(
scoped_refptr<gpu::GpuChannelHost> Gpu::EstablishGpuChannelSync( scoped_refptr<gpu::GpuChannelHost> Gpu::EstablishGpuChannelSync(
bool* connection_error) { bool* connection_error) {
TRACE_EVENT0("mus", "Gpu::EstablishGpuChannelSync");
DCHECK(main_task_runner_->BelongsToCurrentThread()); DCHECK(main_task_runner_->BelongsToCurrentThread());
if (connection_error) if (connection_error)
*connection_error = false; *connection_error = false;
......
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