Skip to content

Commit 203b22a

Browse files
Dominik LaskowskiAndroid (Google) Code Review
authored andcommitted
Merge "Revert^2 "SF: Set an initial mode [...] for external displays"" into main
2 parents e2432b6 + ffb7d28 commit 203b22a

8 files changed

Lines changed: 18 additions & 178 deletions

File tree

services/surfaceflinger/Display/DisplayModeRequest.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ struct DisplayModeRequest {
2727

2828
// Whether to emit DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE.
2929
bool emitEvent = false;
30-
31-
// Whether to force the request to be applied, even if the mode is unchanged.
32-
bool force = false;
3330
};
3431

3532
inline bool operator==(const DisplayModeRequest& lhs, const DisplayModeRequest& rhs) {

services/surfaceflinger/DisplayDevice.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
2626

27-
#include <common/FlagManager.h>
2827
#include <compositionengine/CompositionEngine.h>
2928
#include <compositionengine/Display.h>
3029
#include <compositionengine/DisplayColorProfile.h>
@@ -215,17 +214,6 @@ void DisplayDevice::setActiveMode(DisplayModeId modeId, Fps vsyncRate, Fps rende
215214
bool DisplayDevice::initiateModeChange(display::DisplayModeRequest&& desiredMode,
216215
const hal::VsyncPeriodChangeConstraints& constraints,
217216
hal::VsyncPeriodChangeTimeline& outTimeline) {
218-
// TODO(b/255635711): Flow the DisplayModeRequest through the desired/pending/active states. For
219-
// now, `desiredMode` and `mDesiredModeOpt` are one and the same, but the latter is not cleared
220-
// until the next `SF::initiateDisplayModeChanges`. However, the desired mode has been consumed
221-
// at this point, so clear the `force` flag to prevent an endless loop of `initiateModeChange`.
222-
if (FlagManager::getInstance().connected_display()) {
223-
std::scoped_lock lock(mDesiredModeLock);
224-
if (mDesiredModeOpt) {
225-
mDesiredModeOpt->force = false;
226-
}
227-
}
228-
229217
mPendingModeOpt = std::move(desiredMode);
230218
mIsModeSetPending = true;
231219

@@ -529,34 +517,29 @@ void DisplayDevice::animateOverlay() {
529517
}
530518
}
531519

532-
auto DisplayDevice::setDesiredMode(display::DisplayModeRequest&& desiredMode) -> DesiredModeAction {
520+
auto DisplayDevice::setDesiredMode(display::DisplayModeRequest&& desiredMode, bool force)
521+
-> DesiredModeAction {
533522
ATRACE_CALL();
534523

535524
const auto& desiredModePtr = desiredMode.mode.modePtr;
536525

537526
LOG_ALWAYS_FATAL_IF(getPhysicalId() != desiredModePtr->getPhysicalDisplayId(),
538527
"DisplayId mismatch");
539528

540-
// TODO (b/318533819): Stringize DisplayModeRequest.
541-
ALOGD("%s(%s, force=%s)", __func__, to_string(*desiredModePtr).c_str(),
542-
desiredMode.force ? "true" : "false");
529+
ALOGV("%s(%s)", __func__, to_string(*desiredModePtr).c_str());
543530

544531
std::scoped_lock lock(mDesiredModeLock);
545532
if (mDesiredModeOpt) {
546533
// A mode transition was already scheduled, so just override the desired mode.
547534
const bool emitEvent = mDesiredModeOpt->emitEvent;
548-
const bool force = mDesiredModeOpt->force;
549535
mDesiredModeOpt = std::move(desiredMode);
550536
mDesiredModeOpt->emitEvent |= emitEvent;
551-
if (FlagManager::getInstance().connected_display()) {
552-
mDesiredModeOpt->force |= force;
553-
}
554537
return DesiredModeAction::None;
555538
}
556539

557540
// If the desired mode is already active...
558541
const auto activeMode = refreshRateSelector().getActiveMode();
559-
if (!desiredMode.force && activeMode.modePtr->getId() == desiredModePtr->getId()) {
542+
if (!force && activeMode.modePtr->getId() == desiredModePtr->getId()) {
560543
if (activeMode == desiredMode.mode) {
561544
return DesiredModeAction::None;
562545
}

services/surfaceflinger/DisplayDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ class DisplayDevice : public RefBase {
189189

190190
enum class DesiredModeAction { None, InitiateDisplayModeSwitch, InitiateRenderRateSwitch };
191191

192-
DesiredModeAction setDesiredMode(display::DisplayModeRequest&&) EXCLUDES(mDesiredModeLock);
192+
DesiredModeAction setDesiredMode(display::DisplayModeRequest&&, bool force = false)
193+
EXCLUDES(mDesiredModeLock);
193194

194195
using DisplayModeRequestOpt = ftl::Optional<display::DisplayModeRequest>;
195196

services/surfaceflinger/DisplayHardware/HWC2.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "HWC2.h"
2828

2929
#include <android/configuration.h>
30-
#include <common/FlagManager.h>
3130
#include <ui/Fence.h>
3231
#include <ui/FloatRect.h>
3332
#include <ui/GraphicBuffer.h>
@@ -417,19 +416,7 @@ Error Display::setActiveConfigWithConstraints(hal::HWConfigId configId,
417416
VsyncPeriodChangeTimeline* outTimeline) {
418417
ALOGV("[%" PRIu64 "] setActiveConfigWithConstraints", mId);
419418

420-
// FIXME (b/319505580): At least the first config set on an external display must be
421-
// `setActiveConfig`, so skip over the block that calls `setActiveConfigWithConstraints`
422-
// for simplicity.
423-
ui::DisplayConnectionType type = ui::DisplayConnectionType::Internal;
424-
const bool connected_display = FlagManager::getInstance().connected_display();
425-
if (connected_display) {
426-
if (auto err = getConnectionType(&type); err != Error::NONE) {
427-
return err;
428-
}
429-
}
430-
431-
if (isVsyncPeriodSwitchSupported() &&
432-
(!connected_display || type != ui::DisplayConnectionType::External)) {
419+
if (isVsyncPeriodSwitchSupported()) {
433420
Hwc2::IComposerClient::VsyncPeriodChangeConstraints hwc2Constraints;
434421
hwc2Constraints.desiredTimeNanos = constraints.desiredTimeNanos;
435422
hwc2Constraints.seamlessRequired = constraints.seamlessRequired;

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 8 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -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

37663664
void 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)) {

services/surfaceflinger/SurfaceFlinger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ class SurfaceFlinger : public BnSurfaceComposer,
716716
// Show hdr sdr ratio overlay
717717
bool mHdrSdrRatioOverlay = false;
718718

719-
void setDesiredMode(display::DisplayModeRequest&&) REQUIRES(mStateLock);
719+
void setDesiredMode(display::DisplayModeRequest&&, bool force = false) REQUIRES(mStateLock);
720720

721721
status_t setActiveModeFromBackdoor(const sp<display::DisplayToken>&, DisplayModeId, Fps minFps,
722722
Fps maxFps);

services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,9 @@ struct HwcDisplayVariant {
461461
? IComposerClient::DisplayConnectionType::INTERNAL
462462
: IComposerClient::DisplayConnectionType::EXTERNAL;
463463

464-
using ::testing::AtLeast;
465464
EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _))
466-
.Times(AtLeast(1))
467-
.WillRepeatedly(DoAll(SetArgPointee<1>(CONNECTION_TYPE),
468-
Return(hal::V2_4::Error::NONE)));
465+
.WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE),
466+
Return(hal::V2_4::Error::NONE)));
469467
}
470468

471469
EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_))

services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@
2121
#include "mock/DisplayHardware/MockDisplayMode.h"
2222
#include "mock/MockDisplayModeSpecs.h"
2323

24-
#include <com_android_graphics_surfaceflinger_flags.h>
25-
#include <common/test/FlagUtils.h>
2624
#include <ftl/fake_guard.h>
2725
#include <scheduler/Fps.h>
2826

29-
using namespace com::android::graphics::surfaceflinger;
30-
3127
#define EXPECT_SET_ACTIVE_CONFIG(displayId, modeId) \
3228
EXPECT_CALL(*mComposer, \
3329
setActiveConfigWithConstraints(displayId, \
@@ -353,13 +349,6 @@ MATCHER_P(ModeSettledTo, modeId, "") {
353349
}
354350

355351
TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) {
356-
SET_FLAG_FOR_TEST(flags::connected_display, true);
357-
358-
// For the inner display, this is handled by setupHwcHotplugCallExpectations.
359-
EXPECT_CALL(*mComposer, getDisplayConnectionType(kOuterDisplayHwcId, _))
360-
.WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::INTERNAL),
361-
Return(hal::V2_4::Error::NONE)));
362-
363352
const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
364353

365354
EXPECT_TRUE(innerDisplay->isPoweredOn());
@@ -423,12 +412,6 @@ TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) {
423412
}
424413

