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 | |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 19 | #include <atomic> |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 20 | #include <unordered_set> |
| 21 | |
Dan Stoza | 2095000 | 2020-06-18 14:56:58 -0700 | [diff] [blame^] | 22 | #include <utils/Mutex.h> |
| 23 | |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 24 | #include "../Scheduler/OneShotTimer.h" |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 25 | #include "DisplayIdentification.h" |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | namespace Hwc2 { |
| 29 | |
| 30 | class PowerAdvisor { |
| 31 | public: |
| 32 | virtual ~PowerAdvisor(); |
| 33 | |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 34 | virtual void onBootFinished() = 0; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 35 | virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 36 | virtual void notifyDisplayUpdateImminent() = 0; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | namespace impl { |
| 40 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 41 | // PowerAdvisor is a wrapper around IPower HAL which takes into account the |
| 42 | // full state of the system when sending out power hints to things like the GPU. |
| 43 | class PowerAdvisor final : public Hwc2::PowerAdvisor { |
| 44 | public: |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 45 | class HalWrapper { |
| 46 | public: |
| 47 | virtual ~HalWrapper() = default; |
| 48 | |
| 49 | virtual bool setExpensiveRendering(bool enabled) = 0; |
| 50 | virtual bool notifyDisplayUpdateImminent() = 0; |
| 51 | }; |
| 52 | |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 53 | PowerAdvisor(); |
| 54 | ~PowerAdvisor() override; |
| 55 | |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 56 | void onBootFinished() override; |
Peiyong Lin | 74ca2f4 | 2019-01-14 19:36:57 -0800 | [diff] [blame] | 57 | void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 58 | void notifyDisplayUpdateImminent() override; |
Michael Wright | 5d22d4f | 2018-06-21 02:50:34 +0100 | [diff] [blame] | 59 | |
| 60 | private: |
Dan Stoza | 2095000 | 2020-06-18 14:56:58 -0700 | [diff] [blame^] | 61 | HalWrapper* getPowerHal() REQUIRES(mPowerHalMutex); |
| 62 | bool mReconnectPowerHal GUARDED_BY(mPowerHalMutex) = false; |
| 63 | std::mutex mPowerHalMutex; |
Dan Stoza | 030fbc1 | 2020-02-19 15:32:01 -0800 | [diff] [blame] | 64 | |
Dan Stoza | 29e7bdf | 2020-03-23 14:43:09 -0700 | [diff] [blame] | 65 | std::atomic_bool mBootFinished = 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 |