1 /* 2 * Copyright (C) 2024 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 #include "Utils.h" 18 19 #include <hardware/hwcomposer2.h> 20 #include <chrono> 21 #include "android-base/chrono_utils.h" 22 23 #include "interface/Panel_def.h" 24 25 namespace android::hardware::graphics::composer { 26 getSteadyClockTimeMs()27int64_t getSteadyClockTimeMs() { 28 return std::chrono::duration_cast<std::chrono::milliseconds>( 29 std::chrono::steady_clock::now().time_since_epoch()) 30 .count(); 31 } 32 getSteadyClockTimeNs()33int64_t getSteadyClockTimeNs() { 34 return std::chrono::duration_cast<std::chrono::nanoseconds>( 35 std::chrono::steady_clock::now().time_since_epoch()) 36 .count(); 37 } 38 getBootClockTimeMs()39int64_t getBootClockTimeMs() { 40 return std::chrono::duration_cast<std::chrono::milliseconds>( 41 ::android::base::boot_clock::now().time_since_epoch()) 42 .count(); 43 } 44 getBootClockTimeNs()45int64_t getBootClockTimeNs() { 46 return std::chrono::duration_cast<std::chrono::nanoseconds>( 47 ::android::base::boot_clock::now().time_since_epoch()) 48 .count(); 49 } 50 steadyClockTimeToBootClockTimeNs(int64_t steadyClockTimeNs)51int64_t steadyClockTimeToBootClockTimeNs(int64_t steadyClockTimeNs) { 52 return steadyClockTimeNs + (getBootClockTimeNs() - getSteadyClockTimeNs()); 53 } 54 hasPresentFrameFlag(int flag,PresentFrameFlag target)55bool hasPresentFrameFlag(int flag, PresentFrameFlag target) { 56 return flag & static_cast<int>(target); 57 } 58 isPowerModeOff(int powerMode)59bool isPowerModeOff(int powerMode) { 60 return ((powerMode == HWC_POWER_MODE_OFF) || (powerMode == HWC_POWER_MODE_DOZE_SUSPEND)); 61 } 62 setTimedEventWithAbsoluteTime(TimedEvent & event)63void setTimedEventWithAbsoluteTime(TimedEvent& event) { 64 if (event.mIsRelativeTime) { 65 event.mWhenNs += getSteadyClockTimeNs(); 66 event.mIsRelativeTime = false; 67 } 68 } 69 70 } // namespace android::hardware::graphics::composer 71