@@ -3665,6 +3665,26 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
36653665 return display;
36663666}
36673667
3668+ void SurfaceFlinger::incRefreshableDisplays () {
3669+ if (FlagManager::getInstance ().no_vsyncs_on_screen_off ()) {
3670+ mRefreshableDisplays ++;
3671+ if (mRefreshableDisplays == 1 ) {
3672+ ftl::FakeGuard guard (kMainThreadContext );
3673+ mScheduler ->omitVsyncDispatching (false );
3674+ }
3675+ }
3676+ }
3677+
3678+ void SurfaceFlinger::decRefreshableDisplays () {
3679+ if (FlagManager::getInstance ().no_vsyncs_on_screen_off ()) {
3680+ mRefreshableDisplays --;
3681+ if (mRefreshableDisplays == 0 ) {
3682+ ftl::FakeGuard guard (kMainThreadContext );
3683+ mScheduler ->omitVsyncDispatching (true );
3684+ }
3685+ }
3686+ }
3687+
36683688void SurfaceFlinger::processDisplayAdded (const wp<IBinder>& displayToken,
36693689 const DisplayDeviceState& state) {
36703690 ui::Size resolution (0 , 0 );
@@ -3756,6 +3776,10 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken,
37563776 display->adjustRefreshRate (mScheduler ->getPacesetterRefreshRate ());
37573777 }
37583778
3779+ if (display->isRefreshable ()) {
3780+ incRefreshableDisplays ();
3781+ }
3782+
37593783 mDisplays .try_emplace (displayToken, std::move (display));
37603784
37613785 // For an external display, loadDisplayModes already attempted to select the same mode
@@ -3790,6 +3814,10 @@ void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) {
37903814 } else {
37913815 mScheduler ->unregisterDisplay (display->getPhysicalId (), mActiveDisplayId );
37923816 }
3817+
3818+ if (display->isRefreshable ()) {
3819+ decRefreshableDisplays ();
3820+ }
37933821 }
37943822
37953823 mDisplays .erase (displayToken);
@@ -3824,6 +3852,10 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken,
38243852 if (display->isVirtual ()) {
38253853 releaseVirtualDisplay (display->getVirtualId ());
38263854 }
3855+
3856+ if (display->isRefreshable ()) {
3857+ decRefreshableDisplays ();
3858+ }
38273859 }
38283860
38293861 mDisplays .erase (displayToken);
@@ -5322,7 +5354,15 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
53225354 activeDisplay->isPoweredOn (),
53235355 " Trying to change power mode on inactive display without powering off active display" );
53245356
5357+ const bool couldRefresh = display->isRefreshable ();
53255358 display->setPowerMode (mode);
5359+ const bool canRefresh = display->isRefreshable ();
5360+
5361+ if (couldRefresh && !canRefresh) {
5362+ decRefreshableDisplays ();
5363+ } else if (!couldRefresh && canRefresh) {
5364+ incRefreshableDisplays ();
5365+ }
53265366
53275367 const auto activeMode = display->refreshRateSelector ().getActiveMode ().modePtr ;
53285368 if (currentMode == hal::PowerMode::OFF) {
0 commit comments