425414
TEST_F(DisplayModeSwitchingTest, innerAndOuterDisplay) {
426-
SET_FLAG_FOR_TEST(flags::connected_display, true);
427-
428-
// For the inner display, this is handled by setupHwcHotplugCallExpectations.
429-
EXPECT_CALL(*mComposer, getDisplayConnectionType(kOuterDisplayHwcId, _))
430-
.WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::INTERNAL),
431-
Return(hal::V2_4::Error::NONE)));
432415
const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
433416

434417
EXPECT_TRUE(innerDisplay->isPoweredOn());
@@ -502,13 +485,6 @@ TEST_F(DisplayModeSwitchingTest, powerOffDuringModeSet) {
502485
}
503486

504487
TEST_F(DisplayModeSwitchingTest, powerOffDuringConcurrentModeSet) {
505-
SET_FLAG_FOR_TEST(flags::connected_display, true);
506-
507-
// For the inner display, this is handled by setupHwcHotplugCallExpectations.
508-
EXPECT_CALL(*mComposer, getDisplayConnectionType(kOuterDisplayHwcId, _))
509-
.WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::INTERNAL),
510-
Return(hal::V2_4::Error::NONE)));
511-
512488
const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
513489

514490
EXPECT_TRUE(innerDisplay->isPoweredOn());

0 commit comments

Comments
 (0)