Add a stub __cxa_demangle to disable LLVM's demangler.
[chromium-blink-merge.git] / ui / gl / gpu_timing_fake.cc
blobe7c1df99d06084ff589c81b65fa8d5c35486cf18
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 #include "ui/gl/gpu_timing_fake.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gl/gl_mock.h"
10 namespace gfx {
12 using ::testing::_;
13 using ::testing::AtLeast;
14 using ::testing::AtMost;
15 using ::testing::Exactly;
16 using ::testing::Invoke;
17 using ::testing::NotNull;
19 GPUTimingFake::GPUTimingFake() {
20 Reset();
23 GPUTimingFake::~GPUTimingFake() {
26 void GPUTimingFake::Reset() {
27 current_time_ = 0;
28 next_query_id_ = 23;
29 allocated_queries_.clear();
30 query_results_.clear();
31 current_elapsed_query_.Reset();
34 void GPUTimingFake::SetCurrentGLTime(GLint64 current_time) {
35 current_time_ = current_time;
38 void GPUTimingFake::SetDisjoint() {
39 disjointed_ = true;
42 void GPUTimingFake::ExpectGetErrorCalls(MockGLInterface& gl) {
43 EXPECT_CALL(gl, GetError()).Times(AtLeast(0))
44 .WillRepeatedly(Invoke(this, &GPUTimingFake::FakeGLGetError));
47 void GPUTimingFake::ExpectDisjointCalls(MockGLInterface& gl) {
48 EXPECT_CALL(gl, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1))
49 .WillRepeatedly(Invoke(this, &GPUTimingFake::FakeGLGetIntegerv));
52 void GPUTimingFake::ExpectNoDisjointCalls(MockGLInterface& gl) {
53 EXPECT_CALL(gl, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0));
56 void GPUTimingFake::ExpectGPUTimerQuery(
57 MockGLInterface& gl, bool elapsed_query) {
58 EXPECT_CALL(gl, GenQueries(1, NotNull())).Times(AtLeast(2))
59 .WillRepeatedly(Invoke(this, &GPUTimingFake::FakeGLGenQueries));
61 if (!elapsed_query) {
62 // Time Stamp based queries.
63 EXPECT_CALL(gl, GetInteger64v(GL_TIMESTAMP, _))
64 .WillRepeatedly(
65 Invoke(this, &GPUTimingFake::FakeGLGetInteger64v));
67 EXPECT_CALL(gl, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(1))
68 .WillRepeatedly(
69 Invoke(this, &GPUTimingFake::FakeGLQueryCounter));
72 // Time Elapsed based queries.
73 EXPECT_CALL(gl, BeginQuery(GL_TIME_ELAPSED, _))
74 .WillRepeatedly(
75 Invoke(this, &GPUTimingFake::FakeGLBeginQuery));
77 EXPECT_CALL(gl, EndQuery(GL_TIME_ELAPSED))
78 .WillRepeatedly(Invoke(this, &GPUTimingFake::FakeGLEndQuery));
80 EXPECT_CALL(gl, GetQueryObjectuiv(_, GL_QUERY_RESULT_AVAILABLE,
81 NotNull()))
82 .WillRepeatedly(
83 Invoke(this, &GPUTimingFake::FakeGLGetQueryObjectuiv));
85 EXPECT_CALL(gl, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull()))
86 .WillRepeatedly(
87 Invoke(this, &GPUTimingFake::FakeGLGetQueryObjectui64v));
89 EXPECT_CALL(gl, DeleteQueries(1, NotNull())).Times(AtLeast(2))
90 .WillRepeatedly(
91 Invoke(this, &GPUTimingFake::FakeGLDeleteQueries));
94 void GPUTimingFake::ExpectOffsetCalculationQuery(
95 MockGLInterface& gl) {
96 EXPECT_CALL(gl, GetInteger64v(GL_TIMESTAMP, NotNull()))
97 .Times(AtMost(1))
98 .WillRepeatedly(
99 Invoke(this, &GPUTimingFake::FakeGLGetInteger64v));
102 void GPUTimingFake::ExpectNoOffsetCalculationQuery(
103 MockGLInterface& gl) {
104 EXPECT_CALL(gl, GetInteger64v(GL_TIMESTAMP, NotNull())).Times(Exactly(0));
107 void GPUTimingFake::FakeGLGenQueries(GLsizei n, GLuint* ids) {
108 for (GLsizei i = 0; i < n; i++) {
109 ids[i] = next_query_id_++;
110 allocated_queries_.insert(ids[i]);
114 void GPUTimingFake::FakeGLDeleteQueries(GLsizei n, const GLuint* ids) {
115 for (GLsizei i = 0; i < n; i++) {
116 allocated_queries_.erase(ids[i]);
117 query_results_.erase(ids[i]);
118 if (current_elapsed_query_.query_id_ == ids[i])
119 current_elapsed_query_.Reset();
123 void GPUTimingFake::FakeGLBeginQuery(GLenum target, GLuint id) {
124 switch(target) {
125 case GL_TIME_ELAPSED:
126 ASSERT_FALSE(current_elapsed_query_.active_);
127 current_elapsed_query_.Reset();
128 current_elapsed_query_.active_ = true;
129 current_elapsed_query_.query_id_ = id;
130 current_elapsed_query_.begin_time_ = current_time_;
131 break;
132 default:
133 FAIL() << "Invalid target passed to BeginQuery: " << target;
137 void GPUTimingFake::FakeGLEndQuery(GLenum target) {
138 switch(target) {
139 case GL_TIME_ELAPSED: {
140 ASSERT_TRUE(current_elapsed_query_.active_);
141 QueryResult& query = query_results_[current_elapsed_query_.query_id_];
142 query.type_ = QueryResult::kQueryResultType_Elapsed;
143 query.begin_time_ = current_elapsed_query_.begin_time_;
144 query.value_ = current_time_;
145 current_elapsed_query_.active_ = false;
146 } break;
147 default:
148 FAIL() << "Invalid target passed to BeginQuery: " << target;
152 void GPUTimingFake::FakeGLGetQueryObjectuiv(GLuint id, GLenum pname,
153 GLuint* params) {
154 switch (pname) {
155 case GL_QUERY_RESULT_AVAILABLE: {
156 std::map<GLuint, QueryResult>::iterator it = query_results_.find(id);
157 if (it != query_results_.end() && it->second.value_ <= current_time_)
158 *params = 1;
159 else
160 *params = 0;
161 } break;
162 default:
163 FAIL() << "Invalid variable passed to GetQueryObjectuiv: " << pname;
167 void GPUTimingFake::FakeGLQueryCounter(GLuint id, GLenum target) {
168 switch (target) {
169 case GL_TIMESTAMP: {
170 ASSERT_TRUE(allocated_queries_.find(id) != allocated_queries_.end());
171 QueryResult& query = query_results_[id];
172 query.type_ = QueryResult::kQueryResultType_TimeStamp;
173 query.value_ = current_time_;
174 } break;
176 default:
177 FAIL() << "Invalid variable passed to QueryCounter: " << target;
181 void GPUTimingFake::FakeGLGetInteger64v(GLenum pname, GLint64 * data) {
182 switch (pname) {
183 case GL_TIMESTAMP:
184 *data = current_time_;
185 break;
186 default:
187 FAIL() << "Invalid variable passed to GetInteger64v: " << pname;
191 void GPUTimingFake::FakeGLGetQueryObjectui64v(GLuint id, GLenum pname,
192 GLuint64* params) {
193 switch (pname) {
194 case GL_QUERY_RESULT: {
195 std::map<GLuint, QueryResult>::iterator it = query_results_.find(id);
196 ASSERT_TRUE(it != query_results_.end());
197 switch (it->second.type_) {
198 case QueryResult::kQueryResultType_TimeStamp:
199 *params = it->second.value_;
200 break;
201 case QueryResult::kQueryResultType_Elapsed:
202 *params = it->second.value_ - it->second.begin_time_;
203 break;
204 default:
205 FAIL() << "Invalid Query Result Type: " << it->second.type_;
207 } break;
208 default:
209 FAIL() << "Invalid variable passed to GetQueryObjectui64v: " << pname;
213 void GPUTimingFake::FakeGLGetIntegerv(GLenum pname, GLint* params) {
214 switch (pname) {
215 case GL_GPU_DISJOINT_EXT:
216 *params = static_cast<GLint>(disjointed_);
217 disjointed_ = false;
218 break;
219 default:
220 FAIL() << "Invalid variable passed to GetIntegerv: " << pname;
224 GLenum GPUTimingFake::FakeGLGetError() {
225 return GL_NO_ERROR;
228 } // namespace gfx