| OLD | NEW |
| 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 Loading... |
| 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 std::unique_ptr<CompositorLock> Compositor::GetCompositorLock( | 548 std::unique_ptr<CompositorLock> Compositor::GetCompositorLock( |
| 547 CompositorLockClient* client, | 549 CompositorLockClient* client, |
| 548 base::TimeDelta timeout) { | 550 base::TimeDelta timeout) { |
| 549 // This uses the main WeakPtrFactory to break the connection from the lock to | 551 // This uses the main WeakPtrFactory to break the connection from the lock to |
| 550 // the Compositor when the Compositor is destroyed. | 552 // the Compositor when the Compositor is destroyed. |
| 551 auto lock = | 553 auto lock = |
| 552 base::MakeUnique<CompositorLock>(client, weak_ptr_factory_.GetWeakPtr()); | 554 base::MakeUnique<CompositorLock>(client, weak_ptr_factory_.GetWeakPtr()); |
| 553 bool was_empty = active_locks_.empty(); | 555 bool was_empty = active_locks_.empty(); |
| 554 active_locks_.push_back(lock.get()); | 556 active_locks_.push_back(lock.get()); |
| 555 | 557 |
| 558 bool should_extend_timeout = false; |
| 559 if ((was_empty || allow_locks_to_extend_timeout_) && !timeout.is_zero()) { |
| 560 const base::TimeTicks time_to_timeout = base::TimeTicks::Now() + timeout; |
| 561 // For the first lock, scheduled_timeout.is_null is true, |
| 562 // |time_to_timeout| will always larger than |scheduled_timeout_|. And it |
| 563 // is ok to invalidate the weakptr of |lock_timeout_weak_ptr_factory_|. |
| 564 if (time_to_timeout > scheduled_timeout_) { |
| 565 scheduled_timeout_ = time_to_timeout; |
| 566 should_extend_timeout = true; |
| 567 lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 568 } |
| 569 } |
| 570 |
| 556 if (was_empty) { | 571 if (was_empty) { |
| 557 host_->SetDeferCommits(true); | 572 host_->SetDeferCommits(true); |
| 558 for (auto& observer : observer_list_) | 573 for (auto& observer : observer_list_) |
| 559 observer.OnCompositingLockStateChanged(this); | 574 observer.OnCompositingLockStateChanged(this); |
| 575 } |
| 560 | 576 |
| 561 if (!timeout.is_zero()) { | 577 if (should_extend_timeout) { |
| 562 // The timeout task uses an independent WeakPtrFactory that is invalidated | 578 // The timeout task uses an independent WeakPtrFactory that is invalidated |
| 563 // when all locks are ended to prevent the timeout from leaking into | 579 // when all locks are ended to prevent the timeout from leaking into |
| 564 // another lock that should have its own timeout. | 580 // another lock that should have its own timeout. |
| 565 task_runner_->PostDelayedTask( | 581 task_runner_->PostDelayedTask( |
| 566 FROM_HERE, | 582 FROM_HERE, |
| 567 base::Bind(&Compositor::TimeoutLocks, | 583 base::Bind(&Compositor::TimeoutLocks, |
| 568 lock_timeout_weak_ptr_factory_.GetWeakPtr()), | 584 lock_timeout_weak_ptr_factory_.GetWeakPtr()), |
| 569 timeout); | 585 timeout); |
| 570 } | |
| 571 } | 586 } |
| 572 return lock; | 587 return lock; |
| 573 } | 588 } |
| 574 | 589 |
| 575 void Compositor::RemoveCompositorLock(CompositorLock* lock) { | 590 void Compositor::RemoveCompositorLock(CompositorLock* lock) { |
| 576 base::Erase(active_locks_, lock); | 591 base::Erase(active_locks_, lock); |
| 577 if (active_locks_.empty()) { | 592 if (active_locks_.empty()) { |
| 578 host_->SetDeferCommits(false); | 593 host_->SetDeferCommits(false); |
| 579 for (auto& observer : observer_list_) | 594 for (auto& observer : observer_list_) |
| 580 observer.OnCompositingLockStateChanged(this); | 595 observer.OnCompositingLockStateChanged(this); |
| 581 lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs(); | 596 lock_timeout_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 597 scheduled_timeout_ = base::TimeTicks(); |
| 582 } | 598 } |
| 583 } | 599 } |
| 584 | 600 |
| 585 void Compositor::TimeoutLocks() { | 601 void Compositor::TimeoutLocks() { |
| 586 // Make a copy, we're going to cause |active_locks_| to become | 602 // Make a copy, we're going to cause |active_locks_| to become |
| 587 // empty. | 603 // empty. |
| 588 std::vector<CompositorLock*> locks = active_locks_; | 604 std::vector<CompositorLock*> locks = active_locks_; |
| 589 for (auto* lock : locks) | 605 for (auto* lock : locks) |
| 590 lock->TimeoutLock(); | 606 lock->TimeoutLock(); |
| 591 DCHECK(active_locks_.empty()); | 607 DCHECK(active_locks_.empty()); |
| 592 } | 608 } |
| 593 | 609 |
| 594 } // namespace ui | 610 } // namespace ui |
| OLD | NEW |