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

Side by Side Diff: ui/compositor/compositor.cc

Issue 2870023002: Allow compositor locks to extend timeout. (Closed)
Patch Set: 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 unified diff | Download patch
« ui/compositor/compositor.h ('K') | « ui/compositor/compositor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <deque> 10 #include <deque>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 Compositor::Compositor(const cc::FrameSinkId& frame_sink_id, 51 Compositor::Compositor(const cc::FrameSinkId& frame_sink_id,
52 ui::ContextFactory* context_factory, 52 ui::ContextFactory* context_factory,
53 ui::ContextFactoryPrivate* context_factory_private, 53 ui::ContextFactoryPrivate* context_factory_private,
54 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
55 : context_factory_(context_factory), 55 : context_factory_(context_factory),
56 context_factory_private_(context_factory_private), 56 context_factory_private_(context_factory_private),
57 frame_sink_id_(frame_sink_id), 57 frame_sink_id_(frame_sink_id),
58 task_runner_(task_runner), 58 task_runner_(task_runner),
59 vsync_manager_(new CompositorVSyncManager()), 59 vsync_manager_(new CompositorVSyncManager()),
60 layer_animator_collection_(this), 60 layer_animator_collection_(this),
61 scheduled_timeout_(base::TimeTicks()),
62 allow_locks_to_extend_timeout_(false),
61 weak_ptr_factory_(this), 63 weak_ptr_factory_(this),
62 lock_timeout_weak_ptr_factory_(this) { 64 lock_timeout_weak_ptr_factory_(this) {
63 if (context_factory_private) { 65 if (context_factory_private) {
64 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId( 66 context_factory_private->GetSurfaceManager()->RegisterFrameSinkId(
65 frame_sink_id_); 67 frame_sink_id_);
66 } 68 }
67 root_web_layer_ = cc::Layer::Create(); 69 root_web_layer_ = cc::Layer::Create();
68 70
69 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
70 72
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 std::unique_ptr<CompositorLock> Compositor::GetCompositorLock( 543 std::unique_ptr<CompositorLock> Compositor::GetCompositorLock(
542 CompositorLockClient* client, 544 CompositorLockClient* client,
543 base::TimeDelta timeout) { 545 base::TimeDelta timeout) {
544 // This uses the main WeakPtrFactory to break the connection from the lock to 546 // This uses the main WeakPtrFactory to break the connection from the lock to
545 // the Compositor when the Compositor is destroyed. 547 // the Compositor when the Compositor is destroyed.
546 auto lock = 548 auto lock =
547 base::MakeUnique<CompositorLock>(client, weak_ptr_factory_.GetWeakPtr()); 549 base::MakeUnique<CompositorLock>(client, weak_ptr_factory_.GetWeakPtr());
548 bool was_empty = active_locks_.empty(); 550 bool was_empty = active_locks_.empty();
549 active_locks_.push_back(lock.get()); 551 active_locks_.push_back(lock.get());
550 552
553 bool should_extend_timeout = false;
554 if ((was_empty || allow_locks_to_extend_timeout_) && !timeout.is_zero()) {
555 const base::TimeTicks time_to_timeout = base::TimeTicks::Now() + timeout;
556 // For the first lock, scheduled_timeout.is_null is true,
557 // |time_to_timeout| will always larger than |scheduled_timeout_|. And it
558 // is ok to invalidate the weakptr of |lock_timeout_weak_ptr_factory_|.
559 if (time_to_timeout > scheduled_timeout_) {
560 scheduled_timeout_ = time_to_timeout;
561 should_extend_timeout = true;
562 lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs();
563 }
564 }
565
551 if (was_empty) { 566 if (was_empty) {
552 host_->SetDeferCommits(true); 567 host_->SetDeferCommits(true);
553 for (auto& observer : observer_list_) 568 for (auto& observer : observer_list_)
554 observer.OnCompositingLockStateChanged(this); 569 observer.OnCompositingLockStateChanged(this);
570 }
555 571
556 if (!timeout.is_zero()) { 572 if (should_extend_timeout) {
557 // The timeout task uses an independent WeakPtrFactory that is invalidated 573 // The timeout task uses an independent WeakPtrFactory that is invalidated
558 // when all locks are ended to prevent the timeout from leaking into 574 // when all locks are ended to prevent the timeout from leaking into
559 // another lock that should have its own timeout. 575 // another lock that should have its own timeout.
560 task_runner_->PostDelayedTask( 576 task_runner_->PostDelayedTask(
561 FROM_HERE, 577 FROM_HERE,
562 base::Bind(&Compositor::TimeoutLocks, 578 base::Bind(&Compositor::TimeoutLocks,
563 lock_timeout_weak_ptr_factory_.GetWeakPtr()), 579 lock_timeout_weak_ptr_factory_.GetWeakPtr()),
564 timeout); 580 timeout);
565 }
566 } 581 }
567 return lock; 582 return lock;
568 } 583 }
569 584
570 void Compositor::RemoveCompositorLock(CompositorLock* lock) { 585 void Compositor::RemoveCompositorLock(CompositorLock* lock) {
571 base::Erase(active_locks_, lock); 586 base::Erase(active_locks_, lock);
572 if (active_locks_.empty()) { 587 if (active_locks_.empty()) {
573 host_->SetDeferCommits(false); 588 host_->SetDeferCommits(false);
574 for (auto& observer : observer_list_) 589 for (auto& observer : observer_list_)
575 observer.OnCompositingLockStateChanged(this); 590 observer.OnCompositingLockStateChanged(this);
576 lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs(); 591 lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs();
592 scheduled_timeout_ = base::TimeTicks();
577 } 593 }
578 } 594 }
579 595
580 void Compositor::TimeoutLocks() { 596 void Compositor::TimeoutLocks() {
581 // Make a copy, we're going to cause |active_locks_| to become 597 // Make a copy, we're going to cause |active_locks_| to become
582 // empty. 598 // empty.
583 std::vector<CompositorLock*> locks = active_locks_; 599 std::vector<CompositorLock*> locks = active_locks_;
584 for (auto* lock : locks) 600 for (auto* lock : locks)
585 lock->TimeoutLock(); 601 lock->TimeoutLock();
586 DCHECK(active_locks_.empty()); 602 DCHECK(active_locks_.empty());
587 } 603 }
588 604
589 } // namespace ui 605 } // namespace ui
OLDNEW
« ui/compositor/compositor.h ('K') | « ui/compositor/compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698