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 "gpu/command_buffer/service/gpu_timing.h" | 5 #include "gpu/command_buffer/service/gpu_timing.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "ui/gl/gl_bindings.h" | |
9 #include "ui/gl/gl_context.h" | 8 #include "ui/gl/gl_context.h" |
10 #include "ui/gl/gl_version_info.h" | 9 #include "ui/gl/gl_version_info.h" |
11 | 10 |
12 namespace gpu { | 11 namespace gpu { |
13 | 12 |
14 GPUTimer::GPUTimer(GPUTiming* gpu_timing) : gpu_timing_(gpu_timing) { | 13 GPUTimer::GPUTimer(GPUTiming* gpu_timing) : gpu_timing_(gpu_timing) { |
15 DCHECK(gpu_timing_); | 14 DCHECK(gpu_timing_); |
16 memset(queries_, 0, sizeof(queries_)); | 15 memset(queries_, 0, sizeof(queries_)); |
17 glGenQueriesARB(2, queries_); | 16 glGenQueriesARB(2, queries_); |
18 } | 17 } |
19 | 18 |
20 GPUTimer::~GPUTimer() { | 19 GPUTimer::~GPUTimer() { |
21 glDeleteQueriesARB(2, queries_); | 20 glDeleteQueriesARB(2, queries_); |
22 } | 21 } |
23 | 22 |
24 void GPUTimer::Start() { | 23 void GPUTimer::Start() { |
25 // GL_TIMESTAMP and GL_TIMESTAMP_EXT both have the same value. | 24 // GL_TIMESTAMP and GL_TIMESTAMP_EXT both have the same value. |
26 glQueryCounter(queries_[0], GL_TIMESTAMP); | 25 glQueryCounter(queries_[0], GL_TIMESTAMP); |
| 26 offset_ = gpu_timing_->CalculateTimerOffset(); |
27 } | 27 } |
28 | 28 |
29 void GPUTimer::End() { | 29 void GPUTimer::End() { |
30 end_requested_ = true; | 30 end_requested_ = true; |
31 offset_ = gpu_timing_->CalculateTimerOffset(); | |
32 glQueryCounter(queries_[1], GL_TIMESTAMP); | 31 glQueryCounter(queries_[1], GL_TIMESTAMP); |
33 } | 32 } |
34 | 33 |
35 bool GPUTimer::IsAvailable() { | 34 bool GPUTimer::IsAvailable() { |
36 if (!gpu_timing_->IsAvailable() || !end_requested_) { | 35 if (!gpu_timing_->IsAvailable() || !end_requested_) { |
37 return false; | 36 return false; |
38 } | 37 } |
39 GLint done = 0; | 38 GLint done = 0; |
40 glGetQueryObjectivARB(queries_[1], GL_QUERY_RESULT_AVAILABLE, &done); | 39 glGetQueryObjectivARB(queries_[1], GL_QUERY_RESULT_AVAILABLE, &done); |
41 return done != 0; | 40 return done != 0; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void GPUTiming::SetOffsetForTesting(int64 offset, bool cache_it) { | 136 void GPUTiming::SetOffsetForTesting(int64 offset, bool cache_it) { |
138 offset_ = offset; | 137 offset_ = offset; |
139 offset_valid_ = cache_it; | 138 offset_valid_ = cache_it; |
140 } | 139 } |
141 | 140 |
142 void GPUTiming::SetTimerTypeForTesting(TimerType type) { | 141 void GPUTiming::SetTimerTypeForTesting(TimerType type) { |
143 timer_type_ = type; | 142 timer_type_ = type; |
144 } | 143 } |
145 | 144 |
146 } // namespace gpu | 145 } // namespace gpu |
OLD | NEW |