| Index: ui/gl/gpu_timing.cc
|
| diff --git a/gpu/command_buffer/service/gpu_timing.cc b/ui/gl/gpu_timing.cc
|
| similarity index 59%
|
| rename from gpu/command_buffer/service/gpu_timing.cc
|
| rename to ui/gl/gpu_timing.cc
|
| index 6ab3e831f387515c351e1319dd584725f2533d1b..8e43e292005d0e342267fc5e6d9a3f2e690a65d8 100644
|
| --- a/gpu/command_buffer/service/gpu_timing.cc
|
| +++ b/ui/gl/gpu_timing.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "gpu/command_buffer/service/gpu_timing.h"
|
| +#include "ui/gl/gpu_timing.h"
|
|
|
| #include "base/time/time.h"
|
| #include "ui/gl/gl_bindings.h"
|
| @@ -11,8 +11,34 @@
|
|
|
| namespace gpu {
|
|
|
| -GPUTimer::GPUTimer(GPUTiming* gpu_timing) : gpu_timing_(gpu_timing) {
|
| - DCHECK(gpu_timing_);
|
| +GPUTiming::GPUTiming(gfx::GLContext* context) {
|
| + Initialize(context);
|
| +}
|
| +
|
| +GPUTiming::~GPUTiming() {
|
| +}
|
| +
|
| +void GPUTiming::Initialize(gfx::GLContext* context) {
|
| + timer_type_ = kTimerTypeInvalid;
|
| + if (context) {
|
| + const gfx::GLVersionInfo* version_info = context->GetVersionInfo();
|
| + DCHECK(version_info);
|
| + if (version_info->is_es3 && // glGetInteger64v is supported under ES3.
|
| + context->HasExtension("GL_EXT_disjoint_timer_query")) {
|
| + timer_type_ = kTimerTypeDisjoint;
|
| + } else if (context->HasExtension("GL_ARB_timer_query")) {
|
| + timer_type_ = kTimerTypeARB;
|
| + }
|
| + }
|
| +}
|
| +
|
| +scoped_refptr<GPUTimingClient> GPUTiming::CreateGPUTimingClient() {
|
| + return new GPUTimingClient(this);
|
| +}
|
| +
|
| +GPUTimer::GPUTimer(GPUTimingClient* gpu_timing_client)
|
| + : gpu_timing_client_(gpu_timing_client) {
|
| + DCHECK(gpu_timing_client_);
|
| memset(queries_, 0, sizeof(queries_));
|
| glGenQueriesARB(2, queries_);
|
| }
|
| @@ -28,12 +54,12 @@ void GPUTimer::Start() {
|
|
|
| void GPUTimer::End() {
|
| end_requested_ = true;
|
| - offset_ = gpu_timing_->CalculateTimerOffset();
|
| + offset_ = gpu_timing_client_->CalculateTimerOffset();
|
| glQueryCounter(queries_[1], GL_TIMESTAMP);
|
| }
|
|
|
| bool GPUTimer::IsAvailable() {
|
| - if (!gpu_timing_->IsAvailable() || !end_requested_) {
|
| + if (!gpu_timing_client_->IsAvailable() || !end_requested_) {
|
| return false;
|
| }
|
| GLint done = 0;
|
| @@ -63,46 +89,23 @@ int64 GPUTimer::GetDeltaElapsed() {
|
| return end - start;
|
| }
|
|
|
| -GPUTiming::GPUTiming() : cpu_time_for_testing_() {
|
| +bool GPUTimingClient::IsAvailable() {
|
| + return timer_type_ != GPUTiming::kTimerTypeInvalid;
|
| }
|
|
|
| -GPUTiming::~GPUTiming() {
|
| -}
|
| -
|
| -bool GPUTiming::Initialize(gfx::GLContext* gl_context) {
|
| - DCHECK(gl_context);
|
| - DCHECK_EQ(kTimerTypeInvalid, timer_type_);
|
| -
|
| - const gfx::GLVersionInfo* version_info = gl_context->GetVersionInfo();
|
| - DCHECK(version_info);
|
| - if (version_info->is_es3 && // glGetInteger64v is supported under ES3.
|
| - gfx::g_driver_gl.ext.b_GL_EXT_disjoint_timer_query) {
|
| - timer_type_ = kTimerTypeDisjoint;
|
| - return true;
|
| - } else if (gfx::g_driver_gl.ext.b_GL_ARB_timer_query) {
|
| - timer_type_ = kTimerTypeARB;
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -bool GPUTiming::IsAvailable() {
|
| - return timer_type_ != kTimerTypeInvalid;
|
| -}
|
| -
|
| -const char* GPUTiming::GetTimerTypeName() const {
|
| +const char* GPUTimingClient::GetTimerTypeName() const {
|
| switch (timer_type_) {
|
| - case kTimerTypeDisjoint:
|
| + case GPUTiming::kTimerTypeDisjoint:
|
| return "GL_EXT_disjoint_timer_query";
|
| - case kTimerTypeARB:
|
| + case GPUTiming::kTimerTypeARB:
|
| return "GL_ARB_timer_query";
|
| default:
|
| return "Unknown";
|
| }
|
| }
|
|
|
| -bool GPUTiming::CheckAndResetTimerErrors() {
|
| - if (timer_type_ == kTimerTypeDisjoint) {
|
| +bool GPUTimingClient::CheckAndResetTimerErrors() {
|
| + if (timer_type_ == GPUTiming::kTimerTypeDisjoint) {
|
| GLint disjoint_value = 0;
|
| glGetIntegerv(GL_GPU_DISJOINT_EXT, &disjoint_value);
|
| return disjoint_value != 0;
|
| @@ -111,7 +114,7 @@ bool GPUTiming::CheckAndResetTimerErrors() {
|
| }
|
| }
|
|
|
| -int64 GPUTiming::CalculateTimerOffset() {
|
| +int64 GPUTimingClient::CalculateTimerOffset() {
|
| if (!offset_valid_) {
|
| GLint64 gl_now = 0;
|
| glGetInteger64v(GL_TIMESTAMP, &gl_now);
|
| @@ -120,27 +123,28 @@ int64 GPUTiming::CalculateTimerOffset() {
|
| ? base::TimeTicks::NowFromSystemTraceTime().ToInternalValue()
|
| : cpu_time_for_testing_.Run();
|
| offset_ = now - gl_now / base::Time::kNanosecondsPerMicrosecond;
|
| - offset_valid_ = timer_type_ == kTimerTypeARB;
|
| + offset_valid_ = timer_type_ == GPUTiming::kTimerTypeARB;
|
| }
|
| return offset_;
|
| }
|
|
|
| -void GPUTiming::InvalidateTimerOffset() {
|
| +void GPUTimingClient::InvalidateTimerOffset() {
|
| offset_valid_ = false;
|
| }
|
|
|
| -void GPUTiming::SetCpuTimeForTesting(
|
| +void GPUTimingClient::SetCpuTimeForTesting(
|
| const base::Callback<int64(void)>& cpu_time) {
|
| cpu_time_for_testing_ = cpu_time;
|
| }
|
|
|
| -void GPUTiming::SetOffsetForTesting(int64 offset, bool cache_it) {
|
| - offset_ = offset;
|
| - offset_valid_ = cache_it;
|
| +GPUTimingClient::GPUTimingClient(GPUTiming* gpu_timing)
|
| + : gpu_timing_(gpu_timing) {
|
| + if (gpu_timing) {
|
| + timer_type_ = gpu_timing->GetTimerType();
|
| + }
|
| }
|
|
|
| -void GPUTiming::SetTimerTypeForTesting(TimerType type) {
|
| - timer_type_ = type;
|
| +GPUTimingClient::~GPUTimingClient() {
|
| }
|
|
|
| } // namespace gpu
|
|
|