• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "PowerStatsPresentProfileTokenGenerator.h"
18 
19 #include <string>
20 #include <unordered_map>
21 
22 namespace android::hardware::graphics::composer {
23 
generateModeToken()24 std::string PowerStatsPresentProfileTokenGenerator::generateModeToken() {
25     if (mPowerStatsProfile->isOff()) {
26         return "OFF";
27     } else {
28         if (mPowerStatsProfile->mPowerMode == HWC_POWER_MODE_DOZE) {
29             return "LPM";
30         }
31         return (mPowerStatsProfile->mBrightnessMode == BrightnessMode::kHighBrightnessMode) ? "HBM"
32                                                                                             : "NBM";
33     }
34 }
35 
generateWidthToken()36 std::string PowerStatsPresentProfileTokenGenerator::generateWidthToken() {
37     if (mPowerStatsProfile->isOff()) {
38         return "";
39     }
40     return std::to_string(mPowerStatsProfile->mWidth);
41 }
42 
generateHeightToken()43 std::string PowerStatsPresentProfileTokenGenerator::generateHeightToken() {
44     if (mPowerStatsProfile->isOff()) {
45         return "";
46     }
47     return std::to_string(mPowerStatsProfile->mHeight);
48 }
49 
generateFpsToken()50 std::string PowerStatsPresentProfileTokenGenerator::generateFpsToken() {
51     if (mPowerStatsProfile->isOff()) {
52         return "";
53     }
54     if (mPowerStatsProfile->mFps == 0) {
55         return "oth";
56     }
57     return std::to_string(mPowerStatsProfile->mFps);
58 }
59 
generateToken(const std::string & tokenLabel)60 std::optional<std::string> PowerStatsPresentProfileTokenGenerator::generateToken(
61         const std::string& tokenLabel) {
62     static std::unordered_map<std::string, std::function<std::string()>> functors =
63             {{"mode", std::bind(&PowerStatsPresentProfileTokenGenerator::generateModeToken, this)},
64              {"width",
65               std::bind(&PowerStatsPresentProfileTokenGenerator::generateWidthToken, this)},
66              {"height",
67               std::bind(&PowerStatsPresentProfileTokenGenerator::generateHeightToken, this)},
68              {"fps", std::bind(&PowerStatsPresentProfileTokenGenerator::generateFpsToken, this)}};
69 
70     if (!mPowerStatsProfile) {
71         ALOGE("%s: haven't set target mPowerStatsProfile", __func__);
72         return std::nullopt;
73     }
74 
75     if (functors.find(tokenLabel) != functors.end()) {
76         return (functors[tokenLabel])();
77     } else {
78         ALOGE("%s syntax error: unable to find token label = %s", __func__, tokenLabel.c_str());
79         return std::nullopt;
80     }
81 }
82 
83 } // namespace android::hardware::graphics::composer
84