Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de5241e5 authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Android (Google) Code Review
Browse files

Merge changes I381e5528,Ie4c90d95 into main

* changes:
  SF: Clean up DisplayDevice::initiateModeChange
  SF: Check if mode exists in onKernelTimerChanged
parents 6446c81b 4b32e4bc
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -217,9 +217,9 @@ void DisplayDevice::setActiveMode(DisplayModeId modeId, Fps vsyncRate, Fps rende
    updateRefreshRateOverlayRate(vsyncRate, renderFps);
}

status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
bool DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
                                       const hal::VsyncPeriodChangeConstraints& constraints,
                                           hal::VsyncPeriodChangeTimeline* outTimeline) {
                                       hal::VsyncPeriodChangeTimeline& outTimeline) {
    if (!info.modeOpt || info.modeOpt->modePtr->getPhysicalDisplayId() != getPhysicalId()) {
        ALOGE("Trying to initiate a mode change to invalid mode %s on display %s",
              info.modeOpt ? std::to_string(info.modeOpt->modePtr->getId().value()).c_str()
@@ -230,11 +230,15 @@ status_t DisplayDevice::initiateModeChange(const ActiveModeInfo& info,
    mPendingMode = info;
    mIsModeSetPending = true;

    const auto& pendingMode = *info.modeOpt->modePtr;
    ATRACE_INT(mPendingModeFpsTrace.c_str(), pendingMode.getVsyncRate().getIntValue());
    const auto& mode = *info.modeOpt->modePtr;

    return mHwComposer.setActiveModeWithConstraints(getPhysicalId(), pendingMode.getHwcId(),
                                                    constraints, outTimeline);
    if (mHwComposer.setActiveModeWithConstraints(getPhysicalId(), mode.getHwcId(), constraints,
                                                 &outTimeline) != OK) {
        return false;
    }

    ATRACE_INT(mPendingModeFpsTrace.c_str(), mode.getVsyncRate().getIntValue());
    return true;
}

void DisplayDevice::finalizeModeChange(DisplayModeId modeId, Fps vsyncRate, Fps renderFps) {
+2 −3
Original line number Diff line number Diff line
@@ -223,9 +223,8 @@ public:

    void setActiveMode(DisplayModeId, Fps vsyncRate, Fps renderFps);

    status_t initiateModeChange(const ActiveModeInfo&,
                                const hal::VsyncPeriodChangeConstraints& constraints,
                                hal::VsyncPeriodChangeTimeline* outTimeline)
    bool initiateModeChange(const ActiveModeInfo&, const hal::VsyncPeriodChangeConstraints&,
                            hal::VsyncPeriodChangeTimeline& outTimeline)
            REQUIRES(kMainThreadContext);

    void finalizeModeChange(DisplayModeId, Fps vsyncRate, Fps renderFps)
+12 −8
Original line number Diff line number Diff line
@@ -973,14 +973,18 @@ ftl::Optional<FrameRateMode> RefreshRateSelector::onKernelTimerChanged(
        ftl::Optional<DisplayModeId> desiredModeIdOpt, bool timerExpired) const {
    std::lock_guard lock(mLock);

    const auto current = [&]() REQUIRES(mLock) -> FrameRateMode {
        if (desiredModeIdOpt) {
            const auto& modePtr = mDisplayModes.get(*desiredModeIdOpt)->get();
    const auto current =
            desiredModeIdOpt
                    .and_then([this](DisplayModeId modeId)
                                      REQUIRES(mLock) { return mDisplayModes.get(modeId); })
                    .transform([](const DisplayModePtr& modePtr) {
                        return FrameRateMode{modePtr->getPeakFps(), ftl::as_non_null(modePtr)};
        }

        return getActiveModeLocked();
    }();
                    })
                    .or_else([this] {
                        ftl::FakeGuard guard(mLock);
                        return std::make_optional(getActiveModeLocked());
                    })
                    .value();

    const DisplayModePtr& min = mMinRefreshRateModeIt->second;
    if (current.modePtr->getId() == min->getId()) {
+1 −5
Original line number Diff line number Diff line
@@ -1397,11 +1397,7 @@ void SurfaceFlinger::initiateDisplayModeChanges() {
        constraints.seamlessRequired = false;
        hal::VsyncPeriodChangeTimeline outTimeline;

        const auto status = display->initiateModeChange(*desiredModeOpt, constraints, &outTimeline);
        if (status != NO_ERROR) {
            // initiateModeChange may fail if a hotplug event is just about
            // to be sent. We just log the error in this case.
            ALOGW("initiateModeChange failed: %d", status);
        if (!display->initiateModeChange(*desiredModeOpt, constraints, outTimeline)) {
            continue;
        }

+5 −8
Original line number Diff line number Diff line
@@ -103,13 +103,12 @@ TEST_F(InitiateModeChangeTest, initiateModeChange) REQUIRES(kMainThreadContext)
    EXPECT_FRAME_RATE_MODE(kMode90, 90_Hz, *mDisplay->getDesiredMode()->modeOpt);
    EXPECT_EQ(Event::None, mDisplay->getDesiredMode()->event);

    hal::VsyncPeriodChangeConstraints constraints{
    const hal::VsyncPeriodChangeConstraints constraints{
            .desiredTimeNanos = systemTime(),
            .seamlessRequired = false,
    };
    hal::VsyncPeriodChangeTimeline timeline;
    EXPECT_EQ(OK,
              mDisplay->initiateModeChange(*mDisplay->getDesiredMode(), constraints, &timeline));
    EXPECT_TRUE(mDisplay->initiateModeChange(*mDisplay->getDesiredMode(), constraints, timeline));
    EXPECT_FRAME_RATE_MODE(kMode90, 90_Hz, *mDisplay->getPendingMode().modeOpt);
    EXPECT_EQ(Event::None, mDisplay->getPendingMode().event);

@@ -130,13 +129,12 @@ TEST_F(InitiateModeChangeTest, initiateDisplayModeSwitch) FTL_FAKE_GUARD(kMainTh
    EXPECT_FRAME_RATE_MODE(kMode90, 90_Hz, *mDisplay->getDesiredMode()->modeOpt);
    EXPECT_EQ(Event::None, mDisplay->getDesiredMode()->event);

    hal::VsyncPeriodChangeConstraints constraints{
    const hal::VsyncPeriodChangeConstraints constraints{
            .desiredTimeNanos = systemTime(),
            .seamlessRequired = false,
    };
    hal::VsyncPeriodChangeTimeline timeline;
    EXPECT_EQ(OK,
              mDisplay->initiateModeChange(*mDisplay->getDesiredMode(), constraints, &timeline));
    EXPECT_TRUE(mDisplay->initiateModeChange(*mDisplay->getDesiredMode(), constraints, timeline));
    EXPECT_FRAME_RATE_MODE(kMode90, 90_Hz, *mDisplay->getPendingMode().modeOpt);
    EXPECT_EQ(Event::None, mDisplay->getPendingMode().event);

@@ -149,8 +147,7 @@ TEST_F(InitiateModeChangeTest, initiateDisplayModeSwitch) FTL_FAKE_GUARD(kMainTh
    EXPECT_FRAME_RATE_MODE(kMode90, 90_Hz, *mDisplay->getPendingMode().modeOpt);
    EXPECT_EQ(Event::None, mDisplay->getPendingMode().event);

    EXPECT_EQ(OK,
              mDisplay->initiateModeChange(*mDisplay->getDesiredMode(), constraints, &timeline));
    EXPECT_TRUE(mDisplay->initiateModeChange(*mDisplay->getDesiredMode(), constraints, timeline));
    EXPECT_FRAME_RATE_MODE(kMode120, 120_Hz, *mDisplay->getPendingMode().modeOpt);
    EXPECT_EQ(Event::None, mDisplay->getPendingMode().event);