| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 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 |  | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 25 | #include <atomic> | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 26 | #include <unordered_set> | 
 | 27 |  | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 28 | #include "../Scheduler/OneShotTimer.h" | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 29 | #include "DisplayIdentification.h" | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 30 |  | 
 | 31 | namespace android { | 
 | 32 | namespace Hwc2 { | 
 | 33 |  | 
 | 34 | class PowerAdvisor { | 
 | 35 | public: | 
 | 36 |     virtual ~PowerAdvisor(); | 
 | 37 |  | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 38 |     virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0; | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 39 |     virtual void notifyDisplayUpdateImminent() = 0; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 40 | }; | 
 | 41 |  | 
 | 42 | namespace impl { | 
 | 43 |  | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 44 | // PowerAdvisor is a wrapper around IPower HAL which takes into account the | 
 | 45 | // full state of the system when sending out power hints to things like the GPU. | 
 | 46 | class PowerAdvisor final : public Hwc2::PowerAdvisor { | 
 | 47 | public: | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 48 |     class HalWrapper { | 
 | 49 |     public: | 
 | 50 |         virtual ~HalWrapper() = default; | 
 | 51 |  | 
 | 52 |         virtual bool setExpensiveRendering(bool enabled) = 0; | 
 | 53 |         virtual bool notifyDisplayUpdateImminent() = 0; | 
 | 54 |     }; | 
 | 55 |  | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 56 |     PowerAdvisor(); | 
 | 57 |     ~PowerAdvisor() override; | 
 | 58 |  | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 59 |     void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override; | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 60 |     void notifyDisplayUpdateImminent() override; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 61 |  | 
 | 62 | private: | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 63 |     HalWrapper* getPowerHal(); | 
 | 64 |  | 
 | 65 |     bool mReconnectPowerHal = false; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 66 |  | 
| Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 67 |     std::unordered_set<DisplayId> mExpensiveDisplays; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 68 |     bool mNotifiedExpensiveRendering = false; | 
| Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 69 |  | 
 | 70 |     const bool mUseUpdateImminentTimer; | 
 | 71 |     std::atomic_bool mSendUpdateImminent = true; | 
 | 72 |     scheduler::OneShotTimer mUpdateImminentTimer; | 
| Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 73 | }; | 
 | 74 |  | 
 | 75 | } // namespace impl | 
 | 76 | } // namespace Hwc2 | 
 | 77 | } // namespace android |