Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      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 
      9 
     10 #ifndef SkTime_DEFINED
     11 #define SkTime_DEFINED
     12 
     13 #include "SkTypes.h"
     14 
     15 /** \class SkTime
     16     Platform-implemented utilities to return time of day, and millisecond counter.
     17 */
     18 class SkTime {
     19 public:
     20     struct DateTime {
     21         uint16_t fYear;          //!< e.g. 2005
     22         uint8_t  fMonth;         //!< 1..12
     23         uint8_t  fDayOfWeek;     //!< 0..6, 0==Sunday
     24         uint8_t  fDay;           //!< 1..31
     25         uint8_t  fHour;          //!< 0..23
     26         uint8_t  fMinute;        //!< 0..59
     27         uint8_t  fSecond;        //!< 0..59
     28     };
     29     static void GetDateTime(DateTime*);
     30 
     31     static SkMSec GetMSecs();
     32 };
     33 
     34 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN32)
     35     extern SkMSec gForceTickCount;
     36 #endif
     37 
     38 #define SK_TIME_FACTOR      1
     39 
     40 ///////////////////////////////////////////////////////////////////////////////
     41 
     42 class SkAutoTime {
     43 public:
     44     // The label is not deep-copied, so its address must remain valid for the
     45     // lifetime of this object
     46     SkAutoTime(const char* label = NULL, SkMSec minToDump = 0) : fLabel(label)
     47     {
     48         fNow = SkTime::GetMSecs();
     49         fMinToDump = minToDump;
     50     }
     51     ~SkAutoTime()
     52     {
     53         SkMSec dur = SkTime::GetMSecs() - fNow;
     54         if (dur >= fMinToDump) {
     55             SkDebugf("%s %d\n", fLabel ? fLabel : "", dur);
     56         }
     57     }
     58 private:
     59     const char* fLabel;
     60     SkMSec      fNow;
     61     SkMSec      fMinToDump;
     62 };
     63 
     64 #endif
     65