OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gl/gpu_timing_fake.h" | 5 #include "ui/gl/gpu_timing_fake.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/gl/gl_mock.h" | 8 #include "ui/gl/gl_mock.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 | 71 |
72 // Time Elapsed based queries. | 72 // Time Elapsed based queries. |
73 EXPECT_CALL(gl, BeginQuery(GL_TIME_ELAPSED, _)) | 73 EXPECT_CALL(gl, BeginQuery(GL_TIME_ELAPSED, _)) |
74 .WillRepeatedly( | 74 .WillRepeatedly( |
75 Invoke(this, &GPUTimingFake::FakeGLBeginQuery)); | 75 Invoke(this, &GPUTimingFake::FakeGLBeginQuery)); |
76 | 76 |
77 EXPECT_CALL(gl, EndQuery(GL_TIME_ELAPSED)) | 77 EXPECT_CALL(gl, EndQuery(GL_TIME_ELAPSED)) |
78 .WillRepeatedly(Invoke(this, &GPUTimingFake::FakeGLEndQuery)); | 78 .WillRepeatedly(Invoke(this, &GPUTimingFake::FakeGLEndQuery)); |
79 | 79 |
80 EXPECT_CALL(gl, GetQueryObjectuiv(_, GL_QUERY_RESULT_AVAILABLE, | 80 EXPECT_CALL(gl, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, |
81 NotNull())) | 81 NotNull())) |
82 .WillRepeatedly( | 82 .WillRepeatedly( |
83 Invoke(this, &GPUTimingFake::FakeGLGetQueryObjectuiv)); | 83 Invoke(this, &GPUTimingFake::FakeGLGetQueryObjectiv)); |
84 | 84 |
85 EXPECT_CALL(gl, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) | 85 EXPECT_CALL(gl, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |
86 .WillRepeatedly( | 86 .WillRepeatedly( |
87 Invoke(this, &GPUTimingFake::FakeGLGetQueryObjectui64v)); | 87 Invoke(this, &GPUTimingFake::FakeGLGetQueryObjectui64v)); |
88 | 88 |
89 EXPECT_CALL(gl, DeleteQueries(1, NotNull())).Times(AtLeast(2)) | 89 EXPECT_CALL(gl, DeleteQueries(1, NotNull())).Times(AtLeast(2)) |
90 .WillRepeatedly( | 90 .WillRepeatedly( |
91 Invoke(this, &GPUTimingFake::FakeGLDeleteQueries)); | 91 Invoke(this, &GPUTimingFake::FakeGLDeleteQueries)); |
92 } | 92 } |
93 | 93 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 query.type_ = QueryResult::kQueryResultType_Elapsed; | 142 query.type_ = QueryResult::kQueryResultType_Elapsed; |
143 query.begin_time_ = current_elapsed_query_.begin_time_; | 143 query.begin_time_ = current_elapsed_query_.begin_time_; |
144 query.value_ = current_time_; | 144 query.value_ = current_time_; |
145 current_elapsed_query_.active_ = false; | 145 current_elapsed_query_.active_ = false; |
146 } break; | 146 } break; |
147 default: | 147 default: |
148 FAIL() << "Invalid target passed to BeginQuery: " << target; | 148 FAIL() << "Invalid target passed to BeginQuery: " << target; |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 void GPUTimingFake::FakeGLGetQueryObjectuiv(GLuint id, GLenum pname, | 152 void GPUTimingFake::FakeGLGetQueryObjectiv(GLuint id, GLenum pname, |
153 GLuint* params) { | 153 GLint* params) { |
154 switch (pname) { | 154 switch (pname) { |
155 case GL_QUERY_RESULT_AVAILABLE: { | 155 case GL_QUERY_RESULT_AVAILABLE: { |
156 std::map<GLuint, QueryResult>::iterator it = query_results_.find(id); | 156 std::map<GLuint, QueryResult>::iterator it = query_results_.find(id); |
157 if (it != query_results_.end() && it->second.value_ <= current_time_) | 157 if (it != query_results_.end() && it->second.value_ <= current_time_) |
158 *params = 1; | 158 *params = 1; |
159 else | 159 else |
160 *params = 0; | 160 *params = 0; |
161 } break; | 161 } break; |
162 default: | 162 default: |
163 FAIL() << "Invalid variable passed to GetQueryObjectuiv: " << pname; | 163 FAIL() << "Invalid variable passed to GetQueryObjectiv: " << pname; |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 void GPUTimingFake::FakeGLQueryCounter(GLuint id, GLenum target) { | 167 void GPUTimingFake::FakeGLQueryCounter(GLuint id, GLenum target) { |
168 switch (target) { | 168 switch (target) { |
169 case GL_TIMESTAMP: { | 169 case GL_TIMESTAMP: { |
170 ASSERT_TRUE(allocated_queries_.find(id) != allocated_queries_.end()); | 170 ASSERT_TRUE(allocated_queries_.find(id) != allocated_queries_.end()); |
171 QueryResult& query = query_results_[id]; | 171 QueryResult& query = query_results_[id]; |
172 query.type_ = QueryResult::kQueryResultType_TimeStamp; | 172 query.type_ = QueryResult::kQueryResultType_TimeStamp; |
173 query.value_ = current_time_; | 173 query.value_ = current_time_; |
174 } break; | 174 } break; |
175 | 175 |
176 default: | 176 default: |
177 FAIL() << "Invalid variable passed to QueryCounter: " << target; | 177 FAIL() << "Invalid variable passed to QueryCounter: " << target; |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 void GPUTimingFake::FakeGLGetInteger64v(GLenum pname, GLint64 * data) { | 181 void GPUTimingFake::FakeGLGetInteger64v(GLenum pname, GLint64 * data) { |
182 switch (pname) { | 182 switch (pname) { |
183 case GL_TIMESTAMP: | 183 case GL_TIMESTAMP: |
184 *data = current_time_; | 184 *data = current_time_; |
185 break; | 185 break; |
186 default: | 186 default: |
187 FAIL() << "Invalid variable passed to GetInteger64v: " << pname; | 187 FAIL() << "Invalid variable passed to GetInteger64v: " << pname; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void GPUTimingFake::FakeGLGetQueryObjectui64v(GLuint id, GLenum pname, | 191 void GPUTimingFake::FakeGLGetQueryObjectui64v(GLuint id, GLenum pname, |
192 GLuint64* params) { | 192 GLuint64* params) { |
193 switch (pname) { | 193 switch (pname) { |
194 case GL_QUERY_RESULT: { | 194 case GL_QUERY_RESULT: { |
195 std::map<GLuint, QueryResult>::iterator it = query_results_.find(id); | 195 std::map<GLuint, QueryResult>::iterator it = query_results_.find(id); |
196 ASSERT_TRUE(it != query_results_.end()); | 196 ASSERT_TRUE(it != query_results_.end()); |
197 switch (it->second.type_) { | 197 switch (it->second.type_) { |
198 case QueryResult::kQueryResultType_TimeStamp: | 198 case QueryResult::kQueryResultType_TimeStamp: |
199 *params = it->second.value_; | 199 *params = it->second.value_; |
200 break; | 200 break; |
201 case QueryResult::kQueryResultType_Elapsed: | 201 case QueryResult::kQueryResultType_Elapsed: |
202 *params = it->second.value_ - it->second.begin_time_; | 202 *params = it->second.value_ - it->second.begin_time_; |
(...skipping 16 matching lines...) Expand all Loading... |
219 default: | 219 default: |
220 FAIL() << "Invalid variable passed to GetIntegerv: " << pname; | 220 FAIL() << "Invalid variable passed to GetIntegerv: " << pname; |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 GLenum GPUTimingFake::FakeGLGetError() { | 224 GLenum GPUTimingFake::FakeGLGetError() { |
225 return GL_NO_ERROR; | 225 return GL_NO_ERROR; |
226 } | 226 } |
227 | 227 |
228 } // namespace gfx | 228 } // namespace gfx |
OLD | NEW |