blob: f2d076691aebb1a390f4aa02854aa9c4bde590eb [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 {
Alec Mouridea1ac52021-06-23 18:12:18 -070028
29class SurfaceFlinger;
30
Michael Wright5d22d4f2018-06-21 02:50:34 +010031namespace Hwc2 {
32
33class PowerAdvisor {
34public:
35 virtual ~PowerAdvisor();
36
Alec Mouridea1ac52021-06-23 18:12:18 -070037 // Initializes resources that cannot be initialized on construction
38 virtual void init() = 0;
Dan Stoza29e7bdf2020-03-23 14:43:09 -070039 virtual void onBootFinished() = 0;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080040 virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
Alec Mouridea1ac52021-06-23 18:12:18 -070041 virtual bool isUsingExpensiveRendering() = 0;
Dan Stoza030fbc12020-02-19 15:32:01 -080042 virtual void notifyDisplayUpdateImminent() = 0;
Michael Wright5d22d4f2018-06-21 02:50:34 +010043};
44
45namespace impl {
46
Michael Wright5d22d4f2018-06-21 02:50:34 +010047// PowerAdvisor is a wrapper around IPower HAL which takes into account the
48// full state of the system when sending out power hints to things like the GPU.
49class PowerAdvisor final : public Hwc2::PowerAdvisor {
50public:
Dan Stoza030fbc12020-02-19 15:32:01 -080051 class HalWrapper {
52 public:
53 virtual ~HalWrapper() = default;
54
55 virtual bool setExpensiveRendering(bool enabled) = 0;
56 virtual bool notifyDisplayUpdateImminent() = 0;
57 };
58
Alec Mouridea1ac52021-06-23 18:12:18 -070059 PowerAdvisor(SurfaceFlinger& flinger);
Michael Wright5d22d4f2018-06-21 02:50:34 +010060 ~PowerAdvisor() override;
61
Alec Mouridea1ac52021-06-23 18:12:18 -070062 void init() override;
Dan Stoza29e7bdf2020-03-23 14:43:09 -070063 void onBootFinished() override;
Peiyong Lin74ca2f42019-01-14 19:36:57 -080064 void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
Alec Mouridea1ac52021-06-23 18:12:18 -070065 bool isUsingExpensiveRendering() override { return mNotifiedExpensiveRendering; }
Dan Stoza030fbc12020-02-19 15:32:01 -080066 void notifyDisplayUpdateImminent() override;
Michael Wright5d22d4f2018-06-21 02:50:34 +010067
68private:
Dan Stoza20950002020-06-18 14:56:58 -070069 HalWrapper* getPowerHal() REQUIRES(mPowerHalMutex);
70 bool mReconnectPowerHal GUARDED_BY(mPowerHalMutex) = false;
71 std::mutex mPowerHalMutex;
Dan Stoza030fbc12020-02-19 15:32:01 -080072
Dan Stoza29e7bdf2020-03-23 14:43:09 -070073 std::atomic_bool mBootFinished = false;
Michael Wright5d22d4f2018-06-21 02:50:34 +010074
Peiyong Lin74ca2f42019-01-14 19:36:57 -080075 std::unordered_set<DisplayId> mExpensiveDisplays;
Michael Wright5d22d4f2018-06-21 02:50:34 +010076 bool mNotifiedExpensiveRendering = false;
Dan Stoza030fbc12020-02-19 15:32:01 -080077
Alec Mouridea1ac52021-06-23 18:12:18 -070078 SurfaceFlinger& mFlinger;
79 const bool mUseScreenUpdateTimer;
Dan Stoza030fbc12020-02-19 15:32:01 -080080 std::atomic_bool mSendUpdateImminent = true;
Alec Mouridea1ac52021-06-23 18:12:18 -070081 scheduler::OneShotTimer mScreenUpdateTimer;
Michael Wright5d22d4f2018-06-21 02:50:34 +010082};
83
84} // namespace impl
85} // namespace Hwc2
86} // namespace android