• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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 ANDROID_HWC_TIME_H
18 #define ANDROID_HWC_TIME_H
19 
20 #include <utils/Timers.h>
21 
22 #include <chrono>
23 
24 #include "Common.h"
25 
26 namespace aidl::android::hardware::graphics::composer3::impl {
27 
28 using Nanoseconds = std::chrono::nanoseconds;
29 
30 using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
31 
asTimePoint(int64_t nanos)32 inline TimePoint asTimePoint(int64_t nanos) {
33   return TimePoint(Nanoseconds(nanos));
34 }
35 
now()36 inline TimePoint now() {
37   return asTimePoint(systemTime(SYSTEM_TIME_MONOTONIC));
38 }
39 
asNanosDuration(Nanoseconds duration)40 inline int32_t asNanosDuration(Nanoseconds duration) {
41   return duration.count();
42 }
43 
asNanosTimePoint(TimePoint time)44 inline int64_t asNanosTimePoint(TimePoint time) {
45   TimePoint zero(Nanoseconds(0));
46   return std::chrono::duration_cast<Nanoseconds>(time - zero).count();
47 }
48 
49 }  // namespace aidl::android::hardware::graphics::composer3::impl
50 
51 #endif
52