Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(725)

Unified Diff: ui/compositor/compositor.cc

Issue 2870023002: Allow compositor locks to extend timeout. (Closed)
Patch Set: Rebase. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/compositor_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/compositor.cc
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index 73644716cd17c1fe25f86a5e2204998ba6f79e42..e499f5f567706ff8697bbdb18f4a02851a376fc4 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -58,6 +58,8 @@ Compositor::Compositor(const cc::FrameSinkId& frame_sink_id,
task_runner_(task_runner),
vsync_manager_(new CompositorVSyncManager()),
layer_animator_collection_(this),
+ scheduled_timeout_(base::TimeTicks()),
+ allow_locks_to_extend_timeout_(false),
weak_ptr_factory_(this),
lock_timeout_weak_ptr_factory_(this) {
if (context_factory_private) {
@@ -553,21 +555,34 @@ std::unique_ptr<CompositorLock> Compositor::GetCompositorLock(
bool was_empty = active_locks_.empty();
active_locks_.push_back(lock.get());
+ bool should_extend_timeout = false;
+ if ((was_empty || allow_locks_to_extend_timeout_) && !timeout.is_zero()) {
+ const base::TimeTicks time_to_timeout = base::TimeTicks::Now() + timeout;
+ // For the first lock, scheduled_timeout.is_null is true,
+ // |time_to_timeout| will always larger than |scheduled_timeout_|. And it
+ // is ok to invalidate the weakptr of |lock_timeout_weak_ptr_factory_|.
+ if (time_to_timeout > scheduled_timeout_) {
+ scheduled_timeout_ = time_to_timeout;
+ should_extend_timeout = true;
+ lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs();
+ }
+ }
+
if (was_empty) {
host_->SetDeferCommits(true);
for (auto& observer : observer_list_)
observer.OnCompositingLockStateChanged(this);
+ }
- if (!timeout.is_zero()) {
- // The timeout task uses an independent WeakPtrFactory that is invalidated
- // when all locks are ended to prevent the timeout from leaking into
- // another lock that should have its own timeout.
- task_runner_->PostDelayedTask(
- FROM_HERE,
- base::Bind(&Compositor::TimeoutLocks,
- lock_timeout_weak_ptr_factory_.GetWeakPtr()),
- timeout);
- }
+ if (should_extend_timeout) {
+ // The timeout task uses an independent WeakPtrFactory that is invalidated
+ // when all locks are ended to prevent the timeout from leaking into
+ // another lock that should have its own timeout.
+ task_runner_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&Compositor::TimeoutLocks,
+ lock_timeout_weak_ptr_factory_.GetWeakPtr()),
+ timeout);
}
return lock;
}
@@ -579,6 +594,7 @@ void Compositor::RemoveCompositorLock(CompositorLock* lock) {
for (auto& observer : observer_list_)
observer.OnCompositingLockStateChanged(this);
lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs();
+ scheduled_timeout_ = base::TimeTicks();
}
}
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/compositor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698