OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 // These constants define a reasonable range for a calculated refresh interval. | |
8 // Calculating refreshes out of this range will be considered a fatal error. | |
9 const int64 kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400; | |
10 const int64 kMaxVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 10; | |
11 | |
12 namespace ui { | |
13 | |
14 CompositorVSyncManager::CompositorVSyncManager() | |
15 : observer_list_(new ObserverListThreadSafe<Observer>()), | |
16 authoritative_vsync_interval_(base::TimeDelta::FromSeconds(0)) {} | |
17 | |
18 CompositorVSyncManager::~CompositorVSyncManager() {} | |
19 | |
20 void CompositorVSyncManager::SetAuthoritativeVSyncInterval( | |
21 base::TimeDelta interval) { | |
22 base::AutoLock lock(vsync_parameters_lock_); | |
23 authoritative_vsync_interval_ = interval; | |
24 NotifyObservers(last_timebase_, authoritative_vsync_interval_); | |
piman
2014/02/04 22:52:54
nit: release the lock before NotifyObservers, to m
| |
25 } | |
26 | |
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 } | |
34 NotifyObservers(timebase, interval); | |
35 } | |
36 | |
37 void CompositorVSyncManager::AddObserver(Observer* observer) { | |
38 observer_list_->AddObserver(observer); | |
39 observer->OnUpdateVSyncParameters(last_timebase_, last_interval_); | |
40 } | |
41 | |
42 void CompositorVSyncManager::RemoveObserver(Observer* observer) { | |
43 observer_list_->RemoveObserver(observer); | |
44 } | |
45 | |
46 void CompositorVSyncManager::NotifyObservers(base::TimeTicks timebase, | |
47 base::TimeDelta interval) { | |
48 // The vsync interval reported here controls the repaint rate of the | |
49 // compositor. If too low, kill the process instead of silently appearing to | |
50 // hang the UI. | |
51 if (interval.InMicroseconds() < kMinVsyncIntervalUs || | |
52 interval.InMicroseconds() > kMaxVsyncIntervalUs) { | |
53 LOG(FATAL) << "Calculated bogus refresh interval of " | |
54 << interval.InMicroseconds() << " us."; | |
55 } | |
56 | |
57 last_timebase_ = timebase; | |
58 last_interval_ = interval; | |
piman
2014/02/04 22:52:54
acquire lock while modifying these 2.
| |
59 observer_list_->Notify( | |
60 &CompositorVSyncManager::Observer::OnUpdateVSyncParameters, | |
61 timebase, | |
62 interval); | |
63 } | |
64 | |
65 } // namespace ui | |
OLD | NEW |