@@ -3660,6 +3660,26 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
36603660 return display;
36613661}
36623662
3663+ void SurfaceFlinger::incRefreshableDisplays () {
3664+ if (FlagManager::getInstance ().no_vsyncs_on_screen_off ()) {
3665+ mRefreshableDisplays ++;
3666+ if (mRefreshableDisplays == 1 ) {
3667+ ftl::FakeGuard guard (kMainThreadContext );
3668+ mScheduler ->omitVsyncDispatching (false );
3669+ }
3670+ }
3671+ }
3672+
3673+ void SurfaceFlinger::decRefreshableDisplays () {
3674+ if (FlagManager::getInstance ().no_vsyncs_on_screen_off ()) {
3675+ mRefreshableDisplays --;
3676+ if (mRefreshableDisplays == 0 ) {
3677+ ftl::FakeGuard guard (kMainThreadContext );
3678+ mScheduler ->omitVsyncDispatching (true );
3679+ }
3680+ }
3681+ }
3682+
36633683void SurfaceFlinger::processDisplayAdded (const wp<IBinder>& displayToken,
36643684 const DisplayDeviceState& state) {
36653685 ui::Size resolution (0 , 0 );
@@ -3751,6 +3771,10 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken,
37513771 display->adjustRefreshRate (mScheduler ->getPacesetterRefreshRate ());
37523772 }
37533773
3774+ if (display->isRefreshable ()) {
3775+ incRefreshableDisplays ();
3776+ }
3777+
37543778 mDisplays .try_emplace (displayToken, std::move (display));
37553779
37563780 // For an external display, loadDisplayModes already attempted to select the same mode
@@ -3785,6 +3809,10 @@ void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) {
37853809 } else {
37863810 mScheduler ->unregisterDisplay (display->getPhysicalId (), mActiveDisplayId );
37873811 }
3812+
3813+ if (display->isRefreshable ()) {
3814+ decRefreshableDisplays ();
3815+ }
37883816 }
37893817
37903818 mDisplays .erase (displayToken);
@@ -3819,6 +3847,10 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken,
38193847 if (display->isVirtual ()) {
38203848 releaseVirtualDisplay (display->getVirtualId ());
38213849 }
3850+
3851+ if (display->isRefreshable ()) {
3852+ decRefreshableDisplays ();
3853+ }
38223854 }
38233855
38243856 mDisplays .erase (displayToken);
@@ -5317,7 +5349,15 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
53175349 activeDisplay->isPoweredOn (),
53185350 " Trying to change power mode on inactive display without powering off active display" );
53195351
5352+ const bool couldRefresh = display->isRefreshable ();
53205353 display->setPowerMode (mode);
5354+ const bool canRefresh = display->isRefreshable ();
5355+
5356+ if (couldRefresh && !canRefresh) {
5357+ decRefreshableDisplays ();
5358+ } else if (!couldRefresh && canRefresh) {
5359+ incRefreshableDisplays ();
5360+ }
53215361
53225362 const auto activeMode = display->refreshRateSelector ().getActiveMode ().modePtr ;
53235363 if (currentMode == hal::PowerMode::OFF) {
0 commit comments