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