Commit 1c63949d authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Establish channel directly from viz::GpuClient

Now that viz::mojom::GpuHost implementation has moved out of content,
viz::GpuClient can directly call on that to establish a gpu channel and
we can remove the functionality from GpuClientDelegate.

BUG=709332

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: Ied5a8ead810973068190e3ce485609f68f5826d5
Reviewed-on: https://chromium-review.googlesource.com/1188883
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Reviewed-by: default avatarJonathan Backer <backer@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587852}
parent 5de034ba
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/viz/host/gpu_client.h" #include "components/viz/host/gpu_client.h"
#include "base/numerics/checked_math.h" #include "base/numerics/checked_math.h"
#include "components/viz/host/gpu_host_impl.h"
#include "components/viz/host/host_gpu_memory_buffer_manager.h" #include "components/viz/host/host_gpu_memory_buffer_manager.h"
#include "gpu/ipc/client/gpu_channel_host.h" #include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl.h" #include "gpu/ipc/common/gpu_memory_buffer_impl.h"
...@@ -79,14 +80,14 @@ void GpuClient::OnEstablishGpuChannel( ...@@ -79,14 +80,14 @@ void GpuClient::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,
GpuClientDelegate::EstablishGpuChannelStatus status) { GpuHostImpl::EstablishChannelStatus status) {
DCHECK_EQ(channel_handle.is_valid(), DCHECK_EQ(channel_handle.is_valid(),
status == GpuClientDelegate::EstablishGpuChannelStatus::kSuccess); status == GpuHostImpl::EstablishChannelStatus::kSuccess);
gpu_channel_requested_ = false; gpu_channel_requested_ = false;
EstablishGpuChannelCallback callback = std::move(callback_); EstablishGpuChannelCallback callback = std::move(callback_);
DCHECK(!callback_); DCHECK(!callback_);
if (status == GpuClientDelegate::EstablishGpuChannelStatus::kGpuHostInvalid) { if (status == GpuHostImpl::EstablishChannelStatus::kGpuHostInvalid) {
// GPU process may have crashed or been killed. Try again. // GPU process may have crashed or been killed. Try again.
EstablishGpuChannel(std::move(callback)); EstablishGpuChannel(std::move(callback));
return; return;
...@@ -97,7 +98,7 @@ void GpuClient::OnEstablishGpuChannel( ...@@ -97,7 +98,7 @@ void GpuClient::OnEstablishGpuChannel(
gpu_feature_info); gpu_feature_info);
return; return;
} }
if (status == GpuClientDelegate::EstablishGpuChannelStatus::kSuccess) { if (status == GpuHostImpl::EstablishChannelStatus::kSuccess) {
// This is the case we pre-establish a channel before a request arrives. // This is the case we pre-establish a channel before a request arrives.
// Cache the channel for a future request. // Cache the channel for a future request.
channel_handle_ = std::move(channel_handle); channel_handle_ = std::move(channel_handle);
...@@ -136,26 +137,39 @@ void GpuClient::EstablishGpuChannel(EstablishGpuChannelCallback callback) { ...@@ -136,26 +137,39 @@ void GpuClient::EstablishGpuChannel(EstablishGpuChannelCallback callback) {
} }
return; return;
} }
GpuHostImpl* gpu_host = delegate_->EnsureGpuHost();
if (!gpu_host) {
if (callback) {
std::move(callback).Run(client_id_, mojo::ScopedMessagePipeHandle(),
gpu::GPUInfo(), gpu::GpuFeatureInfo());
}
return;
}
callback_ = std::move(callback); callback_ = std::move(callback);
if (gpu_channel_requested_) if (gpu_channel_requested_)
return; return;
gpu_channel_requested_ = true; gpu_channel_requested_ = true;
delegate_->EstablishGpuChannel( const bool is_gpu_host = false;
client_id_, client_tracing_id_, gpu_host->EstablishGpuChannel(
client_id_, client_tracing_id_, is_gpu_host,
base::BindOnce(&GpuClient::OnEstablishGpuChannel, base::BindOnce(&GpuClient::OnEstablishGpuChannel,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
void GpuClient::CreateJpegDecodeAccelerator( void GpuClient::CreateJpegDecodeAccelerator(
media::mojom::JpegDecodeAcceleratorRequest jda_request) { media::mojom::JpegDecodeAcceleratorRequest jda_request) {
if (auto* gpu_service = delegate_->EnsureGpuService()) if (auto* gpu_host = delegate_->EnsureGpuHost()) {
gpu_service->CreateJpegDecodeAccelerator(std::move(jda_request)); gpu_host->gpu_service()->CreateJpegDecodeAccelerator(
std::move(jda_request));
}
} }
void GpuClient::CreateVideoEncodeAcceleratorProvider( void GpuClient::CreateVideoEncodeAcceleratorProvider(
media::mojom::VideoEncodeAcceleratorProviderRequest vea_provider_request) { media::mojom::VideoEncodeAcceleratorProviderRequest vea_provider_request) {
if (auto* gpu_service = delegate_->EnsureGpuService()) { if (auto* gpu_host = delegate_->EnsureGpuHost()) {
gpu_service->CreateVideoEncodeAcceleratorProvider( gpu_host->gpu_service()->CreateVideoEncodeAcceleratorProvider(
std::move(vea_provider_request)); std::move(vea_provider_request));
} }
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/viz/host/gpu_client_delegate.h" #include "components/viz/host/gpu_client_delegate.h"
#include "components/viz/host/gpu_host_impl.h"
#include "components/viz/host/viz_host_export.h" #include "components/viz/host/viz_host_export.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "services/ws/public/mojom/gpu.mojom.h" #include "services/ws/public/mojom/gpu.mojom.h"
...@@ -65,11 +66,10 @@ class VIZ_HOST_EXPORT GpuClient : public ws::mojom::GpuMemoryBufferFactory, ...@@ -65,11 +66,10 @@ class VIZ_HOST_EXPORT GpuClient : public ws::mojom::GpuMemoryBufferFactory,
kConnectionLost kConnectionLost
}; };
void OnError(ErrorReason reason); void OnError(ErrorReason reason);
void OnEstablishGpuChannel( 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,
GpuClientDelegate::EstablishGpuChannelStatus status); GpuHostImpl::EstablishChannelStatus status);
void OnCreateGpuMemoryBuffer(CreateGpuMemoryBufferCallback callback, void OnCreateGpuMemoryBuffer(CreateGpuMemoryBufferCallback callback,
gfx::GpuMemoryBufferHandle handle); gfx::GpuMemoryBufferHandle handle);
void ClearCallback(); void ClearCallback();
......
...@@ -8,50 +8,21 @@ ...@@ -8,50 +8,21 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "mojo/public/cpp/system/message_pipe.h" #include "mojo/public/cpp/system/message_pipe.h"
namespace gpu {
struct GPUInfo;
struct GpuFeatureInfo;
} // namespace gpu
namespace viz { namespace viz {
namespace mojom {
class GpuService;
}
class GpuHostImpl;
class HostGpuMemoryBufferManager; class HostGpuMemoryBufferManager;
// Delegate interface that GpuClientImpl uses to get the current GpuService // Delegate interface that GpuClient uses to get the current GpuHost and/or
// instance and establish GPU channel for a client. These functions are // GpuMemoryBufferManager instances. These functions are guaranteed to be called
// guaranteed to be called on the thread corresponding to GpuClientImpl's task // on the thread corresponding to GpuClient's task runner.
// runner.
class GpuClientDelegate { class GpuClientDelegate {
public: public:
enum class EstablishGpuChannelStatus {
kGpuAccessDenied, // GPU access was not allowed.
kGpuHostInvalid, // Request failed because the gpu host became invalid
// while processing the request (e.g. the gpu process may
// have been killed). The caller should normally make
// another request to establish a new channel.
kSuccess,
};
using EstablishGpuChannelCallback =
base::OnceCallback<void(mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo&,
const gpu::GpuFeatureInfo&,
EstablishGpuChannelStatus status)>;
virtual ~GpuClientDelegate() {} virtual ~GpuClientDelegate() {}
// Returns the current instance of GPU service. If GPU service is not running, // Returns the current instance of GpuHostImpl. If GPU service is not running,
// tries to launch it. If the launch is unsuccessful, returns nullptr. // tries to launch it. If the launch is unsuccessful, returns nullptr.
virtual mojom::GpuService* EnsureGpuService() = 0; virtual GpuHostImpl* EnsureGpuHost() = 0;
// Sends a request to establish a GPU channel for a client to the GPU service.
// If GPU service is not running, tries to launch it and send the request.
virtual void EstablishGpuChannel(int client_id,
uint64_t client_tracing_id,
EstablishGpuChannelCallback callback) = 0;
// Returns the current HostGpuMemoryBufferManager instance. // Returns the current HostGpuMemoryBufferManager instance.
virtual HostGpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0; virtual HostGpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0;
......
...@@ -4,76 +4,21 @@ ...@@ -4,76 +4,21 @@
#include "content/browser/gpu/browser_gpu_client_delegate.h" #include "content/browser/gpu/browser_gpu_client_delegate.h"
#include <utility>
#include "components/viz/host/gpu_host_impl.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h" #include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_info.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace content { namespace content {
namespace {
void OnEstablishGpuChannel(
viz::GpuClientDelegate::EstablishGpuChannelCallback callback,
mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info,
viz::GpuHostImpl::EstablishChannelStatus status) {
if (!callback)
return;
viz::GpuClientDelegate::EstablishGpuChannelStatus delegate_status;
switch (status) {
case viz::GpuHostImpl::EstablishChannelStatus::kGpuAccessDenied:
delegate_status =
viz::GpuClientDelegate::EstablishGpuChannelStatus::kGpuAccessDenied;
break;
case viz::GpuHostImpl::EstablishChannelStatus::kGpuHostInvalid:
delegate_status =
viz::GpuClientDelegate::EstablishGpuChannelStatus::kGpuHostInvalid;
break;
case viz::GpuHostImpl::EstablishChannelStatus::kSuccess:
delegate_status =
viz::GpuClientDelegate::EstablishGpuChannelStatus::kSuccess;
break;
}
std::move(callback).Run(std::move(channel_handle), gpu_info, gpu_feature_info,
delegate_status);
}
} // namespace
BrowserGpuClientDelegate::BrowserGpuClientDelegate() = default; BrowserGpuClientDelegate::BrowserGpuClientDelegate() = default;
BrowserGpuClientDelegate::~BrowserGpuClientDelegate() = default; BrowserGpuClientDelegate::~BrowserGpuClientDelegate() = default;
viz::mojom::GpuService* BrowserGpuClientDelegate::EnsureGpuService() { viz::GpuHostImpl* BrowserGpuClientDelegate::EnsureGpuHost() {
if (auto* host = GpuProcessHost::Get()) if (auto* host = GpuProcessHost::Get())
return host->gpu_service(); return host->gpu_host();
return nullptr; return nullptr;
} }
void BrowserGpuClientDelegate::EstablishGpuChannel(
int client_id,
uint64_t client_tracing_id,
EstablishGpuChannelCallback callback) {
auto* host = GpuProcessHost::Get();
if (!host) {
std::move(callback).Run(mojo::ScopedMessagePipeHandle(), gpu::GPUInfo(),
gpu::GpuFeatureInfo(),
EstablishGpuChannelStatus::kGpuAccessDenied);
return;
}
const bool is_gpu_host = false;
host->gpu_host()->EstablishGpuChannel(
client_id, client_tracing_id, is_gpu_host,
base::BindOnce(&OnEstablishGpuChannel, std::move(callback)));
}
viz::HostGpuMemoryBufferManager* viz::HostGpuMemoryBufferManager*
BrowserGpuClientDelegate::GetGpuMemoryBufferManager() { BrowserGpuClientDelegate::GetGpuMemoryBufferManager() {
return GpuMemoryBufferManagerSingleton::GetInstance(); return GpuMemoryBufferManagerSingleton::GetInstance();
......
...@@ -15,10 +15,7 @@ class BrowserGpuClientDelegate : public viz::GpuClientDelegate { ...@@ -15,10 +15,7 @@ class BrowserGpuClientDelegate : public viz::GpuClientDelegate {
~BrowserGpuClientDelegate() override; ~BrowserGpuClientDelegate() override;
// GpuClientDelegate: // GpuClientDelegate:
viz::mojom::GpuService* EnsureGpuService() override; viz::GpuHostImpl* EnsureGpuHost() override;
void EstablishGpuChannel(int client_id,
uint64_t client_tracing_id,
EstablishGpuChannelCallback callback) override;
viz::HostGpuMemoryBufferManager* GetGpuMemoryBufferManager() override; viz::HostGpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
private: private:
......
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