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 <hardware/hwcomposer2.h>
20 #include <optional>
21 #include <sstream>
22 #include <string>
23 
24 #include "../display/common/CommonDisplayContextProvider.h"
25 
26 namespace android::hardware::graphics::composer {
27 
28 typedef struct PowerStatsProfile {
isOffPowerStatsProfile29     inline bool isOff() const {
30         if ((mPowerMode == HWC_POWER_MODE_OFF) || (mPowerMode == HWC_POWER_MODE_DOZE_SUSPEND)) {
31             return true;
32         } else {
33             return false;
34         }
35     }
36 
37     bool operator==(const PowerStatsProfile& rhs) const {
38         if (isOff() || rhs.isOff()) {
39             return isOff() == rhs.isOff();
40         }
41         return (mWidth == rhs.mWidth) && (mHeight == rhs.mHeight) && (mFps == rhs.mFps) &&
42                 (mPowerMode == rhs.mPowerMode) && (mBrightnessMode == rhs.mBrightnessMode) &&
43                 (mRefreshSource == rhs.mRefreshSource);
44     }
45 
46     bool operator<(const PowerStatsProfile& rhs) const {
47         if (isOff() && rhs.isOff()) {
48             return false;
49         }
50 
51         if (mPowerMode != rhs.mPowerMode) {
52             return (isOff() || (mPowerMode < rhs.mPowerMode));
53         } else if (mBrightnessMode != rhs.mBrightnessMode) {
54             return mBrightnessMode < rhs.mBrightnessMode;
55         } else if (mRefreshSource != rhs.mRefreshSource) {
56             return mRefreshSource < rhs.mRefreshSource;
57         } else if (mWidth != rhs.mWidth) {
58             return mWidth < rhs.mWidth;
59         } else if (mHeight != rhs.mHeight) {
60             return mHeight < rhs.mHeight;
61         } else {
62             return mFps < rhs.mFps;
63         }
64     }
65 
toStringPowerStatsProfile66     std::string toString() const {
67         std::ostringstream os;
68         os << "mWidth = " << mWidth;
69         os << " mHeight = " << mHeight;
70         os << " mFps = " << mFps;
71         os << ", mRefreshSource = " << mRefreshSource;
72         os << ", power mode = " << mPowerMode;
73         os << ", brightness = " << static_cast<int>(mBrightnessMode);
74         return os.str();
75     }
76 
77     int mWidth = 0;
78     int mHeight = 0;
79     int mFps = -1;
80     int mPowerMode = HWC_POWER_MODE_OFF;
81     BrightnessMode mBrightnessMode = BrightnessMode::kInvalidBrightnessMode;
82     RefreshSource mRefreshSource = kRefreshSourceActivePresent;
83 } PowerStatsProfile;
84 
85 } // namespace android::hardware::graphics::composer
86