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 <optional> 20 #include <string> 21 22 #include "../Statistics/VariableRefreshRateStatistic.h" 23 #include "../display/common/CommonDisplayContextProvider.h" 24 25 namespace android::hardware::graphics::composer { 26 27 typedef struct PowerStatsPresentProfile { isOffPowerStatsPresentProfile28 inline bool isOff() const { 29 if ((mPowerMode == HWC_POWER_MODE_OFF) || (mPowerMode == HWC_POWER_MODE_DOZE_SUSPEND)) { 30 return true; 31 } else { 32 return false; 33 } 34 } 35 36 bool operator==(const PowerStatsPresentProfile& rhs) const { 37 if (isOff() || rhs.isOff()) { 38 return isOff() == rhs.isOff(); 39 } 40 return (mWidth == rhs.mWidth) && (mHeight == rhs.mHeight) && (mFps == rhs.mFps) && 41 (mPowerMode == rhs.mPowerMode) && (mBrightnessMode == rhs.mBrightnessMode); 42 } 43 44 bool operator<(const PowerStatsPresentProfile& rhs) const { 45 if (isOff() && rhs.isOff()) { 46 return false; 47 } 48 49 if (mPowerMode != rhs.mPowerMode) { 50 return (isOff() || (mPowerMode < rhs.mPowerMode)); 51 } else if (mBrightnessMode != rhs.mBrightnessMode) { 52 return mBrightnessMode < rhs.mBrightnessMode; 53 } else if (mWidth != rhs.mWidth) { 54 return mWidth < rhs.mWidth; 55 } else if (mHeight != rhs.mHeight) { 56 return mHeight < rhs.mHeight; 57 } else { 58 return mFps < rhs.mFps; 59 } 60 } 61 toStringPowerStatsPresentProfile62 std::string toString() const { 63 std::ostringstream os; 64 os << "mWidth = " << mWidth; 65 os << " mHeight = " << mHeight; 66 os << " mFps = " << mFps; 67 os << ", power mode = " << mPowerMode; 68 os << ", brightness = " << static_cast<int>(mBrightnessMode); 69 return os.str(); 70 } 71 72 int mWidth = 0; 73 int mHeight = 0; 74 int mFps = -1; 75 int mPowerMode = HWC_POWER_MODE_OFF; 76 BrightnessMode mBrightnessMode = BrightnessMode::kInvalidBrightnessMode; 77 78 } PowerStatsPresentProfile; 79 80 class PowerStatsPresentProfileTokenGenerator { 81 public: 82 PowerStatsPresentProfileTokenGenerator() = default; 83 setPowerStatsPresentProfile(const PowerStatsPresentProfile * powerStatsPresentProfile)84 void setPowerStatsPresentProfile(const PowerStatsPresentProfile* powerStatsPresentProfile) { 85 mPowerStatsProfile = powerStatsPresentProfile; 86 } 87 88 std::optional<std::string> generateToken(const std::string& tokenLabel); 89 90 private: 91 std::string generateModeToken(); 92 93 std::string generateWidthToken(); 94 95 std::string generateHeightToken(); 96 97 std::string generateFpsToken(); 98 99 const PowerStatsPresentProfile* mPowerStatsProfile; 100 }; 101 102 } // namespace android::hardware::graphics::composer 103