diff --git a/cc/test/fake_proxy.h b/cc/test/fake_proxy.h index e4552eb3bc9eb66c027965b855b5013b7eca4d58..2ab79f98269782c4b84e890180b03183596a5237 100644 --- a/cc/test/fake_proxy.h +++ b/cc/test/fake_proxy.h @@ -64,7 +64,11 @@ class FakeProxy : public Proxy { base::OnceClosure callback) override {} double GetPercentDroppedFrames() const override; void SetPauseRendering(bool pause_rendering) override {} - + + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + void SetInputResponsePending() override {} + // cherry-pick from google end private: raw_ptr layer_tree_host_; }; diff --git a/cc/trees/layer_tree_host.h b/cc/trees/layer_tree_host.h index 0e92854e7f7a638d781f9c4dde6cfe8b0e48f250..48bb5eb965a767d1516af9f5a253af5c4063690d 100644 --- a/cc/trees/layer_tree_host.h +++ b/cc/trees/layer_tree_host.h @@ -905,7 +905,12 @@ void RegisterClippedVisualViewportSelectionBounds( [[nodiscard]] base::AutoReset SimulateSyncingDeltasForTesting() { return base::AutoReset(&syncing_deltas_for_test_, true); } - + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + bool WaitedForCommitForTesting() const { + return waited_for_protected_sequence_; + } + // cherry-pick from google end void IncrementVisualUpdateDuration(base::TimeDelta visual_update_duration); #if BUILDFLAG(IS_OHOS) diff --git a/cc/trees/proxy.h b/cc/trees/proxy.h index 44f02bf68cfbe9a35e1e539d21e85cdca6537756..907290491caa90eb3370a998995fa5f39cbe30e5 100644 --- a/cc/trees/proxy.h +++ b/cc/trees/proxy.h @@ -66,6 +66,13 @@ class CC_EXPORT Proxy { // Pauses all main and impl-side rendering. virtual void SetPauseRendering(bool pause_rendering) = 0; + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + // Indicates that the next main frame will contain the result of running an + // event handler for an input event. + virtual void SetInputResponsePending() = 0; + // cherry-pick from google end + // Defers commits until at most the given |timeout| period has passed, // but continues to update the document lifecycle in // LayerTreeHost::BeginMainFrameUpdate. If multiple calls are made when diff --git a/cc/trees/proxy_impl.cc b/cc/trees/proxy_impl.cc index b2952fc5ab8092884479cc2e9160f61fca6ae77e..67d76cec8e3dd2d165b438fc021f176b34592bcf 100644 --- a/cc/trees/proxy_impl.cc +++ b/cc/trees/proxy_impl.cc @@ -62,17 +62,30 @@ class ScopedCommitCompletionEvent { CompletionEvent* event, base::TimeTicks start_time, base::SingleThreadTaskRunner* main_thread_task_runner, + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + bool notify_main, + // cherry-pick from google end base::WeakPtr proxy_main_weak_ptr) : event_(event), commit_timestamps_({start_time, base::TimeTicks()}), main_thread_task_runner_(main_thread_task_runner), + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + notify_main_(notify_main), + // cherry-pick from google end proxy_main_weak_ptr_(proxy_main_weak_ptr) {} ScopedCommitCompletionEvent(const ScopedCommitCompletionEvent&) = delete; ~ScopedCommitCompletionEvent() { event_.ExtractAsDangling()->Signal(); + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + if (notify_main_) { main_thread_task_runner_->PostTask( FROM_HERE, base::BindOnce(&ProxyMain::DidCompleteCommit, proxy_main_weak_ptr_, commit_timestamps_)); + } + // cherry-pick from google end } ScopedCommitCompletionEvent& operator=(const ScopedCommitCompletionEvent&) = delete; @@ -85,6 +98,10 @@ class ScopedCommitCompletionEvent { raw_ptr event_; CommitTimestamps commit_timestamps_; raw_ptr main_thread_task_runner_; + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + bool notify_main_; + // cherry-pick from google end base::WeakPtr proxy_main_weak_ptr_; }; @@ -374,8 +391,15 @@ void ProxyImpl::NotifyReadyToCommitOnImpl( // variable on the call stack of the main thread. If NonBlockingCommit is // enabled, then the commit timestamps are transmitted back to the main thread // by ScopedCommitCompletionEvent. - DCHECK_NE((bool)commit_timestamps, - base::FeatureList::IsEnabled(features::kNonBlockingCommit)); + + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + // DCHECK_NE((bool)commit_timestamps, + // base::FeatureList::IsEnabled(features::kNonBlockingCommit)); + DCHECK_EQ((bool)commit_timestamps, + task_runner_provider_->IsMainThreadBlocked()); + // cherry-pick from google end + base::TimeTicks start_time = base::TimeTicks::Now(); if (commit_timestamps) commit_timestamps->start = start_time; @@ -399,6 +423,10 @@ void ProxyImpl::NotifyReadyToCommitOnImpl( data_for_commit_ = std::make_unique( std::make_unique( completion_event, start_time, MainThreadTaskRunner(), + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + /*notify_main*/!commit_timestamps, + // cherry-pick from google end proxy_main_weak_ptr_), std::move(commit_state), unsafe_state, commit_timestamps); hung_commit_timer_.Start( diff --git a/cc/trees/proxy_main.cc b/cc/trees/proxy_main.cc index d48bf2e191642da076b5228dae87c4df3a06ed16..bda4accdc49e836ba5624500a3765a3813c05569 100644 --- a/cc/trees/proxy_main.cc +++ b/cc/trees/proxy_main.cc @@ -245,6 +245,13 @@ void ProxyMain::BeginMainFrame( commit_timeout = true; } + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + bool blocking = !base::FeatureList::IsEnabled(features::kNonBlockingCommit) || + block_on_next_commit_; + block_on_next_commit_ = false; + // cherry-pick from google end + bool scroll_and_viewport_changes_synced = false; if (!IsDeferringCommits()) { // Synchronizes scroll offsets and page scale deltas (for pinch zoom) from @@ -434,7 +441,12 @@ void ProxyMain::BeginMainFrame( // point of view, but asynchronously performed on the impl thread, // coordinated by the Scheduler. CommitTimestamps commit_timestamps; - bool blocking = !base::FeatureList::IsEnabled(features::kNonBlockingCommit); + + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + // bool blocking = !base::FeatureList::IsEnabled(features::kNonBlockingCommit); + // cherry-pick from google end + { TRACE_EVENT_WITH_FLOW0("viz,benchmark", "MainFrame.NotifyReadyToCommitOnMain", @@ -647,6 +659,17 @@ void ProxyMain::SetPauseRendering(bool pause_rendering) { base::Unretained(proxy_impl_.get()), pause_rendering_)); } + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + void ProxyMain::SetInputResponsePending() { + // If the next main frame will contain the visual response to an input event, + // we pause execution on the main thread until the compositor thread finishes + // processing the commit. This is done to minimize thread contention while + // the compositor is doing critical-path work. + block_on_next_commit_ = true; +} + // cherry-pick from google end + bool ProxyMain::StartDeferringCommits(base::TimeDelta timeout, PaintHoldingReason reason) { DCHECK(task_runner_provider_->IsMainThread()); diff --git a/cc/trees/proxy_main.h b/cc/trees/proxy_main.h index 359bf6964cfc5a7b0fbbb3b2447459be30f7debe..32a41eda4ea93b4ab972364ec1ed8d3f510648dc 100644 --- a/cc/trees/proxy_main.h +++ b/cc/trees/proxy_main.h @@ -111,6 +111,10 @@ class CC_EXPORT ProxyMain : public Proxy { bool RequestedAnimatePending() override; void SetDeferMainFrameUpdate(bool defer_main_frame_update) override; void SetPauseRendering(bool pause_rendering) override; + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + void SetInputResponsePending() override; + // cherry-pick from google end bool StartDeferringCommits(base::TimeDelta timeout, PaintHoldingReason reason) override; void StopDeferringCommits(PaintHoldingCommitTrigger) override; @@ -181,6 +185,10 @@ class CC_EXPORT ProxyMain : public Proxy { absl::optional paint_holding_reason_; bool pause_rendering_; + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + bool block_on_next_commit_ = false; + // cherry-pick from google end // Only used when defer_commits_ is active and must be set in such cases. base::TimeTicks commits_restart_time_; diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc index 797a4a0c9850f5ad6a7314e20c36ea273d9a76f8..551a3050d106287898fc7091089198774c03d050 100644 --- a/cc/trees/single_thread_proxy.cc +++ b/cc/trees/single_thread_proxy.cc @@ -374,6 +374,11 @@ void SingleThreadProxy::SetPauseRendering(bool pause_rendering) { scheduler_on_impl_thread_->SetPauseRendering(pause_rendering_); } + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + void SingleThreadProxy::SetInputResponsePending() {} + // cherry-pick from google end + bool SingleThreadProxy::StartDeferringCommits(base::TimeDelta timeout, PaintHoldingReason reason) { DCHECK(task_runner_provider_->IsMainThread()); diff --git a/cc/trees/single_thread_proxy.h b/cc/trees/single_thread_proxy.h index a148dd2839b36e865f50f76c6d2ada6f9bf32373..e155cee4463d6a3ed389afc5fe428ec2e6af43d2 100644 --- a/cc/trees/single_thread_proxy.h +++ b/cc/trees/single_thread_proxy.h @@ -63,6 +63,10 @@ class CC_EXPORT SingleThreadProxy : public Proxy, bool RequestedAnimatePending() override; void SetDeferMainFrameUpdate(bool defer_main_frame_update) override; void SetPauseRendering(bool pause_rendering) override; + // cherry-pick from google begin + // https://chromium-review.googlesource.com/c/chromium/src/+/4546241 + void SetInputResponsePending() override; + // cherry-pick from google end bool StartDeferringCommits(base::TimeDelta timeout, PaintHoldingReason reason) override; void StopDeferringCommits(PaintHoldingCommitTrigger) override;