Bug 1773205 [wpt PR 34343] - SVG Text NG: Improve performance on ancestor scaling...
[gecko.git] / mozglue / misc / TimeStamp_windows.h
bloba1f4e31ec7de86598c4bd48dfce2af42253a0440
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_TimeStamp_windows_h
8 #define mozilla_TimeStamp_windows_h
10 #include "mozilla/Types.h"
12 namespace mozilla {
14 /**
15 * The [mt] unit:
17 * Many values are kept in ticks of the Performance Counter x 1000,
18 * further just referred as [mt], meaning milli-ticks.
20 * This is needed to preserve maximum precision of the performance frequency
21 * representation. GetTickCount64 values in milliseconds are multiplied with
22 * frequency per second. Therefore we need to multiply QPC value by 1000 to
23 * have the same units to allow simple arithmentic with both QPC and GTC.
25 #define ms2mt(x) ((x)*mozilla::GetQueryPerformanceFrequencyPerSec())
26 #define mt2ms(x) ((x) / mozilla::GetQueryPerformanceFrequencyPerSec())
27 #define mt2ms_f(x) (double(x) / mozilla::GetQueryPerformanceFrequencyPerSec())
29 MFBT_API uint64_t GetQueryPerformanceFrequencyPerSec();
31 class TimeStamp;
32 class TimeStampValue;
34 TimeStampValue NowInternal(bool aHighResolution);
36 class TimeStampValue {
37 friend TimeStampValue NowInternal(bool);
38 friend bool IsCanonicalTimeStamp(TimeStampValue);
39 friend struct IPC::ParamTraits<mozilla::TimeStampValue>;
40 friend class TimeStamp;
42 // Both QPC and GTC are kept in [mt] units.
43 uint64_t mGTC;
44 uint64_t mQPC;
46 bool mIsNull;
47 bool mHasQPC;
49 MFBT_API TimeStampValue(uint64_t aGTC, uint64_t aQPC, bool aHasQPC);
51 MFBT_API uint64_t CheckQPC(const TimeStampValue& aOther) const;
53 // This struct is used to allow doing TimeStampValue a = 0 and similar
54 struct _SomethingVeryRandomHere;
55 constexpr MOZ_IMPLICIT TimeStampValue(_SomethingVeryRandomHere* aNullValue)
56 : mGTC(0), mQPC(0), mIsNull(true), mHasQPC(false) {}
58 public:
59 MFBT_API uint64_t operator-(const TimeStampValue& aOther) const;
61 TimeStampValue operator+(const int64_t aOther) const {
62 return TimeStampValue(mGTC + aOther, mQPC + aOther, mHasQPC);
64 TimeStampValue operator-(const int64_t aOther) const {
65 return TimeStampValue(mGTC - aOther, mQPC - aOther, mHasQPC);
67 MFBT_API TimeStampValue& operator+=(const int64_t aOther);
68 MFBT_API TimeStampValue& operator-=(const int64_t aOther);
70 bool operator<(const TimeStampValue& aOther) const {
71 return int64_t(*this - aOther) < 0;
73 bool operator>(const TimeStampValue& aOther) const {
74 return int64_t(*this - aOther) > 0;
76 bool operator<=(const TimeStampValue& aOther) const {
77 return int64_t(*this - aOther) <= 0;
79 bool operator>=(const TimeStampValue& aOther) const {
80 return int64_t(*this - aOther) >= 0;
82 bool operator==(const TimeStampValue& aOther) const {
83 return int64_t(*this - aOther) == 0;
85 bool operator!=(const TimeStampValue& aOther) const {
86 return int64_t(*this - aOther) != 0;
88 bool IsNull() const { return mIsNull; }
91 } // namespace mozilla
93 #endif /* mozilla_TimeStamp_h */