1 // Copyright (c) 2013 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_GL_VSYNC_PROVIDER_H_
6 #define UI_GL_VSYNC_PROVIDER_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/time.h"
19 virtual ~VSyncProvider();
21 typedef base::Callback
<void(const base::TimeTicks timebase
,
22 const base::TimeDelta interval
)>
25 // Get the time of the most recent screen refresh, along with the time
26 // between consecutive refreshes. The callback is called as soon as
27 // the data is available: it could be immediately from this method,
28 // later via a PostTask to the current MessageLoop, or never (if we have
29 // no data source). We provide the strong guarantee that the callback will
30 // not be called once the instance of this class is destroyed.
31 virtual void GetVSyncParameters(const UpdateVSyncCallback
& callback
) = 0;
34 DISALLOW_COPY_AND_ASSIGN(VSyncProvider
);
37 // Base class for providers based on extensions like GLX_OML_sync_control and
38 // EGL_CHROMIUM_sync_control.
39 class SyncControlVSyncProvider
: public VSyncProvider
{
41 SyncControlVSyncProvider();
42 virtual ~SyncControlVSyncProvider();
44 virtual void GetVSyncParameters(
45 const UpdateVSyncCallback
& callback
) OVERRIDE
;
48 virtual bool GetSyncValues(int64
* system_time
,
49 int64
* media_stream_counter
,
50 int64
* swap_buffer_counter
) = 0;
52 virtual bool GetMscRate(int32
* numerator
, int32
* denominator
) = 0;
55 base::TimeTicks last_timebase_
;
56 uint64 last_media_stream_counter_
;
57 base::TimeDelta last_good_interval_
;
59 // A short history of the last few computed intervals.
60 // We use this to filter out the noise in the computation resulting
61 // from configuration change (monitor reconfiguration, moving windows
62 // between monitors, suspend and resume, etc.).
63 std::queue
<base::TimeDelta
> last_computed_intervals_
;
65 DISALLOW_COPY_AND_ASSIGN(SyncControlVSyncProvider
);
70 #endif // UI_GL_VSYNC_PROVIDER_H_