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

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: fixes 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
« no previous file with comments | « tools/timer/GpuTimer.h ('k') | tools/timer/SysTimer_mach.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) : fContext(glctx) {
13 fContext = glctx; 13 if (fContext) {
tfarina 2014/06/20 18:05:58 if glctx is NULL, aren't we going to leaving fStar
tfarina 2014/06/20 18:06:40 s/leaving/leave
mtklein 2014/06/20 18:08:18 Yes. If fContext is NULL, we'll never touch any o
14 glctx->ref(); 14 fContext->ref();
15 glctx->makeCurrent(); 15 fContext->makeCurrent();
16 fStarted = false; 16 fStarted = false;
17 fSupported = GrGLGetVersion(glctx->gl()) > GR_GL_VER(3,3) || 17 fSupported = GrGLGetVersion(fContext->gl()) > GR_GL_VER(3,3) ||
18 glctx->hasExtension("GL_ARB_timer_query") || 18 fContext->hasExtension("GL_ARB_timer_query") ||
19 glctx->hasExtension("GL_EXT_timer_query"); 19 fContext->hasExtension("GL_EXT_timer_query");
20 20
21 if (fSupported) { 21 if (fSupported) {
22 SK_GL(*glctx, GenQueries(1, &fQuery)); 22 SK_GL(*fContext, GenQueries(1, &fQuery));
23 }
23 } 24 }
24 } 25 }
25 26
26 BenchGpuTimer::~BenchGpuTimer() { 27 GpuTimer::~GpuTimer() {
27 if (fSupported) { 28 if (fContext) {
28 fContext->makeCurrent(); 29 if (fSupported) {
29 SK_GL(*fContext, DeleteQueries(1, &fQuery)); 30 fContext->makeCurrent();
31 SK_GL(*fContext, DeleteQueries(1, &fQuery));
32 }
33 fContext->unref();
30 } 34 }
31 fContext->unref();
32 } 35 }
33 36
34 void BenchGpuTimer::startGpu() { 37 void GpuTimer::start() {
35 if (fSupported) { 38 if (fContext && fSupported) {
36 fContext->makeCurrent(); 39 fContext->makeCurrent();
37 fStarted = true; 40 fStarted = true;
38 SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery)); 41 SK_GL(*fContext, BeginQuery(GR_GL_TIME_ELAPSED, fQuery));
39 } 42 }
40 } 43 }
41 44
42 /** 45 /**
43 * It is important to stop the cpu clocks first, 46 * It is important to stop the cpu clocks first,
44 * as this will cpu wait for the gpu to finish. 47 * as this will cpu wait for the gpu to finish.
45 */ 48 */
46 double BenchGpuTimer::endGpu() { 49 double GpuTimer::end() {
47 if (fSupported) { 50 if (fContext && fSupported) {
48 fStarted = false; 51 fStarted = false;
49 fContext->makeCurrent(); 52 fContext->makeCurrent();
50 SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED)); 53 SK_GL(*fContext, EndQuery(GR_GL_TIME_ELAPSED));
51 54
52 GrGLint available = 0; 55 GrGLint available = 0;
53 while (!available) { 56 while (!available) {
54 SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery, 57 SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery,
55 GR_GL_QUERY_RESULT_AVAILABLE, 58 GR_GL_QUERY_RESULT_AVAI LABLE,
56 &available)); 59 &available));
57 // If GetQueryObjectiv is erroring out we need some alternative 60 // If GetQueryObjectiv is erroring out we need some alternative
58 // means of breaking out of this loop 61 // means of breaking out of this loop
59 GrGLenum error; 62 GrGLenum error;
60 SK_GL_RET_NOERRCHECK(*fContext, error, GetError()); 63 SK_GL_RET_NOERRCHECK(*fContext, error, GetError());
61 if (GR_GL_NO_ERROR != error) { 64 if (GR_GL_NO_ERROR != error) {
62 break; 65 break;
63 } 66 }
64 } 67 }
65 GrGLuint64 totalGPUTimeElapsed = 0; 68 GrGLuint64 totalGPUTimeElapsed = 0;
66 SK_GL(*fContext, GetQueryObjectui64v(fQuery, 69 SK_GL(*fContext, GetQueryObjectui64v(fQuery,
67 GR_GL_QUERY_RESULT, 70 GR_GL_QUERY_RESULT,
68 &totalGPUTimeElapsed)); 71 &totalGPUTimeElapsed));
69 72
70 return totalGPUTimeElapsed / 1000000.0; 73 return totalGPUTimeElapsed / 1000000.0;
71 } else { 74 } else {
72 return 0; 75 return 0;
73 } 76 }
74 } 77 }
OLDNEW
« no previous file with comments | « tools/timer/GpuTimer.h ('k') | tools/timer/SysTimer_mach.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698