Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ffb0288 authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "Reduce more power advisor churn" into tm-dev

parents 6d590fe0 29382ada
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -64,9 +64,10 @@ using scheduler::OneShotTimer;
PowerAdvisor::~PowerAdvisor() = default;

namespace {
int32_t getUpdateTimeout() {
std::chrono::milliseconds getUpdateTimeout() {
    // Default to a timeout of 80ms if nothing else is specified
    static int32_t timeout = sysprop::display_update_imminent_timeout_ms(80);
    static std::chrono::milliseconds timeout =
            std::chrono::milliseconds(sysprop::display_update_imminent_timeout_ms(80));
    return timeout;
}

@@ -81,21 +82,23 @@ void traceExpensiveRendering(bool enabled) {
} // namespace

PowerAdvisor::PowerAdvisor(SurfaceFlinger& flinger) : mFlinger(flinger) {
    if (getUpdateTimeout()) {
        mScreenUpdateTimer.emplace("UpdateImminentTimer",
                                   OneShotTimer::Interval(getUpdateTimeout()),
    if (getUpdateTimeout() > 0ms) {
        mScreenUpdateTimer.emplace("UpdateImminentTimer", getUpdateTimeout(),
                                   /* resetCallback */ nullptr,
                                   /* timeoutCallback */
                                   [this] {
                                       const nsecs_t timeSinceLastUpdate =
                                               systemTime() - mLastScreenUpdatedTime.load();
                                       if (timeSinceLastUpdate < getUpdateTimeout()) {
                                       while (true) {
                                           auto timeSinceLastUpdate = std::chrono::nanoseconds(
                                                   systemTime() - mLastScreenUpdatedTime.load());
                                           if (timeSinceLastUpdate >= getUpdateTimeout()) {
                                               break;
                                           }
                                           // We may try to disable expensive rendering and allow
                                           // for sending DISPLAY_UPDATE_IMMINENT hints too early if
                                           // we idled very shortly after updating the screen, so
                                           // make sure we wait enough time.
                                           std::this_thread::sleep_for(std::chrono::nanoseconds(
                                                   getUpdateTimeout() - timeSinceLastUpdate));
                                           std::this_thread::sleep_for(getUpdateTimeout() -
                                                                       timeSinceLastUpdate);
                                       }
                                       mSendUpdateImminent.store(true);
                                       mFlinger.disableExpensiveRendering();