| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_ | 5 #ifndef UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_ |
| 6 #define UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_ | 6 #define UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "cc/scheduler/vsync_observer.h" |
| 13 #include "ui/compositor/compositor_export.h" | 14 #include "ui/compositor/compositor_export.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 | 17 |
| 17 // This class manages vsync parameters for a compositor. It merges updates of | 18 // This class manages vsync parameters for a compositor. It merges updates of |
| 18 // the parameters from different sources and sends the merged updates to | 19 // the parameters from different sources and sends the merged updates to |
| 19 // observers which register to it. | 20 // observers which register to it. |
| 20 class COMPOSITOR_EXPORT CompositorVSyncManager | 21 class COMPOSITOR_EXPORT CompositorVSyncManager |
| 21 : public base::RefCounted<CompositorVSyncManager> { | 22 : public base::RefCounted<CompositorVSyncManager> { |
| 22 public: | 23 public: |
| 23 class Observer { | |
| 24 public: | |
| 25 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase, | |
| 26 base::TimeDelta interval) = 0; | |
| 27 }; | |
| 28 | |
| 29 CompositorVSyncManager(); | 24 CompositorVSyncManager(); |
| 30 | 25 |
| 31 // The "authoritative" vsync interval, if provided, will override |interval| | 26 // The "authoritative" vsync interval, if provided, will override |interval| |
| 32 // as reported by UpdateVSyncParameters() whenever it is called. This is | 27 // as reported by UpdateVSyncParameters() whenever it is called. This is |
| 33 // typically the value reported by a more reliable source, e.g. the platform | 28 // typically the value reported by a more reliable source, e.g. the platform |
| 34 // display configuration. In the particular case of ChromeOS -- this is the | 29 // display configuration. In the particular case of ChromeOS -- this is the |
| 35 // value queried through XRandR, which is more reliable than the value | 30 // value queried through XRandR, which is more reliable than the value |
| 36 // queried through the 3D context. | 31 // queried through the 3D context. |
| 37 void SetAuthoritativeVSyncInterval(base::TimeDelta interval); | 32 void SetAuthoritativeVSyncInterval(base::TimeDelta interval); |
| 38 | 33 |
| 39 // The vsync parameters consist of |timebase|, which is the platform timestamp | 34 // The vsync parameters consist of |timebase|, which is the platform timestamp |
| 40 // of the last vsync, and |interval|, which is the interval between vsyncs. | 35 // of the last vsync, and |interval|, which is the interval between vsyncs. |
| 41 // |interval| may be overriden by SetAuthoritativeVSyncInterval() above. | 36 // |interval| may be overriden by SetAuthoritativeVSyncInterval() above. |
| 42 void UpdateVSyncParameters(base::TimeTicks timebase, | 37 void UpdateVSyncParameters(base::TimeTicks timebase, |
| 43 base::TimeDelta interval); | 38 base::TimeDelta interval); |
| 44 | 39 |
| 45 void AddObserver(Observer* observer); | 40 void AddObserver(cc::VSyncObserver* observer); |
| 46 void RemoveObserver(Observer* observer); | 41 void RemoveObserver(cc::VSyncObserver* observer); |
| 47 | 42 |
| 48 private: | 43 private: |
| 49 friend class base::RefCounted<CompositorVSyncManager>; | 44 friend class base::RefCounted<CompositorVSyncManager>; |
| 50 | 45 |
| 51 ~CompositorVSyncManager(); | 46 ~CompositorVSyncManager(); |
| 52 | 47 |
| 53 void NotifyObservers(base::TimeTicks timebase, base::TimeDelta interval); | 48 void NotifyObservers(base::TimeTicks timebase, base::TimeDelta interval); |
| 54 | 49 |
| 55 base::ObserverList<Observer> observer_list_; | 50 base::ObserverList<cc::VSyncObserver> observer_list_; |
| 56 | 51 |
| 57 base::TimeTicks last_timebase_; | 52 base::TimeTicks last_timebase_; |
| 58 base::TimeDelta last_interval_; | 53 base::TimeDelta last_interval_; |
| 59 base::TimeDelta authoritative_vsync_interval_; | 54 base::TimeDelta authoritative_vsync_interval_; |
| 60 | 55 |
| 61 DISALLOW_COPY_AND_ASSIGN(CompositorVSyncManager); | 56 DISALLOW_COPY_AND_ASSIGN(CompositorVSyncManager); |
| 62 }; | 57 }; |
| 63 | 58 |
| 64 } // namespace ui | 59 } // namespace ui |
| 65 | 60 |
| 66 #endif // UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_ | 61 #endif // UI_COMPOSITOR_COMPOSITOR_VSYNC_MANAGER_H_ |
| OLD | NEW |