diff options
Diffstat (limited to 'libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.cpp')
-rw-r--r-- | libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.cpp | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.cpp b/libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.cpp index 368c41b..2108e96 100644 --- a/libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.cpp +++ b/libhwc2.1/libmaindisplay/ExynosPrimaryDisplay.cpp @@ -310,6 +310,9 @@ int32_t ExynosPrimaryDisplay::setPowerOff() { closeFencesForSkipFrame(RENDERING_STATE_VALIDATED); mRenderingState = RENDERING_STATE_NONE; + // in the case user turns off screen when LHBM is on + // TODO: b/236433238 considering a lock for mLhbmOn state + mLhbmOn = false; return HWC2_ERROR_NONE; } @@ -491,6 +494,9 @@ int32_t ExynosPrimaryDisplay::SetCurrentPanelGammaSource(const DisplayType type, } int32_t ExynosPrimaryDisplay::setLhbmState(bool enabled) { + // NOTE: mLhbmOn could be set to false at any time by setPowerOff in another + // thread. Make sure no side effect if that happens. Or add lock if we have + // to when new code is added. ATRACE_CALL(); if (enabled) { ATRACE_NAME("wait for peak refresh rate"); @@ -509,39 +515,50 @@ int32_t ExynosPrimaryDisplay::setLhbmState(bool enabled) { } requestLhbm(enabled); + constexpr uint32_t kSysfsCheckTimeoutMs = 500; ALOGI("setLhbmState =%d", enabled); + bool succeed = mBrightnessController->checkSysfsStatus( + BrightnessController::kLocalHbmModeFileNode, + std::to_string(enabled ? 1 : 0), + ms2ns(kSysfsCheckTimeoutMs)); + if (!succeed) { + ALOGE("failed to update lhbm mode"); + return -ENODEV; + } + + { + // lhbm takes effect at next vblank + ATRACE_NAME("lhbm_wait_apply"); + if (mDisplayInterface->waitVBlank()) { + ALOGE("%s failed to wait vblank", __func__); + return -ENODEV; + } + } - std::unique_lock<std::mutex> lk(lhbm_mutex_); - mLhbmChanged = false; - - if (!lhbm_cond_.wait_for(lk, std::chrono::milliseconds(1000), - [this] { return mLhbmChanged; })) { - ALOGI("setLhbmState =%d timeout !", enabled); - return TIMED_OUT; - } else { - if (enabled) { - mDisplayInterface->waitVBlank(); - ATRACE_NAME("frames to reach LHBM peak brightness"); - for (int32_t i = mFramesToReachLhbmPeakBrightness; i > 0; i--) { - mDevice->onRefresh(); - mDisplayInterface->waitVBlank(); + if (enabled) { + for (int32_t i = mFramesToReachLhbmPeakBrightness; i > 0; i--) { + ATRACE_NAME("lhbm_wait_peak_brightness"); + mDevice->onRefresh(); + if (mDisplayInterface->waitVBlank()) { + ALOGE("%s failed to wait vblank, %d", __func__, i); + return -ENODEV; } } - return NO_ERROR; } + + mLhbmOn = enabled; + if (mPowerModeState == HWC2_POWER_MODE_OFF && mLhbmOn) { + mLhbmOn = false; + ALOGE("%s power off during request lhbm on", __func__); + return -EINVAL; + } + return NO_ERROR; } bool ExynosPrimaryDisplay::getLhbmState() { return mLhbmOn; } -void ExynosPrimaryDisplay::notifyLhbmState(bool enabled) { - std::lock_guard<std::mutex> lk(lhbm_mutex_); - mLhbmChanged = true; - lhbm_cond_.notify_one(); - mLhbmOn = enabled; -} - void ExynosPrimaryDisplay::setEarlyWakeupDisplay() { if (mEarlyWakeupDispFd) { writeFileNode(mEarlyWakeupDispFd, 1); |