2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2011-06-07 19:16:02 +00:00
|
|
|
#include "BenchGpuTimer_gl.h"
|
2011-10-19 20:43:20 +00:00
|
|
|
#include "SkGLContext.h"
|
|
|
|
|
|
|
|
BenchGpuTimer::BenchGpuTimer(const SkGLContext* glctx) {
|
|
|
|
fContext = glctx;
|
|
|
|
glctx->ref();
|
|
|
|
glctx->makeCurrent();
|
|
|
|
fStarted = false;
|
|
|
|
fSupported = GrGLGetVersion(glctx->gl()) > GR_GL_VER(3,3) ||
|
|
|
|
GrGLHasExtension(glctx->gl(), "GL_ARB_timer_query") ||
|
|
|
|
GrGLHasExtension(glctx->gl(), "GL_EXT_timer_query");
|
2011-06-07 19:16:02 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
if (fSupported) {
|
|
|
|
SK_GL(*glctx, GenQueries(1, &fQuery));
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BenchGpuTimer::~BenchGpuTimer() {
|
2011-10-19 20:43:20 +00:00
|
|
|
if (fSupported) {
|
|
|
|
fContext->makeCurrent();
|
|
|
|
SK_GL(*fContext, DeleteQueries(1, &fQuery));
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
2011-10-19 20:43:20 +00:00
|
|
|
fContext->unref();
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BenchGpuTimer::startGpu() {
|
2011-10-19 20:43:20 +00:00
|
|
|
if (fSupported) {
|
|
|
|
fContext->makeCurrent();
|
|
|
|
fStarted = true;
|
|
|
|
SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery));
|
|
|
|
}
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* It is important to stop the cpu clocks first,
|
|
|
|
* as this will cpu wait for the gpu to finish.
|
|
|
|
*/
|
|
|
|
double BenchGpuTimer::endGpu() {
|
2011-10-19 20:43:20 +00:00
|
|
|
if (fSupported) {
|
|
|
|
fStarted = false;
|
|
|
|
fContext->makeCurrent();
|
|
|
|
SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED));
|
|
|
|
|
|
|
|
GrGLint available = 0;
|
|
|
|
while (!available) {
|
|
|
|
SK_GL(*fContext, GetQueryObjectiv(fQuery,
|
|
|
|
GR_GL_QUERY_RESULT_AVAILABLE,
|
|
|
|
&available));
|
|
|
|
}
|
|
|
|
GrGLuint64 totalGPUTimeElapsed = 0;
|
|
|
|
SK_GL(*fContext, GetQueryObjectui64v(fQuery,
|
|
|
|
GR_GL_QUERY_RESULT,
|
|
|
|
&totalGPUTimeElapsed));
|
|
|
|
|
|
|
|
return totalGPUTimeElapsed / 1000000.0;
|
|
|
|
} else {
|
|
|
|
return 0;
|
2011-06-07 19:16:02 +00:00
|
|
|
}
|
|
|
|
}
|