Commit 63d85e79 authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Add InitOzone() to viz::GpuHostImpl

Moving InitOzone() from content::GpuProcessHost to viz::GpuHostImpl as
part of moving viz::mojom::GpuHost implementation out of content. This
is a follow-up to https://crrev.com/c/1180658.

BUG=709332

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I022ee15c3a1f194313bf2566e9503e357cd46494
Reviewed-on: https://chromium-review.googlesource.com/1195151Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589178}
parent 711148fd
......@@ -20,6 +20,7 @@ include_rules = [
"+skia",
"+third_party/skia",
"+ui/accelerated_widget_mac",
"+ui/ozone/public",
]
specific_include_rules = {
......
......@@ -12,6 +12,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/threading/thread_checker.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/viz/common/features.h"
......@@ -22,7 +23,10 @@
#include "gpu/ipc/common/gpu_client_ids.h"
#include "gpu/ipc/host/shader_disk_cache.h"
#include "ipc/ipc_channel.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/font_render_params.h"
#include "ui/ozone/public/gpu_platform_support_host.h"
#include "ui/ozone/public/ozone_platform.h"
#if defined(OS_ANDROID)
#include "base/android/build_info.h"
......@@ -75,6 +79,30 @@ FontRenderParams& GetFontRenderParams() {
return *instance;
}
#if defined(USE_OZONE)
// Helper to register Mus/conventional thread bouncers for ozone startup.
void OzoneRegisterStartupCallbackHelper(
scoped_refptr<base::SingleThreadTaskRunner> host_thread_task_runner,
base::OnceCallback<void(ui::OzonePlatform*)> callback) {
// The callback registered in ozone can be called in any thread. So use an
// intermediary callback that bounces to the GpuHost thread if needed, before
// running the callback.
auto bounce_callback = base::BindOnce(
[](base::SingleThreadTaskRunner* host_thread_task_runner,
base::OnceCallback<void(ui::OzonePlatform*)> callback,
ui::OzonePlatform* platform) {
if (host_thread_task_runner->BelongsToCurrentThread()) {
std::move(callback).Run(platform);
} else {
host_thread_task_runner->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), platform));
}
},
base::RetainedRef(host_thread_task_runner), std::move(callback));
ui::OzonePlatform::RegisterStartupCallback(std::move(bounce_callback));
}
#endif // defined(USE_OZONE)
} // namespace
GpuHostImpl::InitParams::InitParams() = default;
......@@ -89,6 +117,7 @@ GpuHostImpl::GpuHostImpl(Delegate* delegate,
: delegate_(delegate),
channel_(channel),
params_(std::move(params)),
host_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
gpu_host_binding_(this),
weak_ptr_factory_(this) {
DCHECK(delegate_);
......@@ -108,6 +137,10 @@ GpuHostImpl::GpuHostImpl(Delegate* delegate,
mojo::MakeRequest(&gpu_service_ptr_), std::move(host_proxy),
std::move(discardable_manager_ptr), activity_flags_.CloneHandle(),
GetFontRenderParams().Get()->subpixel_rendering);
#if defined(USE_OZONE)
InitOzone();
#endif // defined(USE_OZONE)
}
GpuHostImpl::~GpuHostImpl() = default;
......@@ -242,12 +275,87 @@ void GpuHostImpl::SendOutstandingReplies() {
}
}
void GpuHostImpl::BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
delegate_->BindInterface(interface_name, std::move(interface_pipe));
}
mojom::GpuService* GpuHostImpl::gpu_service() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(gpu_service_ptr_.is_bound());
return gpu_service_ptr_.get();
}
#if defined(USE_OZONE)
void GpuHostImpl::InitOzone() {
// Ozone needs to send the primary DRM device to GPU service as early as
// possible to ensure the latter always has a valid device.
// https://crbug.com/608839
// If the OzonePlatform is not created yet, defer the callback until
// OzonePlatform instance is created.
bool using_mojo = true;
#if defined(OS_CHROMEOS)
using_mojo = features::IsOzoneDrmMojo();
#endif
if (using_mojo) {
// TODO(rjkroege): Remove the legacy IPC code paths when no longer
// necessary. https://crbug.com/806092
auto interface_binder = base::BindRepeating(&GpuHostImpl::BindInterface,
weak_ptr_factory_.GetWeakPtr());
auto terminate_callback = base::BindOnce(&GpuHostImpl::TerminateGpuProcess,
weak_ptr_factory_.GetWeakPtr());
auto startup_callback = base::BindOnce(
[](const base::RepeatingCallback<void(const std::string&,
mojo::ScopedMessagePipeHandle)>&
interface_binder,
base::OnceCallback<void(const std::string&)> terminate_callback,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> host_thread_task_runner,
ui::OzonePlatform* platform) {
DCHECK(host_thread_task_runner->BelongsToCurrentThread());
platform->GetGpuPlatformSupportHost()->OnGpuServiceLaunched(
main_thread_task_runner, host_thread_task_runner,
interface_binder, std::move(terminate_callback));
},
interface_binder, std::move(terminate_callback),
params_.main_thread_task_runner, host_thread_task_runner_);
OzoneRegisterStartupCallbackHelper(host_thread_task_runner_,
std::move(startup_callback));
} else {
auto send_callback = base::BindRepeating(
[](base::WeakPtr<GpuHostImpl> host, IPC::Message* message) {
if (host)
host->delegate_->SendGpuProcessMessage(message);
else
delete message;
},
weak_ptr_factory_.GetWeakPtr());
// Create the callback that should run on the current thread.
auto startup_callback = base::BindOnce(
[](int host_id,
const base::RepeatingCallback<void(IPC::Message*)>& send_callback,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> host_thread_task_runner,
ui::OzonePlatform* platform) {
DCHECK(host_thread_task_runner->BelongsToCurrentThread());
platform->GetGpuPlatformSupportHost()->OnGpuProcessLaunched(
host_id, main_thread_task_runner, host_thread_task_runner,
send_callback);
},
params_.restart_id, send_callback, params_.main_thread_task_runner,
host_thread_task_runner_);
OzoneRegisterStartupCallbackHelper(host_thread_task_runner_,
std::move(startup_callback));
}
}
void GpuHostImpl::TerminateGpuProcess(const std::string& message) {
delegate_->TerminateGpuProcess(message);
}
#endif // defined(USE_OZONE)
std::string GpuHostImpl::GetShaderPrefixKey() {
if (shader_prefix_key_.empty()) {
const gpu::GPUInfo& info = delegate_->GetGPUInfo();
......
......@@ -78,6 +78,16 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
virtual void BindDiscardableMemoryRequest(
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest
request) = 0;
virtual void BindInterface(
const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) = 0;
#if defined(USE_OZONE)
virtual void TerminateGpuProcess(const std::string& message) = 0;
// TODO(https://crbug.com/806092): Remove this when legacy IPC-based Ozone
// is removed.
virtual void SendGpuProcessMessage(IPC::Message* message) = 0;
#endif
protected:
virtual ~Delegate() {}
......@@ -103,6 +113,9 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
// Number of frames to CompositorFrame activation deadline.
base::Optional<uint32_t> deadline_to_synchronize_surfaces = base::nullopt;
// Task runner corresponding to the main thread.
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner;
};
enum class EstablishChannelStatus {
......@@ -146,6 +159,9 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
void SendOutstandingReplies();
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe);
mojom::GpuService* gpu_service();
bool initialized() const { return initialized_; }
......@@ -155,6 +171,11 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
}
private:
#if defined(USE_OZONE)
void InitOzone();
void TerminateGpuProcess(const std::string& message);
#endif // defined(USE_OZONE)
std::string GetShaderPrefixKey();
void LoadedShader(int32_t client_id,
......@@ -195,6 +216,9 @@ class VIZ_HOST_EXPORT GpuHostImpl : public mojom::GpuHost {
IPC::Channel* const channel_;
const InitParams params_;
// Task runner corresponding to the thread |this| is created on.
scoped_refptr<base::SingleThreadTaskRunner> host_thread_task_runner_;
mojom::VizMainAssociatedPtr viz_main_ptr_;
mojom::GpuServicePtr gpu_service_ptr_;
mojo::Binding<mojom::GpuHost> gpu_host_binding_;
......
......@@ -276,39 +276,6 @@ void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind,
callback.Run(host);
}
#if defined(USE_OZONE)
// The ozone platform use this callback to send IPC messages to the gpu process.
void SendGpuProcessMessage(base::WeakPtr<GpuProcessHost> host,
IPC::Message* message) {
if (host)
host->Send(message);
else
delete message;
}
// Helper to register Mus/conventional thread bouncers for ozone startup.
void OzoneRegisterStartupCallbackHelper(
base::OnceCallback<void(ui::OzonePlatform*)> io_callback) {
// The callback registered in ozone can be called in any thread. So use an
// intermediary callback that bounces to the IO thread if needed, before
// running the callback.
auto bounce_callback = base::BindOnce(
[](base::TaskRunner* task_runner,
base::OnceCallback<void(ui::OzonePlatform*)> callback,
ui::OzonePlatform* platform) {
if (task_runner->RunsTasksInCurrentSequence()) {
std::move(callback).Run(platform);
} else {
task_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), platform));
}
},
base::RetainedRef(base::ThreadTaskRunnerHandle::Get()),
std::move(io_callback));
ui::OzonePlatform::RegisterStartupCallback(std::move(bounce_callback));
}
#endif // defined(USE_OZONE)
void OnGpuProcessHostDestroyedOnUI(int host_id, const std::string& message) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
GpuDataManagerImpl::GetInstance()->AddLogMessage(
......@@ -621,18 +588,16 @@ void GpuProcessHost::BindInterface(
mojo::ScopedMessagePipeHandle interface_pipe) {
if (interface_name ==
discardable_memory::mojom::DiscardableSharedMemoryManager::Name_) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::BindOnce(
&BindDiscardableMemoryRequestOnUI,
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest(
std::move(interface_pipe))));
BindDiscardableMemoryRequest(
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest(
std::move(interface_pipe)));
return;
}
process_->child_connection()->BindInterface(interface_name,
std::move(interface_pipe));
}
#if defined(USE_OZONE)
void GpuProcessHost::TerminateGpuProcess(const std::string& message) {
// At the moment, this path is only used by Ozone/Wayland. Once others start
// to use this, start to distinguish the origin of termination. By default,
......@@ -641,6 +606,11 @@ void GpuProcessHost::TerminateGpuProcess(const std::string& message) {
process_->TerminateOnBadMessageReceived(message);
}
void GpuProcessHost::SendGpuProcessMessage(IPC::Message* message) {
Send(message);
}
#endif // defined(USE_OZONE)
// static
GpuProcessHost* GpuProcessHost::FromID(int host_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......@@ -803,60 +773,6 @@ GpuProcessHost::~GpuProcessHost() {
base::BindOnce(&OnGpuProcessHostDestroyedOnUI, host_id_, message));
}
#if defined(USE_OZONE)
void GpuProcessHost::InitOzone() {
// Ozone needs to send the primary DRM device to GPU process as early as
// possible to ensure the latter always has a valid device. crbug.com/608839
// When running with mus, the OzonePlatform may not have been created yet. So
// defer the callback until OzonePlatform instance is created.
bool using_mojo = true;
#if defined(OS_CHROMEOS)
using_mojo = features::IsOzoneDrmMojo();
#endif
if (using_mojo) {
// TODO(rjkroege): Remove the legacy IPC code paths when no longer
// necessary. https://crbug.com/806092
auto interface_binder = base::BindRepeating(&GpuProcessHost::BindInterface,
weak_ptr_factory_.GetWeakPtr());
auto terminate_cb = base::BindOnce(&GpuProcessHost::TerminateGpuProcess,
weak_ptr_factory_.GetWeakPtr());
auto io_callback = base::BindOnce(
[](const base::RepeatingCallback<void(const std::string&,
mojo::ScopedMessagePipeHandle)>&
interface_binder,
base::OnceCallback<void(const std::string&)> terminate_cb,
ui::OzonePlatform* platform) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
platform->GetGpuPlatformSupportHost()->OnGpuServiceLaunched(
BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
interface_binder, std::move(terminate_cb));
},
interface_binder, std::move(terminate_cb));
OzoneRegisterStartupCallbackHelper(std::move(io_callback));
} else {
auto send_callback = base::BindRepeating(&SendGpuProcessMessage,
weak_ptr_factory_.GetWeakPtr());
// Create the callback that should run on the current thread (i.e. IO
// thread).
auto io_callback = base::BindOnce(
[](int host_id,
const base::RepeatingCallback<void(IPC::Message*)>& send_callback,
ui::OzonePlatform* platform) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
platform->GetGpuPlatformSupportHost()->OnGpuProcessLaunched(
host_id, BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
send_callback);
},
host_id_, send_callback);
OzoneRegisterStartupCallbackHelper(std::move(io_callback));
}
}
#endif // defined(USE_OZONE)
bool GpuProcessHost::Init() {
init_start_time_ = base::TimeTicks::Now();
......@@ -908,13 +824,11 @@ bool GpuProcessHost::Init() {
params.product = GetContentClient()->GetProduct();
params.deadline_to_synchronize_surfaces =
switches::GetDeadlineToSynchronizeSurfaces();
params.main_thread_task_runner =
BrowserThread::GetTaskRunnerForThread(BrowserThread::UI);
gpu_host_ = std::make_unique<viz::GpuHostImpl>(
this, process_->child_channel(), std::move(params));
#if defined(USE_OZONE)
InitOzone();
#endif // defined(USE_OZONE)
#if defined(OS_MACOSX)
ca_transaction_gpu_coordinator_ = CATransactionGPUCoordinator::Create(this);
#endif
......
......@@ -84,10 +84,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
bool force_create,
const base::Callback<void(GpuProcessHost*)>& callback);
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe);
void TerminateGpuProcess(const std::string& message);
// Get the GPU process host for the GPU process with the given ID. Returns
// null if the process no longer exists.
static GpuProcessHost* FromID(int host_id);
......@@ -130,10 +126,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
bool Init();
#if defined(USE_OZONE)
void InitOzone();
#endif // defined(USE_OZONE)
// BrowserChildProcessHostDelegate implementation.
bool OnMessageReceived(const IPC::Message& message) override;
void OnChannelConnected(int32_t peer_pid) override;
......@@ -163,8 +155,14 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
void BindDiscardableMemoryRequest(
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest request)
override;
void BindInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override;
#if defined(USE_OZONE)
void TerminateGpuProcess(const std::string& message) override;
void SendGpuProcessMessage(IPC::Message* message) override;
#endif
// Message handlers.
// Message handlers.
#if defined(OS_ANDROID)
void OnDestroyingVideoSurfaceAck();
#endif
......
......@@ -4,13 +4,14 @@
#include "content/public/browser/gpu_service_registry.h"
#include "components/viz/host/gpu_host_impl.h"
#include "content/browser/gpu/gpu_process_host.h"
namespace content {
void BindInterfaceInGpuProcess(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) {
GpuProcessHost* host = GpuProcessHost::Get();
auto* host = GpuProcessHost::Get()->gpu_host();
return host->BindInterface(interface_name, std::move(interface_pipe));
}
......
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