Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: tools/timer/GpuTimer.cpp

Issue 344213003: Move BenchTimer to tools as Timer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: alpha Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "BenchGpuTimer_gl.h" 8 #include "GpuTimer.h"
9 #include "gl/SkGLContextHelper.h" 9 #include "gl/SkGLContextHelper.h"
10 #include "gl/GrGLUtil.h" 10 #include "gl/GrGLUtil.h"
11 11
12 BenchGpuTimer::BenchGpuTimer(const SkGLContextHelper* glctx) { 12 GpuTimer::GpuTimer(const SkGLContextHelper* glctx) {
13 fContext = glctx; 13 fContext = glctx;
14 glctx->ref(); 14 glctx->ref();
15 glctx->makeCurrent(); 15 glctx->makeCurrent();
16 fStarted = false; 16 fStarted = false;
17 fSupported = GrGLGetVersion(glctx->gl()) > GR_GL_VER(3,3) || 17 fSupported = GrGLGetVersion(glctx->gl()) > GR_GL_VER(3,3) ||
18 glctx->hasExtension("GL_ARB_timer_query") || 18 glctx->hasExtension("GL_ARB_timer_query") ||
19 glctx->hasExtension("GL_EXT_timer_query"); 19 glctx->hasExtension("GL_EXT_timer_query");
20 20
21 if (fSupported) { 21 if (fSupported) {
22 SK_GL(*glctx, GenQueries(1, &fQuery)); 22 SK_GL(*glctx, GenQueries(1, &fQuery));
23 } 23 }
24 } 24 }
25 25
26 BenchGpuTimer::~BenchGpuTimer() { 26 GpuTimer::~GpuTimer() {
27 if (fSupported) { 27 if (fSupported) {
28 fContext->makeCurrent(); 28 fContext->makeCurrent();
29 SK_GL(*fContext, DeleteQueries(1, &fQuery)); 29 SK_GL(*fContext, DeleteQueries(1, &fQuery));
30 } 30 }
31 fContext->unref(); 31 fContext->unref();
32 } 32 }
33 33
34 void BenchGpuTimer::startGpu() { 34 void GpuTimer::start() {
35 if (fSupported) { 35 if (fSupported) {
36 fContext->makeCurrent(); 36 fContext->makeCurrent();
37 fStarted = true; 37 fStarted = true;
38 SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery)); 38 SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery));
39 } 39 }
40 } 40 }
41 41
42 /** 42 /**
43 * It is important to stop the cpu clocks first, 43 * It is important to stop the cpu clocks first,
44 * as this will cpu wait for the gpu to finish. 44 * as this will cpu wait for the gpu to finish.
45 */ 45 */
46 double BenchGpuTimer::endGpu() { 46 double GpuTimer::end() {
47 if (fSupported) { 47 if (fSupported) {
48 fStarted = false; 48 fStarted = false;
49 fContext->makeCurrent(); 49 fContext->makeCurrent();
50 SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED)); 50 SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED));
51 51
52 GrGLint available = 0; 52 GrGLint available = 0;
53 while (!available) { 53 while (!available) {
54 SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery, 54 SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery,
55 GR_GL_QUERY_RESULT_AVAILABLE, 55 GR_GL_QUERY_RESULT_AVAI LABLE,
56 &available)); 56 &available));
57 // If GetQueryObjectiv is erroring out we need some alternative 57 // If GetQueryObjectiv is erroring out we need some alternative
58 // means of breaking out of this loop 58 // means of breaking out of this loop
59 GrGLenum error; 59 GrGLenum error;
60 SK_GL_RET_NOERRCHECK(*fContext, error, GetError()); 60 SK_GL_RET_NOERRCHECK(*fContext, error, GetError());
61 if (GR_GL_NO_ERROR != error) { 61 if (GR_GL_NO_ERROR != error) {
62 break; 62 break;
63 } 63 }
64 } 64 }
65 GrGLuint64 totalGPUTimeElapsed = 0; 65 GrGLuint64 totalGPUTimeElapsed = 0;
66 SK_GL(*fContext, GetQueryObjectui64v(fQuery, 66 SK_GL(*fContext, GetQueryObjectui64v(fQuery,
67 GR_GL_QUERY_RESULT, 67 GR_GL_QUERY_RESULT,
68 &totalGPUTimeElapsed)); 68 &totalGPUTimeElapsed));
69 69
70 return totalGPUTimeElapsed / 1000000.0; 70 return totalGPUTimeElapsed / 1000000.0;
71 } else { 71 } else {
72 return 0; 72 return 0;
73 } 73 }
74 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698