1414 * limitations under the License.
1515 */
1616
17- // #define LOG_NDEBUG 0
17+ // #define LOG_NDEBUG 0
1818
1919#define ATRACE_TAG ATRACE_TAG_GRAPHICS
2020
2424#include < unistd.h>
2525#include < cinttypes>
2626#include < cstdint>
27+ #include < functional>
2728#include < optional>
2829
2930#include < android-base/properties.h>
3334
3435#include < binder/IServiceManager.h>
3536
36- #include " ../SurfaceFlingerProperties.h"
37+ #pragma clang diagnostic push
38+ #pragma clang diagnostic ignored "-Wconversion"
39+ #include < powermanager/PowerHalController.h>
40+ #include < powermanager/PowerHintSessionWrapper.h>
41+ #pragma clang diagnostic pop
3742
43+ #include < common/FlagManager.h>
3844#include " PowerAdvisor.h"
39- #include " SurfaceFlinger.h"
4045
41- namespace android {
42- namespace Hwc2 {
46+ namespace hal = aidl::android::hardware::power;
4347
44- PowerAdvisor::~PowerAdvisor () = default ;
45-
46- namespace impl {
47-
48- using aidl::android::hardware::power::Boost;
49- using aidl::android::hardware::power::ChannelConfig;
50- using aidl::android::hardware::power::Mode;
51- using aidl::android::hardware::power::SessionHint;
52- using aidl::android::hardware::power::SessionTag;
53- using aidl::android::hardware::power::WorkDuration;
54- using aidl::android::hardware::power::WorkDurationFixedV1;
48+ namespace android ::adpf::impl {
5549
56- using aidl::android::hardware::common::fmq::MQDescriptor;
5750using aidl::android::hardware::common::fmq::SynchronizedReadWrite;
58- using aidl::android::hardware::power::ChannelMessage;
5951using android::hardware::EventFlag;
6052
61- using ChannelMessageContents = ChannelMessage::ChannelMessageContents;
62- using MsgQueue = android::AidlMessageQueue<ChannelMessage, SynchronizedReadWrite>;
53+ using ChannelMessageContents = hal:: ChannelMessage::ChannelMessageContents;
54+ using MsgQueue = android::AidlMessageQueue<hal:: ChannelMessage, SynchronizedReadWrite>;
6355using FlagQueue = android::AidlMessageQueue<int8_t , SynchronizedReadWrite>;
6456
6557PowerAdvisor::~PowerAdvisor () = default ;
6658
6759namespace {
68- std::chrono::milliseconds getUpdateTimeout () {
69- // Default to a timeout of 80ms if nothing else is specified
70- static std::chrono::milliseconds timeout =
71- std::chrono::milliseconds (sysprop::display_update_imminent_timeout_ms (80 ));
72- return timeout;
73- }
74-
7560void traceExpensiveRendering (bool enabled) {
7661 if (enabled) {
7762 SFTRACE_ASYNC_BEGIN (" ExpensiveRendering" , 0 );
@@ -82,28 +67,30 @@ void traceExpensiveRendering(bool enabled) {
8267
8368} // namespace
8469
85- PowerAdvisor::PowerAdvisor (SurfaceFlinger& flinger)
86- : mPowerHal (std::make_unique<power::PowerHalController>()), mFlinger (flinger) {
87- if (getUpdateTimeout () > 0ms) {
88- mScreenUpdateTimer .emplace (" UpdateImminentTimer" , getUpdateTimeout (),
70+ PowerAdvisor::PowerAdvisor (std::function<void ()>&& sfDisableExpensiveFn,
71+ std::chrono::milliseconds timeout)
72+ : mPowerHal (std::make_unique<power::PowerHalController>()) {
73+ if (timeout > 0ms) {
74+ mScreenUpdateTimer .emplace (" UpdateImminentTimer" , timeout,
8975 /* resetCallback */ nullptr ,
9076 /* timeoutCallback */
91- [this ] {
77+ [this , disableExpensiveFn = std::move (sfDisableExpensiveFn),
78+ timeout] {
9279 while (true ) {
9380 auto timeSinceLastUpdate = std::chrono::nanoseconds (
9481 systemTime () - mLastScreenUpdatedTime .load ());
95- if (timeSinceLastUpdate >= getUpdateTimeout () ) {
82+ if (timeSinceLastUpdate >= timeout ) {
9683 break ;
9784 }
9885 // We may try to disable expensive rendering and allow
9986 // for sending DISPLAY_UPDATE_IMMINENT hints too early if
10087 // we idled very shortly after updating the screen, so
10188 // make sure we wait enough time.
102- std::this_thread::sleep_for (getUpdateTimeout () -
89+ std::this_thread::sleep_for (timeout -
10390 timeSinceLastUpdate);
10491 }
10592 mSendUpdateImminent .store (true );
106- mFlinger . disableExpensiveRendering ();
93+ disableExpensiveFn ();
10794 });
10895 }
10996}
@@ -132,7 +119,7 @@ void PowerAdvisor::setExpensiveRenderingExpected(DisplayId displayId, bool expec
132119
133120 const bool expectsExpensiveRendering = !mExpensiveDisplays .empty ();
134121 if (mNotifiedExpensiveRendering != expectsExpensiveRendering) {
135- auto ret = getPowerHal ().setMode (Mode::EXPENSIVE_RENDERING, expectsExpensiveRendering);
122+ auto ret = getPowerHal ().setMode (hal:: Mode::EXPENSIVE_RENDERING, expectsExpensiveRendering);
136123 if (!ret.isOk ()) {
137124 if (ret.isUnsupported ()) {
138125 mHasExpensiveRendering = false ;
@@ -151,7 +138,7 @@ void PowerAdvisor::notifyCpuLoadUp() {
151138 if (!mBootFinished .load ()) {
152139 return ;
153140 }
154- sendHintSessionHint (SessionHint::CPU_LOAD_UP);
141+ sendHintSessionHint (hal:: SessionHint::CPU_LOAD_UP);
155142}
156143
157144void PowerAdvisor::notifyDisplayUpdateImminentAndCpuReset () {
@@ -163,12 +150,12 @@ void PowerAdvisor::notifyDisplayUpdateImminentAndCpuReset() {
163150
164151 if (mSendUpdateImminent .exchange (false )) {
165152 ALOGV (" AIDL notifyDisplayUpdateImminentAndCpuReset" );
166- sendHintSessionHint (SessionHint::CPU_LOAD_RESET);
153+ sendHintSessionHint (hal:: SessionHint::CPU_LOAD_RESET);
167154
168155 if (!mHasDisplayUpdateImminent ) {
169156 ALOGV (" Skipped sending DISPLAY_UPDATE_IMMINENT because HAL doesn't support it" );
170157 } else {
171- auto ret = getPowerHal ().setBoost (Boost::DISPLAY_UPDATE_IMMINENT, 0 );
158+ auto ret = getPowerHal ().setBoost (hal:: Boost::DISPLAY_UPDATE_IMMINENT, 0 );
172159 if (ret.isUnsupported ()) {
173160 mHasDisplayUpdateImminent = false ;
174161 }
@@ -205,7 +192,7 @@ bool PowerAdvisor::shouldCreateSessionWithConfig() {
205192 FlagManager::getInstance ().adpf_use_fmq_channel ();
206193}
207194
208- void PowerAdvisor::sendHintSessionHint (SessionHint hint) {
195+ void PowerAdvisor::sendHintSessionHint (hal:: SessionHint hint) {
209196 if (!mBootFinished || !usePowerHintSession ()) {
210197 ALOGV (" Power hint session is not enabled, skip sending session hint" );
211198 return ;
@@ -236,7 +223,7 @@ bool PowerAdvisor::ensurePowerHintSessionRunning() {
236223 static_cast <int32_t >(getuid ()),
237224 mHintSessionThreadIds ,
238225 mTargetDuration .ns (),
239- SessionTag::SURFACEFLINGER,
226+ hal:: SessionTag::SURFACEFLINGER,
240227 &mSessionConfig );
241228 if (ret.isOk ()) {
242229 mHintSession = ret.value ();
@@ -326,7 +313,7 @@ void PowerAdvisor::reportActualWorkDuration() {
326313 return ;
327314 }
328315 SFTRACE_CALL ();
329- std::optional<WorkDuration> actualDuration = estimateWorkDuration ();
316+ std::optional<hal:: WorkDuration> actualDuration = estimateWorkDuration ();
330317 if (!actualDuration.has_value () || actualDuration->durationNanos < 0 ) {
331318 ALOGV (" Failed to send actual work duration, skipping" );
332319 return ;
@@ -377,7 +364,7 @@ void PowerAdvisor::reportActualWorkDuration() {
377364 mHintSessionQueue .clear ();
378365}
379366
380- template <ChannelMessage::ChannelMessageContents::Tag T, class In >
367+ template <hal:: ChannelMessage::ChannelMessageContents::Tag T, class In >
381368bool PowerAdvisor::writeHintSessionMessage (In* contents, size_t count) {
382369 if (!mMsgQueue ) {
383370 ALOGV (" Skip using FMQ with message tag %hhd as it's not supported" , T);
@@ -395,21 +382,21 @@ bool PowerAdvisor::writeHintSessionMessage(In* contents, size_t count) {
395382 }
396383 for (size_t i = 0 ; i < count; ++i) {
397384 if constexpr (T == ChannelMessageContents::Tag::workDuration) {
398- const WorkDuration& duration = contents[i];
399- new (tx.getSlot (i)) ChannelMessage{
385+ const hal:: WorkDuration& duration = contents[i];
386+ new (tx.getSlot (i)) hal:: ChannelMessage{
400387 .sessionID = static_cast <int32_t >(mSessionConfig .id ),
401388 .timeStampNanos =
402389 (i == count - 1 ) ? ::android::uptimeNanos () : duration.timeStampNanos ,
403390 .data = ChannelMessageContents::make<ChannelMessageContents::Tag::workDuration,
404- WorkDurationFixedV1>({
391+ hal:: WorkDurationFixedV1>({
405392 .durationNanos = duration.durationNanos ,
406393 .workPeriodStartTimestampNanos = duration.workPeriodStartTimestampNanos ,
407394 .cpuDurationNanos = duration.cpuDurationNanos ,
408395 .gpuDurationNanos = duration.gpuDurationNanos ,
409396 }),
410397 };
411398 } else {
412- new (tx.getSlot (i)) ChannelMessage{
399+ new (tx.getSlot (i)) hal:: ChannelMessage{
413400 .sessionID = static_cast <int32_t >(mSessionConfig .id ),
414401 .timeStampNanos = ::android::uptimeNanos (),
415402 .data = ChannelMessageContents::make<T, In>(std::move (contents[i])),
@@ -572,7 +559,7 @@ std::vector<DisplayId> PowerAdvisor::getOrderedDisplayIds(
572559 return sortedDisplays;
573560}
574561
575- std::optional<WorkDuration> PowerAdvisor::estimateWorkDuration () {
562+ std::optional<hal:: WorkDuration> PowerAdvisor::estimateWorkDuration () {
576563 if (!mExpectedPresentTimes .isFull () || !mCommitStartTimes .isFull ()) {
577564 return std::nullopt ;
578565 }
@@ -657,7 +644,7 @@ std::optional<WorkDuration> PowerAdvisor::estimateWorkDuration() {
657644 Duration combinedDuration = combineTimingEstimates (totalDuration, flingerDuration);
658645 Duration cpuDuration = combineTimingEstimates (totalDurationWithoutGpu, flingerDuration);
659646
660- WorkDuration duration{
647+ hal:: WorkDuration duration{
661648 .timeStampNanos = TimePoint::now ().ns (),
662649 .durationNanos = combinedDuration.ns (),
663650 .workPeriodStartTimestampNanos = mCommitStartTimes [0 ].ns (),
@@ -760,6 +747,4 @@ power::PowerHalController& PowerAdvisor::getPowerHal() {
760747 return *mPowerHal ;
761748}
762749
763- } // namespace impl
764- } // namespace Hwc2
765- } // namespace android
750+ } // namespace android::adpf::impl
0 commit comments