/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include "interface/Event.h" #include "interface/VariableRefreshRateInterface.h" inline void clearBit(uint32_t& data, uint32_t bit) { data &= ~(1L << (bit)); } inline void setBit(uint32_t& data, uint32_t bit) { data |= (1L << (bit)); } inline void setBitField(uint32_t& data, uint32_t value, uint32_t offset, uint32_t fieldMask) { data = (data & ~fieldMask) | (((value << offset) & fieldMask)); } namespace android::hardware::graphics::composer { struct TimedEvent; constexpr int64_t kMillisecondToNanoSecond = 1000000; enum PresentFrameFlag { kUpdateRefreshRateIndicatorLayerOnly = (1 << 0), kIsYuv = (1 << 1), kPresentingWhenDoze = (1 << 2), }; template >> T roundDivide(T divident, T divisor) { if (divident < 0 || divisor <= 0) { return 0; } return (divident + (divisor / 2)) / divisor; } template >> struct Fraction { T mNum; T mDen; Fraction(T num = 0, T denom = 1) : mNum(num), mDen(denom) { if (mDen < 0) { mNum = -mNum; mDen = -mDen; } } T round() { return roundDivide(mNum, mDen); } bool operator<(const Fraction& other) const { return mNum * other.mDen < other.mNum * mDen; } bool operator==(const Fraction& other) const { return mNum * other.mDen == other.mNum * mDen; } }; template >> int64_t freqToDurationNs(Fraction freq) { return roundDivide(std::nano::den * static_cast(freq.mDen), static_cast(freq.mNum)); } template >> T durationNsToFreq(T durationNs) { auto res = roundDivide(std::nano::den, static_cast(durationNs)); return static_cast(res); } template >> T freqToDurationNs(T freq) { auto res = roundDivide(std::nano::den, static_cast(freq)); return static_cast(res); } int64_t getSteadyClockTimeMs(); int64_t getSteadyClockTimeNs(); int64_t getBootClockTimeMs(); int64_t getBootClockTimeNs(); bool hasPresentFrameFlag(int flag, PresentFrameFlag target); bool isPowerModeOff(int powerMode); bool isPresentRefresh(RefreshSource refreshSource); void setTimedEventWithAbsoluteTime(TimedEvent& event); int64_t steadyClockTimeToBootClockTimeNs(int64_t steadyClockTimeNs); } // namespace android::hardware::graphics::composer