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