- add sources.
[platform/framework/web/crosswalk.git] / src / ui / gl / vsync_provider.h
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.
4
5 #ifndef UI_GL_VSYNC_PROVIDER_H_
6 #define UI_GL_VSYNC_PROVIDER_H_
7
8 #include <queue>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/time/time.h"
13 #include "ui/gl/gl_export.h"
14
15 namespace gfx {
16
17 class GL_EXPORT VSyncProvider {
18  public:
19   VSyncProvider();
20   virtual ~VSyncProvider();
21
22   typedef base::Callback<void(const base::TimeTicks timebase,
23                               const base::TimeDelta interval)>
24       UpdateVSyncCallback;
25
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;
33
34  private:
35   DISALLOW_COPY_AND_ASSIGN(VSyncProvider);
36 };
37
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();
44
45   virtual void GetVSyncParameters(
46       const UpdateVSyncCallback& callback) OVERRIDE;
47
48  protected:
49   virtual bool GetSyncValues(int64* system_time,
50                              int64* media_stream_counter,
51                              int64* swap_buffer_counter) = 0;
52
53   virtual bool GetMscRate(int32* numerator, int32* denominator) = 0;
54
55  private:
56   base::TimeTicks last_timebase_;
57   uint64 last_media_stream_counter_;
58   base::TimeDelta last_good_interval_;
59
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_;
65
66   DISALLOW_COPY_AND_ASSIGN(SyncControlVSyncProvider);
67 };
68
69 }  // namespace gfx
70
71 #endif  // UI_GL_VSYNC_PROVIDER_H_