[Histograms]: Add histograms for requestIdleCallback.
[chromium-blink-merge.git] / ui / gl / gpu_timing_fake.h
blob33d7bc3d8179a1f80518458e3626cdcae1406403
1 // Copyright 2015 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_GPU_TIMING_FAKE_H_
6 #define UI_GL_GPU_TIMING_FAKE_H_
8 #include <map>
9 #include <set>
11 #include "ui/gl/gl_bindings.h"
13 namespace gfx {
14 class MockGLInterface;
16 class GPUTimingFake {
17 public:
18 GPUTimingFake();
19 ~GPUTimingFake();
21 void Reset();
23 // Used to set the current GPU time queries will return.
24 static int64_t GetFakeCPUTime(); // Useful for binding for Fake CPU time.
25 void SetCurrentCPUTime(int64_t current_time);
26 void SetCurrentGLTime(GLint64 current_time);
27 void SetCPUGLOffset(int64_t offset);
29 // Used to signal a disjoint occurred for disjoint timer queries.
30 void SetDisjoint();
32 // GPUTimer fake queries which can be called multiple times.
33 void ExpectGetErrorCalls(MockGLInterface& gl);
34 void ExpectDisjointCalls(MockGLInterface& gl);
35 void ExpectNoDisjointCalls(MockGLInterface& gl);
37 // GPUTimer fake queries which can only be called once per setup.
38 void ExpectGPUTimeStampQuery(MockGLInterface& gl, bool elapsed_query);
39 void ExpectGPUTimerQuery(MockGLInterface& gl, bool elapsed_query);
40 void ExpectOffsetCalculationQuery(MockGLInterface& gl);
41 void ExpectNoOffsetCalculationQuery(MockGLInterface& gl);
43 // Fake GL Functions.
44 void FakeGLGenQueries(GLsizei n, GLuint* ids);
45 void FakeGLDeleteQueries(GLsizei n, const GLuint* ids);
46 void FakeGLBeginQuery(GLenum target, GLuint id);
47 void FakeGLEndQuery(GLenum target);
48 void FakeGLGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params);
49 void FakeGLQueryCounter(GLuint id, GLenum target);
50 void FakeGLGetInteger64v(GLenum pname, GLint64 * data);
51 void FakeGLGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64* params);
52 void FakeGLGetIntegerv(GLenum pname, GLint* params);
53 GLenum FakeGLGetError();
55 protected:
56 bool disjointed_ = false;
57 static int64_t fake_cpu_time_;
58 GLint64 current_gl_time_ = 0;
59 int64_t gl_cpu_time_offset_ = 0;
60 GLuint next_query_id_ = 0;
61 std::set<GLuint> allocated_queries_;
62 struct QueryResult {
63 enum QueryResultType {
64 kQueryResultType_Invalid,
65 kQueryResultType_TimeStamp,
66 kQueryResultType_Elapsed
67 } type_ = kQueryResultType_Invalid;
68 GLint64 begin_time_ = 0;
69 GLint64 value_ = 0;
71 std::map<GLuint, QueryResult> query_results_;
72 struct ElapsedQuery {
73 bool active_ = false;
74 GLuint query_id_ = 0;
75 GLint64 begin_time_ = 0;
77 void Reset() {
78 active_ = false;
79 query_id_ = 0;
80 begin_time_ = 0;
83 ElapsedQuery current_elapsed_query_;
86 } // namespace gfx
88 #endif // UI_GL_GPU_TIMING_FAKE_H_