diff --git a/components/viz/service/frame_sinks/frame_sink_bundle_impl.cc b/components/viz/service/frame_sinks/frame_sink_bundle_impl.cc index 07262759cca3da862c7975d5ed54b75b9281f5f1..f01b98ffb56d715bfa72a8946b38c0344ddabfa5 100644 --- a/components/viz/service/frame_sinks/frame_sink_bundle_impl.cc +++ b/components/viz/service/frame_sinks/frame_sink_bundle_impl.cc @@ -4,12 +4,15 @@ #include "components/viz/service/frame_sinks/frame_sink_bundle_impl.h" +#include #include #include #include "base/check.h" #include "base/functional/bind.h" +#include "base/memory/raw_ptr.h" #include "base/memory/raw_ref.h" +#include "base/memory/weak_ptr.h" #include "build/build_config.h" #include "components/viz/service/frame_sinks/compositor_frame_sink_impl.h" #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h" @@ -45,6 +48,10 @@ class FrameSinkBundleImpl::SinkGroup : public BeginFrameObserver { bool IsEmpty() const { return frame_sinks_.empty(); } + base::WeakPtr GetWeakPtr() { + return weak_ptr_factory_.GetWeakPtr(); + } + void AddFrameSink(uint32_t sink_id) { frame_sinks_.insert(sink_id); @@ -204,6 +211,8 @@ class FrameSinkBundleImpl::SinkGroup : public BeginFrameObserver { std::set unacked_submissions_; BeginFrameArgs last_used_begin_frame_args_; + + base::WeakPtrFactory weak_ptr_factory_{this}; }; FrameSinkBundleImpl::FrameSinkBundleImpl( @@ -274,7 +283,7 @@ void FrameSinkBundleImpl::SetNeedsBeginFrame(uint32_t sink_id, void FrameSinkBundleImpl::Submit( std::vector submissions) { - std::set affected_groups; + std::map, base::WeakPtr> affected_groups; // Count the frame submissions before processing anything. This ensures that // any frames submitted here will be acked together in a batch, and not acked // individually in case they happen to ack synchronously within @@ -287,7 +296,7 @@ void FrameSinkBundleImpl::Submit( if (submission->data->is_frame()) { if (auto* group = GetSinkGroup(submission->sink_id)) { group->WillSubmitFrame(submission->sink_id); - affected_groups.insert(group); + affected_groups.emplace(group, group->GetWeakPtr()); } } } @@ -317,8 +326,10 @@ void FrameSinkBundleImpl::Submit( } } - for (auto* group : affected_groups) { - group->FlushMessages(); + for (const auto& [unsafe_group, weak_group] : affected_groups) { + if (weak_group) { + weak_group->FlushMessages(); + } } }