@@ -1230,10 +1230,8 @@ status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken,
12301230 return NO_ERROR;
12311231}
12321232
1233- void SurfaceFlinger::setDesiredMode (display::DisplayModeRequest&& desiredMode) {
1234- const auto mode = desiredMode.mode ;
1235- const auto displayId = mode.modePtr ->getPhysicalDisplayId ();
1236-
1233+ void SurfaceFlinger::setDesiredMode (display::DisplayModeRequest&& request, bool force) {
1234+ const auto displayId = request.mode .modePtr ->getPhysicalDisplayId ();
12371235 ATRACE_NAME (ftl::Concat (__func__, ' ' , displayId.value ).c_str ());
12381236
12391237 const auto display = getDisplayDeviceLocked (displayId);
@@ -1242,9 +1240,10 @@ void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) {
12421240 return ;
12431241 }
12441242
1245- const bool emitEvent = desiredMode.emitEvent ;
1243+ const auto mode = request.mode ;
1244+ const bool emitEvent = request.emitEvent ;
12461245
1247- switch (display->setDesiredMode (std::move (desiredMode) )) {
1246+ switch (display->setDesiredMode (std::move (request), force )) {
12481247 case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch:
12491248 // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler.
12501249 mScheduler ->setRenderRate (displayId,
@@ -1430,8 +1429,7 @@ void SurfaceFlinger::initiateDisplayModeChanges() {
14301429 to_string (displayModePtrOpt->get ()->getVsyncRate ()).c_str (),
14311430 to_string (display->getId ()).c_str ());
14321431
1433- if ((!FlagManager::getInstance ().connected_display () || !desiredModeOpt->force ) &&
1434- display->getActiveMode () == desiredModeOpt->mode ) {
1432+ if (display->getActiveMode () == desiredModeOpt->mode ) {
14351433 applyActiveMode (display);
14361434 continue ;
14371435 }
@@ -3286,88 +3284,13 @@ std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes(
32863284 std::vector<HWComposer::HWCDisplayMode> hwcModes;
32873285 std::optional<hal::HWConfigId> activeModeHwcIdOpt;
32883286
3289- const bool isExternalDisplay = FlagManager::getInstance ().connected_display () &&
3290- getHwComposer ().getDisplayConnectionType (displayId) ==
3291- ui::DisplayConnectionType::External;
3292-
32933287 int attempt = 0 ;
32943288 constexpr int kMaxAttempts = 3 ;
32953289 do {
32963290 hwcModes = getHwComposer ().getModes (displayId,
32973291 scheduler::RefreshRateSelector::kMinSupportedFrameRate
32983292 .getPeriodNsecs ());
3299- const auto activeModeHwcIdExp = getHwComposer ().getActiveMode (displayId);
3300- activeModeHwcIdOpt = activeModeHwcIdExp.value_opt ();
3301-
3302- if (isExternalDisplay &&
3303- activeModeHwcIdExp.has_error ([](status_t error) { return error == NO_INIT; })) {
3304- constexpr nsecs_t k59HzVsyncPeriod = 16949153 ;
3305- constexpr nsecs_t k60HzVsyncPeriod = 16666667 ;
3306-
3307- // DM sets the initial mode for an external display to 1080p@60, but
3308- // this comes after SF creates its own state (including the
3309- // DisplayDevice). For now, pick the same mode in order to avoid
3310- // inconsistent state and unnecessary mode switching.
3311- // TODO (b/318534874): Let DM decide the initial mode.
3312- //
3313- // Try to find 1920x1080 @ 60 Hz
3314- if (const auto iter = std::find_if (hwcModes.begin (), hwcModes.end (),
3315- [](const auto & mode) {
3316- return mode.width == 1920 &&
3317- mode.height == 1080 &&
3318- mode.vsyncPeriod == k60HzVsyncPeriod;
3319- });
3320- iter != hwcModes.end ()) {
3321- activeModeHwcIdOpt = iter->hwcId ;
3322- break ;
3323- }
3324-
3325- // Try to find 1920x1080 @ 59-60 Hz
3326- if (const auto iter = std::find_if (hwcModes.begin (), hwcModes.end (),
3327- [](const auto & mode) {
3328- return mode.width == 1920 &&
3329- mode.height == 1080 &&
3330- mode.vsyncPeriod >= k60HzVsyncPeriod &&
3331- mode.vsyncPeriod <= k59HzVsyncPeriod;
3332- });
3333- iter != hwcModes.end ()) {
3334- activeModeHwcIdOpt = iter->hwcId ;
3335- break ;
3336- }
3337-
3338- // The display does not support 1080p@60, and this is the last attempt to pick a display
3339- // mode. Prefer 60 Hz if available, with the closest resolution to 1080p.
3340- if (attempt + 1 == kMaxAttempts ) {
3341- std::vector<HWComposer::HWCDisplayMode> hwcModeOpts;
3342-
3343- for (const auto & mode : hwcModes) {
3344- if (mode.width <= 1920 && mode.height <= 1080 &&
3345- mode.vsyncPeriod >= k60HzVsyncPeriod &&
3346- mode.vsyncPeriod <= k59HzVsyncPeriod) {
3347- hwcModeOpts.push_back (mode);
3348- }
3349- }
3350-
3351- if (const auto iter = std::max_element (hwcModeOpts.begin (), hwcModeOpts.end (),
3352- [](const auto & a, const auto & b) {
3353- const auto aSize = a.width * a.height ;
3354- const auto bSize = b.width * b.height ;
3355- if (aSize < bSize)
3356- return true ;
3357- else if (aSize == bSize)
3358- return a.vsyncPeriod > b.vsyncPeriod ;
3359- else
3360- return false ;
3361- });
3362- iter != hwcModeOpts.end ()) {
3363- activeModeHwcIdOpt = iter->hwcId ;
3364- break ;
3365- }
3366-
3367- // hwcModeOpts was empty, use hwcModes[0] as the last resort
3368- activeModeHwcIdOpt = hwcModes[0 ].hwcId ;
3369- }
3370- }
3293+ activeModeHwcIdOpt = getHwComposer ().getActiveMode (displayId).value_opt ();
33713294
33723295 const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) {
33733296 return mode.hwcId == activeModeHwcIdOpt;
@@ -3428,10 +3351,6 @@ std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes(
34283351 return pair.second ->getHwcId () == activeModeHwcIdOpt;
34293352 })->second ;
34303353
3431- if (isExternalDisplay) {
3432- ALOGI (" External display %s initial mode: {%s}" , to_string (displayId).c_str (),
3433- to_string (*activeMode).c_str ());
3434- }
34353354 return {modes, activeMode};
34363355}
34373356
@@ -3740,27 +3659,6 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken,
37403659 }
37413660
37423661 mDisplays .try_emplace (displayToken, std::move (display));
3743-
3744- // For an external display, loadDisplayModes already attempted to select the same mode
3745- // as DM, but SF still needs to be updated to match.
3746- // TODO (b/318534874): Let DM decide the initial mode.
3747- if (const auto & physical = state.physical ;
3748- mScheduler && physical && FlagManager::getInstance ().connected_display ()) {
3749- const bool isInternalDisplay = mPhysicalDisplays .get (physical->id )
3750- .transform (&PhysicalDisplay::isInternal)
3751- .value_or (false );
3752-
3753- if (!isInternalDisplay) {
3754- auto activeModePtr = physical->activeMode ;
3755- const auto fps = activeModePtr->getPeakFps ();
3756-
3757- setDesiredMode (
3758- {.mode = scheduler::FrameRateMode{fps,
3759- ftl::as_non_null (std::move (activeModePtr))},
3760- .emitEvent = false ,
3761- .force = true });
3762- }
3763- }
37643662}
37653663
37663664void SurfaceFlinger::processDisplayRemoved (const wp<IBinder>& displayToken) {
@@ -8485,7 +8383,7 @@ status_t SurfaceFlinger::applyRefreshRateSelectorPolicy(
84858383 return INVALID_OPERATION;
84868384 }
84878385
8488- setDesiredMode ({std::move (preferredMode), .emitEvent = true , . force = force} );
8386+ setDesiredMode ({std::move (preferredMode), .emitEvent = true }, force);
84898387
84908388 // Update the frameRateOverride list as the display render rate might have changed
84918389 if (mScheduler ->updateFrameRateOverrides (scheduler::GlobalSignals{}, preferredFps)) {
0 commit comments