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 #pragma once 18 19 #include "RefreshRateCalculator.h" 20 21 #include "../EventQueue.h" 22 #include "../Utils.h" 23 24 namespace android::hardware::graphics::composer { 25 26 struct ExitIdleRefreshRateCalculatorParameters { 27 int64_t mIdleCriteriaTimeNs = 1000000000; // 1 second 28 int64_t mMaxValidTimeNs = 250000000; // 250 ms 29 }; 30 31 class ExitIdleRefreshRateCalculator : public RefreshRateCalculator { 32 public: 33 ExitIdleRefreshRateCalculator(EventQueue* eventQueue); 34 35 ExitIdleRefreshRateCalculator(EventQueue* eventQueue, 36 const ExitIdleRefreshRateCalculatorParameters& params); 37 38 int getRefreshRate() const override; 39 40 void onPowerStateChange(int from, int to) final; 41 42 void onPresentInternal(int64_t presentTimeNs, int flag) override; 43 44 void reset() override; 45 46 void setEnabled(bool isEnabled) final; 47 48 private: 49 ExitIdleRefreshRateCalculator(const ExitIdleRefreshRateCalculator&) = delete; 50 ExitIdleRefreshRateCalculator& operator=(const ExitIdleRefreshRateCalculator&) = delete; 51 52 void setNewRefreshRate(int newRefreshRate); 53 54 int invalidateRefreshRate(); 55 56 EventQueue* mEventQueue; 57 VrrControllerEvent mTimeoutEvent; 58 59 const ExitIdleRefreshRateCalculatorParameters mParams; 60 61 int64_t mLastPresentTimeNs = kDefaultInvalidPresentTimeNs; 62 int mLastRefreshRate = kDefaultInvalidRefreshRate; 63 }; 64 65 } // namespace android::hardware::graphics::composer 66