OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.h" | 5 #include "ui/gl/gpu_timing.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "ui/gl/gl_bindings.h" | 8 #include "ui/gl/gl_bindings.h" |
9 #include "ui/gl/gl_context.h" | 9 #include "ui/gl/gl_context.h" |
10 #include "ui/gl/gl_version_info.h" | 10 #include "ui/gl/gl_version_info.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // Returns true when UpdateQueryResults() is ready to be called. | 196 // Returns true when UpdateQueryResults() is ready to be called. |
197 bool IsAvailable(GPUTimingImpl* gpu_timing) override { | 197 bool IsAvailable(GPUTimingImpl* gpu_timing) override { |
198 if (gpu_timing->GetElapsedQueryCount() != 0 && | 198 if (gpu_timing->GetElapsedQueryCount() != 0 && |
199 gpu_timing->GetLastElapsedQuery() == this) { | 199 gpu_timing->GetLastElapsedQuery() == this) { |
200 // Cannot query if result is available if EndQuery has not been called. | 200 // Cannot query if result is available if EndQuery has not been called. |
201 // Since only one query is going on at a time, the end query is only not | 201 // Since only one query is going on at a time, the end query is only not |
202 // called for the very last query when ongoing query counter is not 0. | 202 // called for the very last query when ongoing query counter is not 0. |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
206 GLuint done = 0; | 206 GLint done = 0; |
207 glGetQueryObjectuiv(gl_query_id_, GL_QUERY_RESULT_AVAILABLE, &done); | 207 glGetQueryObjectiv(gl_query_id_, GL_QUERY_RESULT_AVAILABLE, &done); |
208 return !!done; | 208 return !!done; |
209 } | 209 } |
210 | 210 |
211 // Fills out query result start and end, called after IsAvailable() is true. | 211 // Fills out query result start and end, called after IsAvailable() is true. |
212 void UpdateQueryResults(GPUTimingImpl* gpu_timing) override { | 212 void UpdateQueryResults(GPUTimingImpl* gpu_timing) override { |
| 213 DCHECK(IsAvailable(gpu_timing)); |
| 214 |
213 GLuint64 result_value = 0; | 215 GLuint64 result_value = 0; |
214 glGetQueryObjectui64v(gl_query_id_, GL_QUERY_RESULT, &result_value); | 216 glGetQueryObjectui64v(gl_query_id_, GL_QUERY_RESULT, &result_value); |
215 const int64_t micro_results = NanoToMicro(result_value); | 217 const int64_t micro_results = NanoToMicro(result_value); |
216 | 218 |
217 // Adjust prev query end time if it is before the current max. | 219 // Adjust prev query end time if it is before the current max. |
218 const int64_t start_time = | 220 const int64_t start_time = |
219 std::max(first_top_level_query_ ? query_begin_cpu_time_ : 0, | 221 std::max(first_top_level_query_ ? query_begin_cpu_time_ : 0, |
220 std::max(prev_query_end_time_, | 222 std::max(prev_query_end_time_, |
221 gpu_timing->GetMaxTimeStamp())); | 223 gpu_timing->GetMaxTimeStamp())); |
222 | 224 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 270 } |
269 | 271 |
270 scoped_refptr<QueryResult> DoQuery() { | 272 scoped_refptr<QueryResult> DoQuery() { |
271 glQueryCounter(gl_query_id_, GL_TIMESTAMP); | 273 glQueryCounter(gl_query_id_, GL_TIMESTAMP); |
272 query_result_ = new QueryResult(); | 274 query_result_ = new QueryResult(); |
273 return query_result_; | 275 return query_result_; |
274 } | 276 } |
275 | 277 |
276 // Returns true when UpdateQueryResults() is ready to be called. | 278 // Returns true when UpdateQueryResults() is ready to be called. |
277 bool IsAvailable(GPUTimingImpl* gpu_timing) override { | 279 bool IsAvailable(GPUTimingImpl* gpu_timing) override { |
278 GLuint done = 0; | 280 GLint done = 0; |
279 glGetQueryObjectuiv(gl_query_id_, GL_QUERY_RESULT_AVAILABLE, &done); | 281 glGetQueryObjectiv(gl_query_id_, GL_QUERY_RESULT_AVAILABLE, &done); |
280 return !!done; | 282 return !!done; |
281 } | 283 } |
282 | 284 |
283 // Fills out query result start and end, called after IsAvailable() is true. | 285 // Fills out query result start and end, called after IsAvailable() is true. |
284 void UpdateQueryResults(GPUTimingImpl* gpu_timing) override { | 286 void UpdateQueryResults(GPUTimingImpl* gpu_timing) override { |
285 DCHECK(IsAvailable(gpu_timing)); | 287 DCHECK(IsAvailable(gpu_timing)); |
286 | 288 |
287 GLuint64 result_value = 0; | 289 GLuint64 result_value = 0; |
288 glGetQueryObjectui64v(gl_query_id_, GL_QUERY_RESULT, &result_value); | 290 glGetQueryObjectui64v(gl_query_id_, GL_QUERY_RESULT, &result_value); |
289 const int64_t micro_results = NanoToMicro(result_value); | 291 const int64_t micro_results = NanoToMicro(result_value); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 598 |
597 void GPUTimingClient::ForceTimeElapsedQuery() { | 599 void GPUTimingClient::ForceTimeElapsedQuery() { |
598 DCHECK(gpu_timing_); | 600 DCHECK(gpu_timing_); |
599 gpu_timing_->ForceTimeElapsedQuery(); | 601 gpu_timing_->ForceTimeElapsedQuery(); |
600 } | 602 } |
601 | 603 |
602 GPUTimingClient::~GPUTimingClient() { | 604 GPUTimingClient::~GPUTimingClient() { |
603 } | 605 } |
604 | 606 |
605 } // namespace gfx | 607 } // namespace gfx |
OLD | NEW |