• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #include <atomic>
20 #include <unordered_set>
21 
22 #include <utils/Mutex.h>
23 
24 #include "../Scheduler/OneShotTimer.h"
25 #include "DisplayIdentification.h"
26 
27 namespace android {
28 
29 class SurfaceFlinger;
30 
31 namespace Hwc2 {
32 
33 class PowerAdvisor {
34 public:
35     virtual ~PowerAdvisor();
36 
37     // Initializes resources that cannot be initialized on construction
38     virtual void init() = 0;
39     virtual void onBootFinished() = 0;
40     virtual void setExpensiveRenderingExpected(DisplayId displayId, bool expected) = 0;
41     virtual bool isUsingExpensiveRendering() = 0;
42     virtual void notifyDisplayUpdateImminent() = 0;
43 };
44 
45 namespace impl {
46 
47 // 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.
49 class PowerAdvisor final : public Hwc2::PowerAdvisor {
50 public:
51     class HalWrapper {
52     public:
53         virtual ~HalWrapper() = default;
54 
55         virtual bool setExpensiveRendering(bool enabled) = 0;
56         virtual bool notifyDisplayUpdateImminent() = 0;
57     };
58 
59     PowerAdvisor(SurfaceFlinger& flinger);
60     ~PowerAdvisor() override;
61 
62     void init() override;
63     void onBootFinished() override;
64     void setExpensiveRenderingExpected(DisplayId displayId, bool expected) override;
isUsingExpensiveRendering()65     bool isUsingExpensiveRendering() override { return mNotifiedExpensiveRendering; }
66     void notifyDisplayUpdateImminent() override;
67 
68 private:
69     HalWrapper* getPowerHal() REQUIRES(mPowerHalMutex);
70     bool mReconnectPowerHal GUARDED_BY(mPowerHalMutex) = false;
71     std::mutex mPowerHalMutex;
72 
73     std::atomic_bool mBootFinished = false;
74 
75     std::unordered_set<DisplayId> mExpensiveDisplays;
76     bool mNotifiedExpensiveRendering = false;
77 
78     SurfaceFlinger& mFlinger;
79     const bool mUseScreenUpdateTimer;
80     std::atomic_bool mSendUpdateImminent = true;
81     scheduler::OneShotTimer mScreenUpdateTimer;
82 };
83 
84 } // namespace impl
85 } // namespace Hwc2
86 } // namespace android
87