00001 /* 00002 * Copyright (C) 2006 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkTime_DEFINED 00018 #define SkTime_DEFINED 00019 00020 #include "SkTypes.h" 00021 00025 class SkTime { 00026 public: 00027 struct DateTime { 00028 uint16_t fYear; 00029 uint8_t fMonth; 00030 uint8_t fDayOfWeek; 00031 uint8_t fDay; 00032 uint8_t fHour; 00033 uint8_t fMinute; 00034 uint8_t fSecond; 00035 }; 00036 static void GetDateTime(DateTime*); 00037 00038 static SkMSec GetMSecs(); 00039 }; 00040 00041 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN32) 00042 extern SkMSec gForceTickCount; 00043 #endif 00044 00045 #define SK_TIME_FACTOR 1 00046 00048 00049 class SkAutoTime { 00050 public: 00051 // The label is not deep-copied, so its address must remain valid for the 00052 // lifetime of this object 00053 SkAutoTime(const char* label = NULL, SkMSec minToDump = 0) : fLabel(label) 00054 { 00055 fNow = SkTime::GetMSecs(); 00056 fMinToDump = minToDump; 00057 } 00058 ~SkAutoTime() 00059 { 00060 SkMSec dur = SkTime::GetMSecs() - fNow; 00061 if (dur >= fMinToDump) { 00062 SkDebugf("%s %d\n", fLabel ? fLabel : "", dur); 00063 } 00064 } 00065 private: 00066 const char* fLabel; 00067 SkMSec fNow; 00068 SkMSec fMinToDump; 00069 }; 00070 00071 #endif 00072