SkTime.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2006 The Android Open Source Project
  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 SkTime_DEFINED
  8. #define SkTime_DEFINED
  9. #include "include/core/SkTypes.h"
  10. #include "include/private/SkMacros.h"
  11. class SkString;
  12. /** \class SkTime
  13. Platform-implemented utilities to return time of day, and millisecond counter.
  14. */
  15. class SK_API SkTime {
  16. public:
  17. struct DateTime {
  18. int16_t fTimeZoneMinutes; // The number of minutes that GetDateTime()
  19. // is ahead of or behind UTC.
  20. uint16_t fYear; //!< e.g. 2005
  21. uint8_t fMonth; //!< 1..12
  22. uint8_t fDayOfWeek; //!< 0..6, 0==Sunday
  23. uint8_t fDay; //!< 1..31
  24. uint8_t fHour; //!< 0..23
  25. uint8_t fMinute; //!< 0..59
  26. uint8_t fSecond; //!< 0..59
  27. void toISO8601(SkString* dst) const;
  28. };
  29. static void GetDateTime(DateTime*);
  30. static double GetSecs() { return GetNSecs() * 1e-9; }
  31. static double GetMSecs() { return GetNSecs() * 1e-6; }
  32. static double GetNSecs();
  33. };
  34. ///////////////////////////////////////////////////////////////////////////////
  35. class SkAutoTime {
  36. public:
  37. // The label is not deep-copied, so its address must remain valid for the
  38. // lifetime of this object
  39. SkAutoTime(const char* label = nullptr)
  40. : fLabel(label)
  41. , fNow(SkTime::GetMSecs()) {}
  42. ~SkAutoTime() {
  43. uint64_t dur = static_cast<uint64_t>(SkTime::GetMSecs() - fNow);
  44. SkDebugf("%s %ld\n", fLabel ? fLabel : "", dur);
  45. }
  46. private:
  47. const char* fLabel;
  48. double fNow;
  49. };
  50. #define SkAutoTime(...) SK_REQUIRE_LOCAL_VAR(SkAutoTime)
  51. #endif