Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkTime_DEFINED
     18 #define SkTime_DEFINED
     19 
     20 #include "SkTypes.h"
     21 
     22 /** \class SkTime
     23     Platform-implemented utilities to return time of day, and millisecond counter.
     24 */
     25 class SkTime {
     26 public:
     27     struct DateTime {
     28         uint16_t fYear;          //!< e.g. 2005
     29         uint8_t  fMonth;         //!< 1..12
     30         uint8_t  fDayOfWeek;     //!< 0..6, 0==Sunday
     31         uint8_t  fDay;           //!< 1..31
     32         uint8_t  fHour;          //!< 0..23
     33         uint8_t  fMinute;        //!< 0..59
     34         uint8_t  fSecond;        //!< 0..59
     35     };
     36     static void GetDateTime(DateTime*);
     37 
     38     static SkMSec GetMSecs();
     39 };
     40 
     41 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN32)
     42     extern SkMSec gForceTickCount;
     43 #endif
     44 
     45 #define SK_TIME_FACTOR      1
     46 
     47 ///////////////////////////////////////////////////////////////////////////////
     48 
     49 class SkAutoTime {
     50 public:
     51     // The label is not deep-copied, so its address must remain valid for the
     52     // lifetime of this object
     53     SkAutoTime(const char* label = NULL, SkMSec minToDump = 0) : fLabel(label)
     54     {
     55         fNow = SkTime::GetMSecs();
     56         fMinToDump = minToDump;
     57     }
     58     ~SkAutoTime()
     59     {
     60         SkMSec dur = SkTime::GetMSecs() - fNow;
     61         if (dur >= fMinToDump) {
     62             SkDebugf("%s %d\n", fLabel ? fLabel : "", dur);
     63         }
     64     }
     65 private:
     66     const char* fLabel;
     67     SkMSec      fNow;
     68     SkMSec      fMinToDump;
     69 };
     70 
     71 #endif
     72 
     73