Commit 14fe0ac0 authored by kylechar's avatar kylechar Committed by Commit Bot

Switch BindingSet to Receiver

There should only be one mojom::GpuService message pipe so
GpuServiceImpl only needs one receiver instead of a set of them.

Bug: none
Change-Id: I76737d92dfcd4af84120709f4a25497ca34ab9e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869396Reviewed-by: default avatarJonathan Ross <jonross@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707452}
parent 668783bd
......@@ -131,12 +131,6 @@ base::OnceCallback<void(Params&&...)> WrapCallback(
base::RetainedRef(std::move(runner)), std::move(callback));
}
void DestroyBinding(mojo::BindingSet<mojom::GpuService>* binding,
base::WaitableEvent* wait) {
binding->CloseAllBindings();
wait->Signal();
}
} // namespace
GpuServiceImpl::GpuServiceImpl(
......@@ -163,8 +157,7 @@ GpuServiceImpl::GpuServiceImpl(
#if BUILDFLAG(ENABLE_VULKAN)
vulkan_implementation_(vulkan_implementation),
#endif
exit_callback_(std::move(exit_callback)),
bindings_(std::make_unique<mojo::BindingSet<mojom::GpuService>>()) {
exit_callback_(std::move(exit_callback)) {
DCHECK(!io_runner_->BelongsToCurrentThread());
DCHECK(exit_callback_);
......@@ -214,11 +207,18 @@ GpuServiceImpl::~GpuServiceImpl() {
bind_task_tracker_.TryCancelAll();
logging::SetLogMessageHandler(nullptr);
g_log_callback.Get().Reset();
// Destroy the receiver on the IO thread.
base::WaitableEvent wait;
if (io_runner_->PostTask(
FROM_HERE, base::BindOnce(&DestroyBinding, bindings_.get(), &wait))) {
auto destroy_receiver_task = base::BindOnce(
[](mojo::Receiver<mojom::GpuService>* receiver,
base::WaitableEvent* wait) {
receiver->reset();
wait->Signal();
},
&receiver_, &wait);
if (io_runner_->PostTask(FROM_HERE, std::move(destroy_receiver_task)))
wait.Wait();
}
if (watchdog_thread_)
watchdog_thread_->OnGpuProcessTearDown();
......@@ -338,15 +338,17 @@ void GpuServiceImpl::InitializeWithHost(
watchdog_thread()->AddPowerObserver();
}
void GpuServiceImpl::Bind(mojom::GpuServiceRequest request) {
void GpuServiceImpl::Bind(
mojo::PendingReceiver<mojom::GpuService> pending_receiver) {
if (main_runner_->BelongsToCurrentThread()) {
bind_task_tracker_.PostTask(
io_runner_.get(), FROM_HERE,
base::BindOnce(&GpuServiceImpl::Bind, base::Unretained(this),
std::move(request)));
std::move(pending_receiver)));
return;
}
bindings_->AddBinding(this, std::move(request));
DCHECK(!receiver_.is_bound());
receiver_.Bind(std::move(pending_receiver));
}
void GpuServiceImpl::DisableGpuCompositing() {
......@@ -732,7 +734,7 @@ void GpuServiceImpl::EstablishGpuChannel(int32_t client_id,
if (IsExiting()) {
// We are already exiting so there is no point in responding. Close the
// receiver so we can safely drop the callback.
bindings_->CloseAllBindings();
receiver_.reset();
return;
}
......
......@@ -32,7 +32,8 @@
#include "gpu/ipc/service/gpu_config.h"
#include "gpu/ipc/service/x_util.h"
#include "gpu/vulkan/buildflags.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/shared_remote.h"
#include "services/viz/privileged/mojom/gl/gpu_host.mojom.h"
......@@ -98,7 +99,7 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
gpu::SyncPointManager* sync_point_manager = nullptr,
gpu::SharedImageManager* shared_image_manager = nullptr,
base::WaitableEvent* shutdown_event = nullptr);
void Bind(mojom::GpuServiceRequest request);
void Bind(mojo::PendingReceiver<mojom::GpuService> pending_receiver);
scoped_refptr<gpu::SharedContextState> GetContextState();
......@@ -358,9 +359,10 @@ class VIZ_SERVICE_EXPORT GpuServiceImpl : public gpu::GpuChannelManagerDelegate,
base::Time start_time_;
// Used to track the task to bind a GpuServiceRequest on the io thread.
// Used to track the task to bind |receiver_| on the IO thread.
base::CancelableTaskTracker bind_task_tracker_;
std::unique_ptr<mojo::BindingSet<mojom::GpuService>> bindings_;
// Should only be accessed on the IO thread after creation.
mojo::Receiver<mojom::GpuService> receiver_{this};
#if defined(OS_WIN)
// Used to track if the Dx Diag task on a different thread is still running.
......
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