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 #ifndef UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_
6 #define UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/observer_list.h"
10 #include "base/synchronization/lock.h"
11 #include "base/time/time.h"
12 #include "ui/compositor/compositor_export.h"
16 // This class manages vsync parameters for a compositor. It merges updates of
17 // the parameters from different sources and sends the merged updates to
18 // observers which register to it.
19 class COMPOSITOR_EXPORT CompositorVSyncManager
20 : public base::RefCounted
<CompositorVSyncManager
> {
24 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase
,
25 base::TimeDelta interval
) = 0;
28 CompositorVSyncManager();
30 // The "authoritative" vsync interval, if provided, will override |interval|
31 // as reported by UpdateVSyncParameters() whenever it is called. This is
32 // typically the value reported by a more reliable source, e.g. the platform
33 // display configuration. In the particular case of ChromeOS -- this is the
34 // value queried through XRandR, which is more reliable than the value
35 // queried through the 3D context.
36 void SetAuthoritativeVSyncInterval(base::TimeDelta interval
);
38 // The vsync parameters consist of |timebase|, which is the platform timestamp
39 // of the last vsync, and |interval|, which is the interval between vsyncs.
40 // |interval| may be overriden by SetAuthoritativeVSyncInterval() above.
41 void UpdateVSyncParameters(base::TimeTicks timebase
,
42 base::TimeDelta interval
);
44 void AddObserver(Observer
* observer
);
45 void RemoveObserver(Observer
* observer
);
48 friend class base::RefCounted
<CompositorVSyncManager
>;
50 ~CompositorVSyncManager();
52 void NotifyObservers(base::TimeTicks timebase
, base::TimeDelta interval
);
54 ObserverList
<Observer
> observer_list_
;
56 base::TimeTicks last_timebase_
;
57 base::TimeDelta last_interval_
;
58 base::TimeDelta authoritative_vsync_interval_
;
60 DISALLOW_COPY_AND_ASSIGN(CompositorVSyncManager
);
65 #endif // UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_