blob: 11d4d01635c8fb6566b6e8c9a2d8fd22ce82730d [file] [log] [blame]
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08001#ifndef ANDROID_DVR_GRAPHICS_TIMER_QUERY_H_
2#define ANDROID_DVR_GRAPHICS_TIMER_QUERY_H_
3
4#include <GLES3/gl3.h>
5
6namespace android {
7namespace dvr {
8
9// Class used to asynchronously query time between draw calls on gpu.
10class TimerQuery {
11 public:
12 TimerQuery();
13 ~TimerQuery();
14
15 // Marks the start of the timer on gpu.
16 void Begin();
17
18 // Marks the end of the timer on gpu.
19 void End();
20
21 // Gets the time that has passed from call to Begin to End.
22 // Should be called only after the frame has been presented (after the call to
23 // swapbuffers).
24 double GetTimeInMS();
25
26 private:
27 // Generates OpenGL query object.
28 void Init();
29 // Deletes OpenGL query object.
30 void Delete();
31
32 GLuint query_ = 0;
33
34 friend class SyncTimerQuery;
35};
36
37// Simplification of TimerQuery that allows to synchronously query time used
38// for draw calls on gpu by doing glFlush and stalling cpu.
39class SyncTimerQuery {
40 public:
41 SyncTimerQuery();
42
43 double FlushAndGetTimeInMS(); // Note: This WILL cause a glFlush()
44
45 private:
46 TimerQuery timer_;
47};
48
49} // namespace dvr
50} // namespace android
51
52#endif // ANDROID_DVR_GRAPHICS_TIMER_QUERY_H_