Home | History | Annotate | Download | only in timer
      1 /*
      2  * Copyright 2011 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 #ifndef Timer_DEFINED
      8 #define Timer_DEFINED
      9 
     10 #include "SkTypes.h"
     11 #include "SkString.h"
     12 
     13 #if defined(SK_BUILD_FOR_WIN32)
     14     #include "SysTimer_windows.h"
     15 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
     16     #include "SysTimer_mach.h"
     17 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
     18     #include "SysTimer_posix.h"
     19 #endif
     20 
     21 #if SK_SUPPORT_GPU
     22     #include "GpuTimer.h"
     23 #endif
     24 
     25 class SkGLContext;
     26 
     27 /**
     28  * SysTimers and GpuTimers are implemented orthogonally.
     29  * This class combines 2 SysTimers and a GpuTimer into one single,
     30  * platform specific Timer with a simple interface. The truncated
     31  * timer doesn't include the time required for the GPU to finish
     32  * its rendering. It should always be <= the un-truncated system
     33  * times and (for GPU configurations) can be used to roughly (very
     34  * roughly) gauge the GPU load/backlog.
     35  */
     36 class Timer {
     37 public:
     38     explicit Timer(SkGLContext* gl = NULL);
     39 
     40     void start();
     41     void truncatedEnd();
     42     void end();
     43 
     44     // All times in milliseconds.
     45     double fCpu;
     46     double fWall;
     47     double fTruncatedCpu;
     48     double fTruncatedWall;
     49     double fGpu;
     50 
     51 private:
     52     SysTimer fSysTimer;
     53     SysTimer fTruncatedSysTimer;
     54 #if SK_SUPPORT_GPU
     55     GpuTimer fGpuTimer;
     56 #endif
     57 };
     58 
     59 // Same as Timer above, supporting only fWall but with much lower overhead.
     60 // (Typically, ~30ns instead of Timer's ~1us.)
     61 class WallTimer {
     62 public:
     63     WallTimer();
     64 
     65     void start();
     66     void end();
     67 
     68     double fWall;  // Milliseconds.
     69 
     70 private:
     71     SysTimer fSysTimer;
     72 };
     73 
     74 SkString HumanizeMs(double);
     75 
     76 #endif
     77