blob: 957d28989b56a5e472d005ff60de5f1fec46fef8 [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
Peiyong Lin74ca2f42019-01-14 19:36:57 -080038 virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
Dan Stoza030fbc12020-02-19 15:32:01 -080039 virtual void notifyDisplayUpdateImminent() = 0;
Michael Wright5d22d4f2018-06-21 02:50:34 +010040};
41
42namespace impl {
43
Michael Wright5d22d4f2018-06-21 02:50:34 +010044// 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.
46class PowerAdvisor final : public Hwc2::PowerAdvisor {
47public:
Dan Stoza030fbc12020-02-19 15:32:01 -080048 class HalWrapper {
49 public:
50 virtual ~HalWrapper() = default;
51
52 virtual bool setExpensiveRendering(bool enabled) = 0;
53 virtual bool notifyDisplayUpdateImminent() = 0;
54 };
55
Michael Wright5d22d4f2018-06-21 02:50:34 +010056 PowerAdvisor();
57 ~PowerAdvisor() override;
58
Peiyong Lin74ca2f42019-01-14 19:36:57 -080059 void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
Dan Stoza030fbc12020-02-19 15:32:01 -080060 void notifyDisplayUpdateImminent() override;
Michael Wright5d22d4f2018-06-21 02:50:34 +010061
62private:
Dan Stoza030fbc12020-02-19 15:32:01 -080063 HalWrapper* getPowerHal();
64
65 bool mReconnectPowerHal = 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