Revert 219061 "Introduce facade for interaction with Android Sur..."
[chromium-blink-merge.git] / ui / gl / vsync_provider.h
blobb9cef7a8b9b5f89733b32c14fe76ee25e741baf9
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_
8 #include <queue>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/time/time.h"
13 #include "ui/gl/gl_export.h"
15 namespace gfx {
17 class GL_EXPORT VSyncProvider {
18 public:
19 VSyncProvider();
20 virtual ~VSyncProvider();
22 typedef base::Callback<void(const base::TimeTicks timebase,
23 const base::TimeDelta interval)>
24 UpdateVSyncCallback;
26 // Get the time of the most recent screen refresh, along with the time
27 // between consecutive refreshes. The callback is called as soon as
28 // the data is available: it could be immediately from this method,
29 // later via a PostTask to the current MessageLoop, or never (if we have
30 // no data source). We provide the strong guarantee that the callback will
31 // not be called once the instance of this class is destroyed.
32 virtual void GetVSyncParameters(const UpdateVSyncCallback& callback) = 0;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(VSyncProvider);
38 // Base class for providers based on extensions like GLX_OML_sync_control and
39 // EGL_CHROMIUM_sync_control.
40 class SyncControlVSyncProvider : public VSyncProvider {
41 public:
42 SyncControlVSyncProvider();
43 virtual ~SyncControlVSyncProvider();
45 virtual void GetVSyncParameters(
46 const UpdateVSyncCallback& callback) OVERRIDE;
48 protected:
49 virtual bool GetSyncValues(int64* system_time,
50 int64* media_stream_counter,
51 int64* swap_buffer_counter) = 0;
53 virtual bool GetMscRate(int32* numerator, int32* denominator) = 0;
55 private:
56 base::TimeTicks last_timebase_;
57 uint64 last_media_stream_counter_;
58 base::TimeDelta last_good_interval_;
60 // A short history of the last few computed intervals.
61 // We use this to filter out the noise in the computation resulting
62 // from configuration change (monitor reconfiguration, moving windows
63 // between monitors, suspend and resume, etc.).
64 std::queue<base::TimeDelta> last_computed_intervals_;
66 DISALLOW_COPY_AND_ASSIGN(SyncControlVSyncProvider);
69 } // namespace gfx
71 #endif // UI_GL_VSYNC_PROVIDER_H_