Home | History | Annotate | Download | only in bench
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #include "BenchTimer.h"
      9 #if defined(SK_BUILD_FOR_WIN32)
     10     #include "BenchSysTimer_windows.h"
     11 #elif defined(SK_BUILD_FOR_MAC)
     12     #include "BenchSysTimer_mach.h"
     13 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
     14     #include "BenchSysTimer_posix.h"
     15 #else
     16     #include "BenchSysTimer_c.h"
     17 #endif
     18 
     19 #include "BenchGpuTimer_gl.h"
     20 
     21 BenchTimer::BenchTimer(SkGLContext* gl)
     22         : fCpu(-1.0)
     23         , fWall(-1.0)
     24         , fGpu(-1.0)
     25 {
     26     fSysTimer = new BenchSysTimer();
     27     if (gl) {
     28         fGpuTimer = new BenchGpuTimer(gl);
     29     } else {
     30         fGpuTimer = NULL;
     31     }
     32 }
     33 
     34 BenchTimer::~BenchTimer() {
     35     delete fSysTimer;
     36     delete fGpuTimer;
     37 }
     38 
     39 void BenchTimer::start() {
     40     fSysTimer->startWall();
     41     if (fGpuTimer) {
     42         fGpuTimer->startGpu();
     43     }
     44     fSysTimer->startCpu();
     45 }
     46 
     47 void BenchTimer::end() {
     48     fCpu = fSysTimer->endCpu();
     49     //It is important to stop the cpu clocks first,
     50     //as the following will cpu wait for the gpu to finish.
     51     if (fGpuTimer) {
     52         fGpu = fGpuTimer->endGpu();
     53     }
     54     fWall = fSysTimer->endWall();
     55 }
     56