Skia
2D Graphics Library
SkTime.h
Go to the documentation of this file.
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 "include/core/SkTypes.h"
14 #include "include/private/SkMacros.h"
15 
16 class SkString;
17 
21 class SK_API SkTime {
22 public:
23  struct DateTime {
24  int16_t fTimeZoneMinutes; // The number of minutes that GetDateTime()
25  // is ahead of or behind UTC.
26  uint16_t fYear;
27  uint8_t fMonth;
28  uint8_t fDayOfWeek;
29  uint8_t fDay;
30  uint8_t fHour;
31  uint8_t fMinute;
32  uint8_t fSecond;
33 
34  void toISO8601(SkString* dst) const;
35  };
36  static void GetDateTime(DateTime*);
37 
38  static double GetSecs() { return GetNSecs() * 1e-9; }
39  static double GetMSecs() { return GetNSecs() * 1e-6; }
40  static double GetNSecs();
41 };
42 
44 
45 class SkAutoTime {
46 public:
47  // The label is not deep-copied, so its address must remain valid for the
48  // lifetime of this object
49  SkAutoTime(const char* label = nullptr)
50  : fLabel(label)
51  , fNow(SkTime::GetMSecs()) {}
53  uint64_t dur = static_cast<uint64_t>(SkTime::GetMSecs() - fNow);
54  SkDebugf("%s %ld\n", fLabel ? fLabel : "", dur);
55  }
56 private:
57  const char* fLabel;
58  double fNow;
59 };
60 
61 #endif
SkAutoTime::SkAutoTime
SkAutoTime(const char *label=nullptr)
Definition: SkTime.h:49
SkTime::DateTime::toISO8601
void toISO8601(SkString *dst) const
SkTypes.h
SkTime::DateTime::fDay
uint8_t fDay
1..31
Definition: SkTime.h:29
SkDebugf
SK_API void SkDebugf(const char format[],...)
SkAutoTime::~SkAutoTime
~SkAutoTime()
Definition: SkTime.h:52
SkTime::GetSecs
static double GetSecs()
Definition: SkTime.h:38
SkTime::GetMSecs
static double GetMSecs()
Definition: SkTime.h:39
SkAutoTime
Definition: SkTime.h:45
SK_API
#define SK_API
Definition: SkTypes.h:181
SkTime
Definition: SkTime.h:21
SkTime::DateTime::fYear
uint16_t fYear
e.g. 2005
Definition: SkTime.h:26
SkTime::DateTime::fSecond
uint8_t fSecond
0..59
Definition: SkTime.h:32
SkTime::DateTime::fTimeZoneMinutes
int16_t fTimeZoneMinutes
Definition: SkTime.h:24
SkTime::DateTime::fDayOfWeek
uint8_t fDayOfWeek
0..6, 0==Sunday
Definition: SkTime.h:28
SkTime::DateTime::fMinute
uint8_t fMinute
0..59
Definition: SkTime.h:31
SkTime::DateTime
Definition: SkTime.h:23
SkTime::GetDateTime
static void GetDateTime(DateTime *)
SkTime::DateTime::fHour
uint8_t fHour
0..23
Definition: SkTime.h:30
SkTime::DateTime::fMonth
uint8_t fMonth
1..12
Definition: SkTime.h:27
SkString
Definition: SkString.h:116
SkTime::GetNSecs
static double GetNSecs()