blob: 34e63e725b63ff07fddf1a916593f65c6a376663 [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 Stoza030fbc12020-02-19 15:32:01 -080022#include "../Scheduler/OneShotTimer.h"
Peiyong Lin74ca2f42019-01-14 19:36:57 -080023#include "DisplayIdentification.h"
Michael Wright5d22d4f2018-06-21 02:50:34 +010024
25namespace android {
26namespace Hwc2 {
27
28class PowerAdvisor {
29public:
30 virtual ~PowerAdvisor();
31
Dan Stoza29e7bdf2020-03-23 14:43:09 -070032 virtual void onBootFinished() = 0;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080033 virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
Dan Stoza030fbc12020-02-19 15:32:01 -080034 virtual void notifyDisplayUpdateImminent() = 0;
Michael Wright5d22d4f2018-06-21 02:50:34 +010035};
36
37namespace impl {
38
Michael Wright5d22d4f2018-06-21 02:50:34 +010039// PowerAdvisor is a wrapper around IPower HAL which takes into account the
40// full state of the system when sending out power hints to things like the GPU.
41class PowerAdvisor final : public Hwc2::PowerAdvisor {
42public:
Dan Stoza030fbc12020-02-19 15:32:01 -080043 class HalWrapper {
44 public:
45 virtual ~HalWrapper() = default;
46
47 virtual bool setExpensiveRendering(bool enabled) = 0;
48 virtual bool notifyDisplayUpdateImminent() = 0;
49 };
50
Michael Wright5d22d4f2018-06-21 02:50:34 +010051 PowerAdvisor();
52 ~PowerAdvisor() override;
53
Dan Stoza29e7bdf2020-03-23 14:43:09 -070054 void onBootFinished() override;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080055 void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
Dan Stoza030fbc12020-02-19 15:32:01 -080056 void notifyDisplayUpdateImminent() override;
Michael Wright5d22d4f2018-06-21 02:50:34 +010057
58private:
Dan Stoza030fbc12020-02-19 15:32:01 -080059 HalWrapper* getPowerHal();
60
Dan Stoza29e7bdf2020-03-23 14:43:09 -070061 std::atomic_bool mBootFinished = false;
Dan Stoza030fbc12020-02-19 15:32:01 -080062 bool mReconnectPowerHal = false;
Michael Wright5d22d4f2018-06-21 02:50:34 +010063
Peiyong Lin74ca2f42019-01-14 19:36:57 -080064 std::unordered_set<DisplayId> mExpensiveDisplays;
Michael Wright5d22d4f2018-06-21 02:50:34 +010065 bool mNotifiedExpensiveRendering = false;
Dan Stoza030fbc12020-02-19 15:32:01 -080066
67 const bool mUseUpdateImminentTimer;
68 std::atomic_bool mSendUpdateImminent = true;
69 scheduler::OneShotTimer mUpdateImminentTimer;
Michael Wright5d22d4f2018-06-21 02:50:34 +010070};
71
72} // namespace impl
73} // namespace Hwc2
74} // namespace android