@@ -591,6 +591,8 @@ sp<IBinder> SurfaceFlinger::createVirtualDisplay(
591591 return nullptr ;
592592 }
593593
594+ ALOGD (" Creating virtual display: %s" , displayName.c_str ());
595+
594596 class DisplayToken : public BBinder {
595597 sp<SurfaceFlinger> flinger;
596598 virtual ~DisplayToken () {
@@ -615,6 +617,8 @@ sp<IBinder> SurfaceFlinger::createVirtualDisplay(
615617 // TODO (b/314820005): separate as a different arg when creating the display.
616618 state.isProtected = isSecure;
617619 state.optimizationPolicy = optimizationPolicy;
620+ // Virtual displays start in ON mode.
621+ state.initialPowerMode = hal::PowerMode::ON;
618622 state.displayName = displayName;
619623 state.uniqueId = uniqueId;
620624 state.requestedRefreshRate = Fps::fromValue (requestedRefreshRate);
@@ -636,6 +640,9 @@ status_t SurfaceFlinger::destroyVirtualDisplay(const sp<IBinder>& displayToken)
636640 ALOGE (" %s: Invalid operation on physical display" , __func__);
637641 return INVALID_OPERATION;
638642 }
643+
644+ ALOGD (" Destroying virtual display: %s" , state.displayName .c_str ());
645+
639646 mCurrentState .displays .removeItemsAt (index);
640647 setTransactionFlags (eDisplayTransactionNeeded);
641648 return NO_ERROR;
@@ -3913,7 +3920,12 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
39133920 getPhysicalDisplayOrientation (compositionDisplay->getId (), creationArgs.isPrimary );
39143921 ALOGV (" Display Orientation: %s" , toCString (creationArgs.physicalOrientation ));
39153922
3916- creationArgs.initialPowerMode = state.isVirtual () ? hal::PowerMode::ON : hal::PowerMode::OFF;
3923+ if (FlagManager::getInstance ().correct_virtual_display_power_state ()) {
3924+ creationArgs.initialPowerMode = state.initialPowerMode ;
3925+ } else {
3926+ creationArgs.initialPowerMode =
3927+ state.isVirtual () ? hal::PowerMode::ON : hal::PowerMode::OFF;
3928+ }
39173929
39183930 creationArgs.requestedRefreshRate = state.requestedRefreshRate ;
39193931
@@ -3987,6 +3999,8 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken,
39873999 // Virtual displays without a surface are dormant:
39884000 // they have external state (layer stack, projection,
39894001 // etc.) but no internal state (i.e. a DisplayDevice).
4002+ ALOGD (" Not adding dormant virtual display with token %p: %s" , displayToken.unsafe_get (),
4003+ state.displayName .c_str ());
39904004 return ;
39914005 }
39924006
@@ -5806,16 +5820,32 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:
58065820}
58075821
58085822void SurfaceFlinger::setPowerMode (const sp<IBinder>& displayToken, int mode) {
5809- auto future = mScheduler ->schedule ([=, this ]() FTL_FAKE_GUARD (mStateLock ) FTL_FAKE_GUARD (
5810- kMainThreadContext ) {
5823+ auto future = mScheduler ->schedule ([=, this ]() FTL_FAKE_GUARD (kMainThreadContext ) {
58115824 mSkipPowerOnForQuiescent = false ;
5812- const auto display = getDisplayDeviceLocked (displayToken);
5825+ const auto display = FTL_FAKE_GUARD ( mStateLock , getDisplayDeviceLocked (displayToken) );
58135826 if (!display) {
5814- ALOGE (" Attempt to set power mode %d for invalid display token %p" , mode,
5815- displayToken.get ());
5827+ Mutex::Autolock lock (mStateLock );
5828+ const ssize_t index = mCurrentState .displays .indexOfKey (displayToken);
5829+ if (index >= 0 ) {
5830+ auto & state = mCurrentState .displays .editValueFor (displayToken);
5831+ if (state.isVirtual ()) {
5832+ ALOGD (" Setting power mode %d for a dormant virtual display with token %p" , mode,
5833+ displayToken.get ());
5834+ state.initialPowerMode = static_cast <hal::PowerMode>(mode);
5835+ return ;
5836+ }
5837+ }
5838+ ALOGE (" Failed to set power mode %d for display token %p" , mode, displayToken.get ());
58165839 } else if (display->isVirtual ()) {
5817- ALOGW (" Attempt to set power mode %d for virtual display" , mode);
5840+ if (FlagManager::getInstance ().correct_virtual_display_power_state ()) {
5841+ ALOGD (" Setting power mode %d on virtual display %s" , mode,
5842+ display->getDisplayName ().c_str ());
5843+ display->setPowerMode (static_cast <hal::PowerMode>(mode));
5844+ } else {
5845+ ALOGW (" Attempt to set power mode %d for virtual display" , mode);
5846+ }
58185847 } else {
5848+ ftl::FakeGuard guard (mStateLock );
58195849 setPowerModeInternal (display, static_cast <hal::PowerMode>(mode));
58205850 }
58215851 });
0 commit comments