1 /*
2  * Copyright 2018 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 #define HWC2_INCLUDE_STRINGIFICATION
20 #define HWC2_USE_CPP11
21 #include <hardware/hwcomposer2.h>
22 #undef HWC2_INCLUDE_STRINGIFICATION
23 #undef HWC2_USE_CPP11
24 
25 #include <unordered_set>
26 
27 #include <android/hardware/power/1.3/IPower.h>
28 #include <utils/StrongPointer.h>
29 
30 #include "DisplayIdentification.h"
31 
32 namespace android {
33 namespace Hwc2 {
34 
35 class PowerAdvisor {
36 public:
37     virtual ~PowerAdvisor();
38 
39     virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
40 };
41 
42 namespace impl {
43 
44 namespace V1_3 = android::hardware::power::V1_3;
45 
46 // PowerAdvisor is a wrapper around IPower HAL which takes into account the
47 // full state of the system when sending out power hints to things like the GPU.
48 class PowerAdvisor final : public Hwc2::PowerAdvisor {
49 public:
50     PowerAdvisor();
51     ~PowerAdvisor() override;
52 
53     void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
54 
55 private:
56     sp<V1_3::IPower> getPowerHal();
57 
58     std::unordered_set<DisplayId> mExpensiveDisplays;
59     bool mNotifiedExpensiveRendering = false;
60     bool mReconnectPowerHal = false;
61 };
62 
63 } // namespace impl
64 } // namespace Hwc2
65 } // namespace android
66