/* * 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 "../Statistics/VariableRefreshRateStatistic.h" #include "PowerStatsPresentProfileTokenGenerator.h" // #define DEBUG_VRR_POWERSTATS 1 namespace android::hardware::graphics::composer { using aidl::android::hardware::power::stats::State; using aidl::android::hardware::power::stats::StateResidency; typedef std::vector StateResidencies; class DisplayStateResidencyProvider { public: DisplayStateResidencyProvider( std::shared_ptr displayContextProvider, std::shared_ptr statisticsProvider); void getStateResidency(std::vector* stats); const std::vector& getStates(); DisplayStateResidencyProvider(const DisplayStateResidencyProvider& other) = delete; DisplayStateResidencyProvider& operator=(const DisplayStateResidencyProvider& other) = delete; private: static const std::set> kFpsMappingTable; static const std::unordered_set kFpsLowPowerModeMappingTable; static const std::unordered_set kActivePowerModes; // The format of pattern is: ([token label]'delimiter'?)* static constexpr std::string_view kDisplayStateResidencyPattern = "[mode](:)[width](x)[height](@)[fps]()"; static constexpr char kTokenLabelStart = '['; static constexpr char kTokenLabelEnd = ']'; static constexpr char kDelimiterStart = '('; static constexpr char kDelimiterEnd = ')'; void mapStatistics(); uint64_t aggregateStatistics(); void generatePowerStatsStates(); bool parseDisplayStateResidencyPattern(); std::shared_ptr mDisplayContextProvider; std::shared_ptr mStatisticsProvider; DisplayPresentStatistics mStatistics; typedef std::map PowerStatsPresentStatistics; PowerStatsPresentStatistics mRemappedStatistics; PowerStatsPresentProfileTokenGenerator mPowerStatsPresentProfileTokenGenerator; std::vector> mDisplayStateResidencyPattern; std::vector mStates; std::map mPowerStatsPresentProfileToIdMap; #ifdef DEBUG_VRR_POWERSTATS int64_t mLastGetStateResidencyTimeNs = -1; int64_t mLastPowerStatsTotalTimeNs = -1; #endif uint64_t mStartStatisticTimeNs; std::vector mStateResidency; }; } // namespace android::hardware::graphics::composer