1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/compositor/compositor_vsync_manager.h"
6
7 namespace ui {
8
CompositorVSyncManager()9 CompositorVSyncManager::CompositorVSyncManager()
10 : observer_list_(new ObserverListThreadSafe<Observer>()),
11 authoritative_vsync_interval_(base::TimeDelta::FromSeconds(0)) {}
12
~CompositorVSyncManager()13 CompositorVSyncManager::~CompositorVSyncManager() {}
14
SetAuthoritativeVSyncInterval(base::TimeDelta interval)15 void CompositorVSyncManager::SetAuthoritativeVSyncInterval(
16 base::TimeDelta interval) {
17 base::TimeTicks timebase;
18 {
19 base::AutoLock lock(vsync_parameters_lock_);
20 timebase = last_timebase_;
21 authoritative_vsync_interval_ = interval;
22 last_interval_ = interval;
23 }
24 NotifyObservers(timebase, interval);
25 }
26
UpdateVSyncParameters(base::TimeTicks timebase,base::TimeDelta interval)27 void CompositorVSyncManager::UpdateVSyncParameters(base::TimeTicks timebase,
28 base::TimeDelta interval) {
29 {
30 base::AutoLock lock(vsync_parameters_lock_);
31 if (authoritative_vsync_interval_ != base::TimeDelta::FromSeconds(0))
32 interval = authoritative_vsync_interval_;
33 last_timebase_ = timebase;
34 last_interval_ = interval;
35 }
36 NotifyObservers(timebase, interval);
37 }
38
AddObserver(Observer * observer)39 void CompositorVSyncManager::AddObserver(Observer* observer) {
40 base::TimeTicks timebase;
41 base::TimeDelta interval;
42 {
43 base::AutoLock lock(vsync_parameters_lock_);
44 timebase = last_timebase_;
45 interval = last_interval_;
46 }
47 observer_list_->AddObserver(observer);
48 observer->OnUpdateVSyncParameters(timebase, interval);
49 }
50
RemoveObserver(Observer * observer)51 void CompositorVSyncManager::RemoveObserver(Observer* observer) {
52 observer_list_->RemoveObserver(observer);
53 }
54
NotifyObservers(base::TimeTicks timebase,base::TimeDelta interval)55 void CompositorVSyncManager::NotifyObservers(base::TimeTicks timebase,
56 base::TimeDelta interval) {
57 observer_list_->Notify(
58 &CompositorVSyncManager::Observer::OnUpdateVSyncParameters,
59 timebase,
60 interval);
61 }
62
63 } // namespace ui
64