gpu: Cut most remaining vestiges of legacy IPC
This removes some more dead legacy IPC-related code from GPU, and lands a few other small changes in preparation for actually ripping IPC::Channel out of GpuChannel/Host. Namely: - GpuChannel::IsLost() state no longer relies on IPC::Listener events - The client-side GpuChannel interface remote now disconnects at the same time as the IPC Channel, so that when we remove the IPC Channel later, we should not incur any behavioral changes. No functional changes should result from this CL; it's meant as a safe precursor to the slightly riskier change of actually ripping out the IPC::Channel. Bug: 1196476 Change-Id: I0902d401cf96fdaff886de69742be896e6a8554f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2984065 Reviewed-by: Zhenyao Mo <zmo@chromium.org> Commit-Queue: Ken Rockot <rockot@google.com> Cr-Commit-Position: refs/heads/master@{#895755}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
35333f5c11
commit
87f4cd3d41
@ -673,7 +673,6 @@ test("gpu_unittests") {
|
||||
"//gpu/ipc/common:test_support",
|
||||
"//gpu/ipc/host",
|
||||
"//gpu/ipc/service",
|
||||
"//ipc:test_support",
|
||||
"//mojo/core/embedder",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/cpp/test_support:test_utils",
|
||||
|
@ -37,6 +37,7 @@ GpuChannelHost::GpuChannelHost(
|
||||
gpu_info_(gpu_info),
|
||||
gpu_feature_info_(gpu_feature_info),
|
||||
listener_(new Listener(), base::OnTaskRunnerDeleter(io_thread_)),
|
||||
connection_tracker_(base::MakeRefCounted<ConnectionTracker>()),
|
||||
shared_image_interface_(
|
||||
this,
|
||||
static_cast<int32_t>(
|
||||
@ -51,6 +52,10 @@ GpuChannelHost::GpuChannelHost(
|
||||
io_thread_);
|
||||
gpu_channel_ = mojo::SharedAssociatedRemote<mojom::GpuChannel>(
|
||||
std::move(channel), io_thread_);
|
||||
gpu_channel_.set_disconnect_handler(
|
||||
base::BindOnce(&ConnectionTracker::OnDisconnectedFromGpuProcess,
|
||||
connection_tracker_),
|
||||
io_thread_);
|
||||
|
||||
next_image_id_.GetNext();
|
||||
for (int32_t i = 0;
|
||||
@ -154,6 +159,8 @@ void GpuChannelHost::InternalFlush(uint32_t deferred_message_id) {
|
||||
}
|
||||
|
||||
void GpuChannelHost::DestroyChannel() {
|
||||
gpu_channel_.Disconnect();
|
||||
connection_tracker_->OnDisconnectedFromGpuProcess();
|
||||
io_thread_->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&Listener::Close, base::Unretained(listener_.get())));
|
||||
@ -182,6 +189,14 @@ GpuChannelHost::CreateClientSharedImageInterface() {
|
||||
|
||||
GpuChannelHost::~GpuChannelHost() = default;
|
||||
|
||||
GpuChannelHost::ConnectionTracker::ConnectionTracker() = default;
|
||||
|
||||
GpuChannelHost::ConnectionTracker::~ConnectionTracker() = default;
|
||||
|
||||
void GpuChannelHost::ConnectionTracker::OnDisconnectedFromGpuProcess() {
|
||||
is_connected_.store(false);
|
||||
}
|
||||
|
||||
GpuChannelHost::OrderingBarrierInfo::OrderingBarrierInfo() = default;
|
||||
|
||||
GpuChannelHost::OrderingBarrierInfo::~OrderingBarrierInfo() = default;
|
||||
@ -222,12 +237,6 @@ bool GpuChannelHost::Listener::OnMessageReceived(const IPC::Message& message) {
|
||||
void GpuChannelHost::Listener::OnChannelError() {
|
||||
AutoLock lock(lock_);
|
||||
channel_ = nullptr;
|
||||
lost_ = true;
|
||||
}
|
||||
|
||||
bool GpuChannelHost::Listener::IsLost() const {
|
||||
AutoLock lock(lock_);
|
||||
return lost_;
|
||||
}
|
||||
|
||||
} // namespace gpu
|
||||
|
@ -8,14 +8,13 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/atomic_sequence_num.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/process/process.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
#include "gpu/config/gpu_feature_info.h"
|
||||
@ -63,11 +62,10 @@ class GPU_EXPORT GpuChannelHost
|
||||
const gpu::GpuFeatureInfo& gpu_feature_info,
|
||||
mojo::ScopedMessagePipeHandle handle,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = nullptr);
|
||||
GpuChannelHost(const GpuChannelHost&) = delete;
|
||||
GpuChannelHost& operator=(const GpuChannelHost&) = delete;
|
||||
|
||||
bool IsLost() const {
|
||||
DCHECK(listener_.get());
|
||||
return listener_->IsLost();
|
||||
}
|
||||
bool IsLost() const { return !connection_tracker_->is_connected(); }
|
||||
|
||||
int channel_id() const { return channel_id_; }
|
||||
|
||||
@ -124,7 +122,7 @@ class GPU_EXPORT GpuChannelHost
|
||||
// otherwise ignored.
|
||||
void CrashGpuProcessForTesting();
|
||||
|
||||
// Termintes the GPU process with an exit code of 0. This only works when
|
||||
// Terminates the GPU process with an exit code of 0. This only works when
|
||||
// running tests and is otherwise ignored.
|
||||
void TerminateGpuProcessForTesting();
|
||||
|
||||
@ -140,6 +138,25 @@ class GPU_EXPORT GpuChannelHost
|
||||
virtual ~GpuChannelHost();
|
||||
|
||||
private:
|
||||
// Tracks whether we still have a working connection to the GPU process. This
|
||||
// is updated eaglerly from the IO thread if the connection is broken, but it
|
||||
// may be queried from any thread via GpuChannel::IsLost(). This is why it's a
|
||||
// RefCountedThreadSafe object.
|
||||
struct ConnectionTracker
|
||||
: public base::RefCountedThreadSafe<ConnectionTracker> {
|
||||
ConnectionTracker();
|
||||
|
||||
bool is_connected() const { return is_connected_.load(); }
|
||||
|
||||
void OnDisconnectedFromGpuProcess();
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<ConnectionTracker>;
|
||||
~ConnectionTracker();
|
||||
|
||||
std::atomic_bool is_connected_{true};
|
||||
};
|
||||
|
||||
// A filter used internally to route incoming messages from the IO thread
|
||||
// to the correct message loop. It also maintains some shared state between
|
||||
// all the contexts.
|
||||
@ -161,17 +178,8 @@ class GPU_EXPORT GpuChannelHost
|
||||
bool OnMessageReceived(const IPC::Message& msg) override;
|
||||
void OnChannelError() override;
|
||||
|
||||
// The following methods can be called on any thread.
|
||||
|
||||
// Whether the channel is lost.
|
||||
bool IsLost() const;
|
||||
|
||||
private:
|
||||
// Protects all fields below this one.
|
||||
mutable base::Lock lock_;
|
||||
|
||||
// Whether the channel has been lost.
|
||||
bool lost_ GUARDED_BY(lock_) = false;
|
||||
std::unique_ptr<IPC::ChannelMojo> channel_ GUARDED_BY(lock_);
|
||||
};
|
||||
|
||||
@ -212,6 +220,11 @@ class GPU_EXPORT GpuChannelHost
|
||||
// with base::Unretained(listener_).
|
||||
std::unique_ptr<Listener, base::OnTaskRunnerDeleter> listener_;
|
||||
|
||||
// Atomically tracks whether the GPU connection has been lost. This can be
|
||||
// queried from any thread by IsLost() but is always set on the IO thread as
|
||||
// soon as disconnection is detected.
|
||||
const scoped_refptr<ConnectionTracker> connection_tracker_;
|
||||
|
||||
mojo::SharedAssociatedRemote<mojom::GpuChannel> gpu_channel_;
|
||||
SharedImageInterfaceProxy shared_image_interface_;
|
||||
|
||||
@ -227,17 +240,17 @@ class GPU_EXPORT GpuChannelHost
|
||||
// Protects |deferred_messages_|, |pending_ordering_barrier_| and
|
||||
// |*_deferred_message_id_|.
|
||||
mutable base::Lock context_lock_;
|
||||
std::vector<mojom::DeferredRequestPtr> deferred_messages_;
|
||||
absl::optional<OrderingBarrierInfo> pending_ordering_barrier_;
|
||||
uint32_t next_deferred_message_id_ = 1;
|
||||
std::vector<mojom::DeferredRequestPtr> deferred_messages_
|
||||
GUARDED_BY(context_lock_);
|
||||
absl::optional<OrderingBarrierInfo> pending_ordering_barrier_
|
||||
GUARDED_BY(context_lock_);
|
||||
uint32_t next_deferred_message_id_ GUARDED_BY(context_lock_) = 1;
|
||||
// Highest deferred message id in |deferred_messages_|.
|
||||
uint32_t enqueued_deferred_message_id_ = 0;
|
||||
uint32_t enqueued_deferred_message_id_ GUARDED_BY(context_lock_) = 0;
|
||||
// Highest deferred message id sent to the channel.
|
||||
uint32_t flushed_deferred_message_id_ = 0;
|
||||
uint32_t flushed_deferred_message_id_ GUARDED_BY(context_lock_) = 0;
|
||||
// Highest deferred message id known to have been received by the service.
|
||||
uint32_t verified_deferred_message_id_ = 0;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GpuChannelHost);
|
||||
uint32_t verified_deferred_message_id_ GUARDED_BY(context_lock_) = 0;
|
||||
};
|
||||
|
||||
} // namespace gpu
|
||||
|
@ -166,14 +166,6 @@ void CommandBufferStub::ExecuteDeferredRequest(
|
||||
}
|
||||
}
|
||||
|
||||
bool CommandBufferStub::OnMessageReceived(const IPC::Message& message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommandBufferStub::Send(IPC::Message* message) {
|
||||
return channel_->Send(message);
|
||||
}
|
||||
|
||||
bool CommandBufferStub::IsScheduled() {
|
||||
return (!command_buffer_.get() || command_buffer_->scheduled());
|
||||
}
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include "gpu/ipc/common/surface_handle.h"
|
||||
#include "gpu/ipc/service/context_url.h"
|
||||
#include "gpu/ipc/service/gpu_ipc_service_export.h"
|
||||
#include "ipc/ipc_listener.h"
|
||||
#include "ipc/ipc_sender.h"
|
||||
#include "mojo/public/cpp/bindings/associated_receiver.h"
|
||||
#include "mojo/public/cpp/bindings/shared_associated_remote.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
@ -62,9 +60,7 @@ class SyncPointClientState;
|
||||
// For every CommandBufferStub instance, there's a corresponding
|
||||
// CommandBufferProxyImpl client.
|
||||
class GPU_IPC_SERVICE_EXPORT CommandBufferStub
|
||||
: public IPC::Listener,
|
||||
public IPC::Sender,
|
||||
public CommandBufferServiceClient,
|
||||
: public CommandBufferServiceClient,
|
||||
public DecoderClient,
|
||||
public mojom::CommandBuffer,
|
||||
public base::SupportsWeakPtr<CommandBufferStub> {
|
||||
@ -136,12 +132,6 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub
|
||||
int32_t end,
|
||||
WaitForStateCallback callback);
|
||||
|
||||
// IPC::Listener implementation:
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
// IPC::Sender implementation:
|
||||
bool Send(IPC::Message* msg) override;
|
||||
|
||||
// CommandBufferServiceClient implementation:
|
||||
CommandBatchProcessedResult OnCommandBatchProcessed() override;
|
||||
void OnParseError() override;
|
||||
@ -284,12 +274,10 @@ class GPU_IPC_SERVICE_EXPORT CommandBufferStub
|
||||
gles2::ProgramCache::ScopedCacheUse CreateCacheUse();
|
||||
|
||||
// Message handlers:
|
||||
void OnGetState(IPC::Message* reply_message);
|
||||
void OnAsyncFlush(int32_t put_offset,
|
||||
uint32_t flush_id,
|
||||
const std::vector<SyncToken>& sync_token_fences);
|
||||
void OnDestroyTransferBuffer(int32_t id);
|
||||
void OnGetTransferBuffer(int32_t id, IPC::Message* reply_message);
|
||||
|
||||
void OnSignalAck(uint32_t id);
|
||||
|
||||
|
@ -53,7 +53,6 @@
|
||||
#include "gpu/ipc/service/raster_command_buffer_stub.h"
|
||||
#include "gpu/ipc/service/webgpu_command_buffer_stub.h"
|
||||
#include "ipc/ipc_channel.h"
|
||||
#include "ipc/message_filter.h"
|
||||
#include "mojo/public/cpp/bindings/associated_receiver.h"
|
||||
#include "ui/gl/gl_context.h"
|
||||
#include "ui/gl/gl_image_shared_memory.h"
|
||||
@ -66,20 +65,6 @@
|
||||
|
||||
namespace gpu {
|
||||
|
||||
struct GpuChannelMessage {
|
||||
IPC::Message message;
|
||||
uint32_t order_number;
|
||||
base::TimeTicks time_received;
|
||||
|
||||
GpuChannelMessage(const IPC::Message& msg,
|
||||
uint32_t order_num,
|
||||
base::TimeTicks ts)
|
||||
: message(msg), order_number(order_num), time_received(ts) {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(GpuChannelMessage);
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
@ -101,7 +86,7 @@ bool TryCreateStreamTexture(
|
||||
// - posts control and out of order messages to the main thread
|
||||
// - forwards other messages to the scheduler
|
||||
class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter
|
||||
: public IPC::MessageFilter,
|
||||
: public base::RefCountedThreadSafe<GpuChannelMessageFilter>,
|
||||
public mojom::GpuChannel {
|
||||
public:
|
||||
GpuChannelMessageFilter(
|
||||
@ -110,6 +95,8 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter
|
||||
Scheduler* scheduler,
|
||||
ImageDecodeAcceleratorWorker* image_decode_accelerator_worker,
|
||||
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);
|
||||
GpuChannelMessageFilter(const GpuChannelMessageFilter&) = delete;
|
||||
GpuChannelMessageFilter& operator=(const GpuChannelMessageFilter&) = delete;
|
||||
|
||||
// Methods called on main thread.
|
||||
void Destroy();
|
||||
@ -119,16 +106,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter
|
||||
void RemoveRoute(int32_t route_id);
|
||||
|
||||
// Methods called on IO thread.
|
||||
// IPC::MessageFilter implementation.
|
||||
void OnFilterAdded(IPC::Channel* channel) override;
|
||||
void OnFilterRemoved() override;
|
||||
void OnChannelConnected(int32_t peer_pid) override;
|
||||
void OnChannelError() override;
|
||||
void OnChannelClosing() override;
|
||||
bool OnMessageReceived(const IPC::Message& message) override;
|
||||
|
||||
void AddChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
|
||||
void RemoveChannelFilter(scoped_refptr<IPC::MessageFilter> filter);
|
||||
|
||||
void BindGpuChannel(
|
||||
mojo::PendingAssociatedReceiver<mojom::GpuChannel> receiver) {
|
||||
@ -140,12 +117,11 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter
|
||||
}
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<GpuChannelMessageFilter>;
|
||||
~GpuChannelMessageFilter() override;
|
||||
|
||||
SequenceId GetSequenceId(int32_t route_id) const;
|
||||
|
||||
bool MessageErrorHandler(const IPC::Message& message, const char* error_msg);
|
||||
|
||||
// mojom::GpuChannel:
|
||||
void CrashForTesting() override;
|
||||
void TerminateForTesting() override;
|
||||
@ -212,10 +188,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter
|
||||
}
|
||||
#endif // defined(OS_FUCHSIA)
|
||||
|
||||
IPC::Channel* ipc_channel_ = nullptr;
|
||||
base::ProcessId peer_pid_ = base::kNullProcessId;
|
||||
std::vector<scoped_refptr<IPC::MessageFilter>> channel_filters_;
|
||||
|
||||
// Map of route id to scheduler sequence id.
|
||||
base::flat_map<int32_t, SequenceId> route_sequences_;
|
||||
mutable base::Lock gpu_channel_lock_;
|
||||
@ -239,8 +211,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelMessageFilter
|
||||
bool allow_process_kill_for_testing_ = false;
|
||||
|
||||
mojo::AssociatedReceiver<mojom::GpuChannel> receiver_{this};
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GpuChannelMessageFilter);
|
||||
};
|
||||
|
||||
GpuChannelMessageFilter::GpuChannelMessageFilter(
|
||||
@ -290,66 +260,6 @@ void GpuChannelMessageFilter::RemoveRoute(int32_t route_id) {
|
||||
route_sequences_.erase(route_id);
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::OnFilterAdded(IPC::Channel* channel) {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
DCHECK(!ipc_channel_);
|
||||
ipc_channel_ = channel;
|
||||
for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_)
|
||||
filter->OnFilterAdded(ipc_channel_);
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::OnFilterRemoved() {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_)
|
||||
filter->OnFilterRemoved();
|
||||
ipc_channel_ = nullptr;
|
||||
peer_pid_ = base::kNullProcessId;
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::OnChannelConnected(int32_t peer_pid) {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
DCHECK(peer_pid_ == base::kNullProcessId);
|
||||
peer_pid_ = peer_pid;
|
||||
for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_)
|
||||
filter->OnChannelConnected(peer_pid);
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::OnChannelError() {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_)
|
||||
filter->OnChannelError();
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::OnChannelClosing() {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
for (scoped_refptr<IPC::MessageFilter>& filter : channel_filters_)
|
||||
filter->OnChannelClosing();
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::AddChannelFilter(
|
||||
scoped_refptr<IPC::MessageFilter> filter) {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
channel_filters_.push_back(filter);
|
||||
if (ipc_channel_)
|
||||
filter->OnFilterAdded(ipc_channel_);
|
||||
if (peer_pid_ != base::kNullProcessId)
|
||||
filter->OnChannelConnected(peer_pid_);
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::RemoveChannelFilter(
|
||||
scoped_refptr<IPC::MessageFilter> filter) {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
if (ipc_channel_)
|
||||
filter->OnFilterRemoved();
|
||||
base::Erase(channel_filters_, filter);
|
||||
}
|
||||
|
||||
bool GpuChannelMessageFilter::OnMessageReceived(const IPC::Message& message) {
|
||||
DCHECK(io_thread_checker_.CalledOnValidThread());
|
||||
DCHECK(ipc_channel_);
|
||||
return false;
|
||||
}
|
||||
|
||||
SequenceId GpuChannelMessageFilter::GetSequenceId(int32_t route_id) const {
|
||||
gpu_channel_lock_.AssertAcquired();
|
||||
auto it = route_sequences_.find(route_id);
|
||||
@ -399,17 +309,6 @@ void GpuChannelMessageFilter::FlushDeferredRequests(
|
||||
scheduler_->ScheduleTasks(std::move(tasks));
|
||||
}
|
||||
|
||||
bool GpuChannelMessageFilter::MessageErrorHandler(const IPC::Message& message,
|
||||
const char* error_msg) {
|
||||
DLOG(ERROR) << error_msg;
|
||||
if (message.is_sync()) {
|
||||
IPC::Message* reply = IPC::SyncMessage::GenerateReply(&message);
|
||||
reply->set_reply_error();
|
||||
ipc_channel_->Send(reply);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GpuChannelMessageFilter::CrashForTesting() {
|
||||
if (allow_process_kill_for_testing_) {
|
||||
gl::Crash();
|
||||
@ -560,12 +459,15 @@ GpuChannel::GpuChannel(
|
||||
io_task_runner_(io_task_runner),
|
||||
share_group_(share_group),
|
||||
image_manager_(new gles2::ImageManager()),
|
||||
is_gpu_host_(is_gpu_host) {
|
||||
is_gpu_host_(is_gpu_host),
|
||||
filter_(base::MakeRefCounted<GpuChannelMessageFilter>(
|
||||
this,
|
||||
channel_token,
|
||||
scheduler,
|
||||
image_decode_accelerator_worker,
|
||||
std::move(task_runner))) {
|
||||
DCHECK(gpu_channel_manager_);
|
||||
DCHECK(client_id_);
|
||||
filter_ =
|
||||
new GpuChannelMessageFilter(this, channel_token, scheduler,
|
||||
image_decode_accelerator_worker, task_runner);
|
||||
}
|
||||
|
||||
GpuChannel::~GpuChannel() {
|
||||
@ -616,7 +518,6 @@ void GpuChannel::Init(IPC::ChannelHandle channel_handle,
|
||||
base::WaitableEvent* shutdown_event) {
|
||||
sync_channel_ = IPC::SyncChannel::Create(this, io_task_runner_.get(),
|
||||
task_runner_.get(), shutdown_event);
|
||||
sync_channel_->AddFilter(filter_.get());
|
||||
sync_channel_->AddAssociatedInterfaceForIOThread(
|
||||
base::BindRepeating(&GpuChannelMessageFilter::BindGpuChannel, filter_));
|
||||
sync_channel_->Init(channel_handle, IPC::Channel::MODE_SERVER,
|
||||
@ -638,22 +539,6 @@ void GpuChannel::OnChannelError() {
|
||||
gpu_channel_manager_->RemoveChannel(client_id_);
|
||||
}
|
||||
|
||||
bool GpuChannel::Send(IPC::Message* message) {
|
||||
// The GPU process must never send a synchronous IPC message to the renderer
|
||||
// process. This could result in deadlock.
|
||||
DCHECK(!message->is_sync());
|
||||
|
||||
DVLOG(1) << "sending message @" << message << " on channel @" << this
|
||||
<< " with type " << message->type();
|
||||
|
||||
if (!channel_) {
|
||||
delete message;
|
||||
return false;
|
||||
}
|
||||
|
||||
return channel_->Send(message);
|
||||
}
|
||||
|
||||
void GpuChannel::OnCommandBufferScheduled(CommandBufferStub* stub) {
|
||||
scheduler_->EnableSequence(stub->sequence_id());
|
||||
}
|
||||
@ -1004,18 +889,6 @@ void GpuChannel::CacheShader(const std::string& key,
|
||||
gpu_channel_manager_->delegate()->StoreShaderToDisk(client_id_, key, shader);
|
||||
}
|
||||
|
||||
void GpuChannel::AddFilter(IPC::MessageFilter* filter) {
|
||||
io_task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&GpuChannelMessageFilter::AddChannelFilter,
|
||||
filter_, base::RetainedRef(filter)));
|
||||
}
|
||||
|
||||
void GpuChannel::RemoveFilter(IPC::MessageFilter* filter) {
|
||||
io_task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&GpuChannelMessageFilter::RemoveChannelFilter,
|
||||
filter_, base::RetainedRef(filter)));
|
||||
}
|
||||
|
||||
uint64_t GpuChannel::GetMemoryUsage() const {
|
||||
// Collect the unique memory trackers in use by the |stubs_|.
|
||||
base::flat_set<MemoryTracker*> unique_memory_trackers;
|
||||
|
@ -13,13 +13,11 @@
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/process/process_handle.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/trace_event/memory_dump_provider.h"
|
||||
#include "base/unguessable_token.h"
|
||||
#include "build/build_config.h"
|
||||
#include "gpu/command_buffer/common/capabilities.h"
|
||||
@ -29,7 +27,6 @@
|
||||
#include "gpu/ipc/service/command_buffer_stub.h"
|
||||
#include "gpu/ipc/service/gpu_ipc_service_export.h"
|
||||
#include "gpu/ipc/service/shared_image_stub.h"
|
||||
#include "ipc/ipc_sender.h"
|
||||
#include "ipc/ipc_sync_channel.h"
|
||||
#include "mojo/public/cpp/bindings/generic_pending_associated_receiver.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
@ -51,15 +48,12 @@ class SharedImageStub;
|
||||
class StreamTexture;
|
||||
class SyncPointManager;
|
||||
|
||||
namespace mojom {
|
||||
class GpuChannel;
|
||||
}
|
||||
|
||||
// Encapsulates an IPC channel between the GPU process and one renderer
|
||||
// process. On the renderer side there's a corresponding GpuChannelHost.
|
||||
class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener,
|
||||
public IPC::Sender {
|
||||
class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener {
|
||||
public:
|
||||
GpuChannel(const GpuChannel&) = delete;
|
||||
GpuChannel& operator=(const GpuChannel&) = delete;
|
||||
~GpuChannel() override;
|
||||
|
||||
static std::unique_ptr<GpuChannel> Create(
|
||||
@ -127,12 +121,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener,
|
||||
bool OnMessageReceived(const IPC::Message& msg) override;
|
||||
void OnChannelError() override;
|
||||
|
||||
// IPC::Sender implementation:
|
||||
bool Send(IPC::Message* msg) override;
|
||||
|
||||
void AddFilter(IPC::MessageFilter* filter);
|
||||
void RemoveFilter(IPC::MessageFilter* filter);
|
||||
|
||||
void OnCommandBufferScheduled(CommandBufferStub* stub);
|
||||
void OnCommandBufferDescheduled(CommandBufferStub* stub);
|
||||
|
||||
@ -239,9 +227,6 @@ class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener,
|
||||
|
||||
base::ProcessId client_pid_ = base::kNullProcessId;
|
||||
|
||||
// The message filter on the io thread.
|
||||
scoped_refptr<GpuChannelMessageFilter> filter_;
|
||||
|
||||
// An optional binder to handle associated interface requests from the Media
|
||||
// stack, targeting a specific CommandBuffer.
|
||||
CommandBufferMediaBinder command_buffer_media_binder_;
|
||||
@ -287,12 +272,14 @@ class GPU_IPC_SERVICE_EXPORT GpuChannel : public IPC::Listener,
|
||||
base::flat_map<int32_t, scoped_refptr<StreamTexture>> stream_textures_;
|
||||
#endif
|
||||
|
||||
// State shared with the IO thread. Receives all GpuChannel interface messages
|
||||
// and schedules tasks for them appropriately.
|
||||
const scoped_refptr<GpuChannelMessageFilter> filter_;
|
||||
|
||||
// Member variables should appear before the WeakPtrFactory, to ensure that
|
||||
// any WeakPtrs to Controller are invalidated before its members variable's
|
||||
// destructors are executed, rendering them invalid.
|
||||
base::WeakPtrFactory<GpuChannel> weak_factory_{this};
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(GpuChannel);
|
||||
};
|
||||
|
||||
} // namespace gpu
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/trace_event/memory_dump_manager.h"
|
||||
#include "base/unguessable_token.h"
|
||||
#include "build/build_config.h"
|
||||
#include "gpu/command_buffer/common/activity_flags.h"
|
||||
#include "gpu/command_buffer/service/scheduler.h"
|
||||
#include "gpu/command_buffer/service/shared_image_manager.h"
|
||||
@ -116,7 +117,7 @@ GpuChannel* GpuChannelTestCommon::CreateChannel(int32_t client_id,
|
||||
base::UnguessableToken::Create(), client_id, kClientTracingId,
|
||||
is_gpu_host, true);
|
||||
base::ProcessId kProcessId = 1;
|
||||
channel->OnChannelConnected(kProcessId);
|
||||
channel->set_client_pid(kProcessId);
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,6 @@
|
||||
#include "gpu/ipc/service/command_buffer_stub.h"
|
||||
#include "gpu/ipc/service/gpu_channel.h"
|
||||
#include "gpu/ipc/service/gpu_channel_manager.h"
|
||||
#include "ipc/ipc_message.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
|
@ -63,7 +63,6 @@
|
||||
#include "gpu/ipc/service/gpu_channel_test_common.h"
|
||||
#include "gpu/ipc/service/image_decode_accelerator_stub.h"
|
||||
#include "gpu/ipc/service/image_decode_accelerator_worker.h"
|
||||
#include "ipc/ipc_message.h"
|
||||
#include "skia/ext/skia_memory_dump_provider.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "gpu/ipc/common/command_buffer_id.h"
|
||||
#include "gpu/ipc/common/gpu_channel.mojom.h"
|
||||
#include "gpu/ipc/service/gpu_ipc_service_export.h"
|
||||
#include "ipc/ipc_listener.h"
|
||||
|
||||
namespace gpu {
|
||||
class SharedContextState;
|
||||
|
@ -13,6 +13,17 @@
|
||||
|
||||
namespace mojo {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename Interface>
|
||||
struct SharedRemoteTraits<AssociatedRemote<Interface>> {
|
||||
static void BindDisconnected(AssociatedRemote<Interface>& remote) {
|
||||
ignore_result(remote.BindNewEndpointAndPassDedicatedReceiver());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// SharedAssociatedRemote wraps a non-thread-safe AssociatedRemote and proxies
|
||||
// messages to it. Unlike normal AssociatedRemote objects,
|
||||
// SharedAssociatedRemote is copyable and usable from any thread, but has some
|
||||
@ -57,6 +68,14 @@ class SharedAssociatedRemote {
|
||||
// reference the same underlying endpoint.
|
||||
void reset() { remote_.reset(); }
|
||||
|
||||
// Disconnects the SharedAssociatedRemote. This leaves the object in a usable
|
||||
// state -- i.e. it's still safe to dereference and make calls -- but severs
|
||||
// the underlying connection so that no new replies will be received and all
|
||||
// outgoing messages will be discarded. This is useful when you want to force
|
||||
// a disconnection like with reset(), but you don't want the
|
||||
// SharedAssociatedRemote to become unbound.
|
||||
void Disconnect() { remote_->Disconnect(); }
|
||||
|
||||
// Creates a new pair of endpoints and binds this SharedAssociatedRemote to
|
||||
// one of them, on `task_runner`. The other is returned as a receiver.
|
||||
mojo::PendingAssociatedReceiver<Interface> BindNewEndpointAndPassReceiver(
|
||||
|
@ -23,6 +23,20 @@
|
||||
|
||||
namespace mojo {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename RemoteType>
|
||||
struct SharedRemoteTraits;
|
||||
|
||||
template <typename Interface>
|
||||
struct SharedRemoteTraits<Remote<Interface>> {
|
||||
static void BindDisconnected(Remote<Interface>& remote) {
|
||||
ignore_result(remote.BindNewPipeAndPassReceiver());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// Helper that may be used from any sequence to serialize |Interface| messages
|
||||
// and forward them elsewhere. In general, prefer `SharedRemote`, but this type
|
||||
// may be useful when it's necessary to manually manage the lifetime of the
|
||||
@ -71,6 +85,8 @@ class SharedRemoteBase
|
||||
std::move(handler_task_runner));
|
||||
}
|
||||
|
||||
void Disconnect() { wrapper_->Disconnect(); }
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<SharedRemoteBase<RemoteType>>;
|
||||
template <typename Interface>
|
||||
@ -125,6 +141,19 @@ class SharedRemoteBase
|
||||
remote_.set_disconnect_handler(std::move(wrapped_handler));
|
||||
}
|
||||
|
||||
void Disconnect() {
|
||||
if (!task_runner_->RunsTasksInCurrentSequence()) {
|
||||
task_runner_->PostTask(
|
||||
FROM_HERE, base::BindOnce(&RemoteWrapper::Disconnect, this));
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the remote and rebind it in a disconnected state, so that it's
|
||||
// usable but discards all messages.
|
||||
remote_.reset();
|
||||
internal::SharedRemoteTraits<RemoteType>::BindDisconnected(remote_);
|
||||
}
|
||||
|
||||
private:
|
||||
friend struct RemoteWrapperDeleter;
|
||||
|
||||
@ -252,6 +281,14 @@ class SharedRemote {
|
||||
// underlying endpoint.
|
||||
void reset() { remote_.reset(); }
|
||||
|
||||
// Disconnects the SharedRemote. This leaves the object in a usable state --
|
||||
// i.e. it's still safe to dereference and make calls -- but severs the
|
||||
// underlying connection so that no new replies will be received and all
|
||||
// outgoing messages will be discarded. This is useful when you want to force
|
||||
// a disconnection like with reset(), but you don't want the SharedRemote to
|
||||
// become unbound.
|
||||
void Disconnect() { remote_->Disconnect(); }
|
||||
|
||||
// Binds this SharedRemote to `pending_remote` on the sequence given by
|
||||
// `bind_task_runner`, or the calling sequence if `bind_task_runner` is null.
|
||||
// Once bound, the SharedRemote may be used to send messages on the underlying
|
||||
|
Reference in New Issue
Block a user