blob: 4a90acbdeebd41b2b715f217ec97813116298619 [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
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 Stoza030fbc12020-02-19 15:32:01 -080025#include <atomic>
Peiyong Lin74ca2f42019-01-14 19:36:57 -080026#include <unordered_set>
27
Dan Stoza030fbc12020-02-19 15:32:01 -080028#include "../Scheduler/OneShotTimer.h"
Peiyong Lin74ca2f42019-01-14 19:36:57 -080029#include "DisplayIdentification.h"
Michael Wright5d22d4f2018-06-21 02:50:34 +010030
31namespace android {
32namespace Hwc2 {
33
34class PowerAdvisor {
35public:
36 virtual ~PowerAdvisor();
37
Dan Stoza29e7bdf2020-03-23 14:43:09 -070038 virtual void onBootFinished() = 0;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080039 virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
Dan Stoza030fbc12020-02-19 15:32:01 -080040 virtual void notifyDisplayUpdateImminent() = 0;
Michael Wright5d22d4f2018-06-21 02:50:34 +010041};
42
43namespace impl {
44
Michael Wright5d22d4f2018-06-21 02:50:34 +010045// PowerAdvisor is a wrapper around IPower HAL which takes into account the
46// full state of the system when sending out power hints to things like the GPU.
47class PowerAdvisor final : public Hwc2::PowerAdvisor {
48public:
Dan Stoza030fbc12020-02-19 15:32:01 -080049 class HalWrapper {
50 public:
51 virtual ~HalWrapper() = default;
52
53 virtual bool setExpensiveRendering(bool enabled) = 0;
54 virtual bool notifyDisplayUpdateImminent() = 0;
55 };
56
Michael Wright5d22d4f2018-06-21 02:50:34 +010057 PowerAdvisor();
58 ~PowerAdvisor() override;
59
Dan Stoza29e7bdf2020-03-23 14:43:09 -070060 void onBootFinished() override;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080061 void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
Dan Stoza030fbc12020-02-19 15:32:01 -080062 void notifyDisplayUpdateImminent() override;
Michael Wright5d22d4f2018-06-21 02:50:34 +010063
64private:
Dan Stoza030fbc12020-02-19 15:32:01 -080065 HalWrapper* getPowerHal();
66
Dan Stoza29e7bdf2020-03-23 14:43:09 -070067 std::atomic_bool mBootFinished = false;
Dan Stoza030fbc12020-02-19 15:32:01 -080068 bool mReconnectPowerHal = false;
Michael Wright5d22d4f2018-06-21 02:50:34 +010069
Peiyong Lin74ca2f42019-01-14 19:36:57 -080070 std::unordered_set<DisplayId> mExpensiveDisplays;
Michael Wright5d22d4f2018-06-21 02:50:34 +010071 bool mNotifiedExpensiveRendering = false;
Dan Stoza030fbc12020-02-19 15:32:01 -080072
73 const bool mUseUpdateImminentTimer;
74 std::atomic_bool mSendUpdateImminent = true;
75 scheduler::OneShotTimer mUpdateImminentTimer;
Michael Wright5d22d4f2018-06-21 02:50:34 +010076};
77
78} // namespace impl
79} // namespace Hwc2
80} // namespace android