[DevTools] Implement DevToolsManager::Observer which notifies about target updates.
[chromium-blink-merge.git] / ui / compositor / compositor_vsync_manager.cc
blob1a10d4ad30965904482b28bedf1d6427d730a12c
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.
5 #include "ui/compositor/compositor_vsync_manager.h"
7 namespace ui {
9 CompositorVSyncManager::CompositorVSyncManager()
10 : observer_list_(new ObserverListThreadSafe<Observer>()),
11 authoritative_vsync_interval_(base::TimeDelta::FromSeconds(0)) {}
13 CompositorVSyncManager::~CompositorVSyncManager() {}
15 void CompositorVSyncManager::SetAuthoritativeVSyncInterval(
16 base::TimeDelta interval) {
17 base::TimeTicks timebase;
19 base::AutoLock lock(vsync_parameters_lock_);
20 timebase = last_timebase_;
21 authoritative_vsync_interval_ = interval;
22 last_interval_ = interval;
24 NotifyObservers(timebase, interval);
27 void CompositorVSyncManager::UpdateVSyncParameters(base::TimeTicks timebase,
28 base::TimeDelta interval) {
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;
36 NotifyObservers(timebase, interval);
39 void CompositorVSyncManager::AddObserver(Observer* observer) {
40 base::TimeTicks timebase;
41 base::TimeDelta interval;
43 base::AutoLock lock(vsync_parameters_lock_);
44 timebase = last_timebase_;
45 interval = last_interval_;
47 observer_list_->AddObserver(observer);
48 observer->OnUpdateVSyncParameters(timebase, interval);
51 void CompositorVSyncManager::RemoveObserver(Observer* observer) {
52 observer_list_->RemoveObserver(observer);
55 void CompositorVSyncManager::NotifyObservers(base::TimeTicks timebase,
56 base::TimeDelta interval) {
57 observer_list_->Notify(
58 &CompositorVSyncManager::Observer::OnUpdateVSyncParameters,
59 timebase,
60 interval);
63 } // namespace ui