blob: 95eb0e2bb76db22519af35a34238d29e6c184724 [file] [log] [blame]
Michael Wright5d22d4f2018-06-21 02:50:34 +01001/*
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 Stoza030fbc12020-02-19 15:32:01 -080019#include <atomic>
Peiyong Lin74ca2f42019-01-14 19:36:57 -080020#include <unordered_set>
21
Dan Stoza20950002020-06-18 14:56:58 -070022#include <utils/Mutex.h>
23
Dan Stoza030fbc12020-02-19 15:32:01 -080024#include "../Scheduler/OneShotTimer.h"
Peiyong Lin74ca2f42019-01-14 19:36:57 -080025#include "DisplayIdentification.h"
Michael Wright5d22d4f2018-06-21 02:50:34 +010026
27namespace android {
28namespace Hwc2 {
29
30class PowerAdvisor {
31public:
32 virtual ~PowerAdvisor();
33
Dan Stoza29e7bdf2020-03-23 14:43:09 -070034 virtual void onBootFinished() = 0;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080035 virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
Dan Stoza030fbc12020-02-19 15:32:01 -080036 virtual void notifyDisplayUpdateImminent() = 0;
Michael Wright5d22d4f2018-06-21 02:50:34 +010037};
38
39namespace impl {
40
Michael Wright5d22d4f2018-06-21 02:50:34 +010041// 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.
43class PowerAdvisor final : public Hwc2::PowerAdvisor {
44public:
Dan Stoza030fbc12020-02-19 15:32:01 -080045 class HalWrapper {
46 public:
47 virtual ~HalWrapper() = default;
48
49 virtual bool setExpensiveRendering(bool enabled) = 0;
50 virtual bool notifyDisplayUpdateImminent() = 0;
51 };
52
Michael Wright5d22d4f2018-06-21 02:50:34 +010053 PowerAdvisor();
54 ~PowerAdvisor() override;
55
Dan Stoza29e7bdf2020-03-23 14:43:09 -070056 void onBootFinished() override;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080057 void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
Dan Stoza030fbc12020-02-19 15:32:01 -080058 void notifyDisplayUpdateImminent() override;
Michael Wright5d22d4f2018-06-21 02:50:34 +010059
60private:
Dan Stoza20950002020-06-18 14:56:58 -070061 HalWrapper* getPowerHal() REQUIRES(mPowerHalMutex);
62 bool mReconnectPowerHal GUARDED_BY(mPowerHalMutex) = false;
63 std::mutex mPowerHalMutex;
Dan Stoza030fbc12020-02-19 15:32:01 -080064
Dan Stoza29e7bdf2020-03-23 14:43:09 -070065 std::atomic_bool mBootFinished = false;
Michael Wright5d22d4f2018-06-21 02:50:34 +010066
Peiyong Lin74ca2f42019-01-14 19:36:57 -080067 std::unordered_set<DisplayId> mExpensiveDisplays;
Michael Wright5d22d4f2018-06-21 02:50:34 +010068 bool mNotifiedExpensiveRendering = false;
Dan Stoza030fbc12020-02-19 15:32:01 -080069
70 const bool mUseUpdateImminentTimer;
71 std::atomic_bool mSendUpdateImminent = true;
72 scheduler::OneShotTimer mUpdateImminentTimer;
Michael Wright5d22d4f2018-06-21 02:50:34 +010073};
74
75} // namespace impl
76} // namespace Hwc2
77} // namespace android