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

Commit bda5236d authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Merge on{,Non}PrimaryDisplayModeChanged

Branch on the pacesetter rather than active display, though they are the
same display in practice for now.

Bug: 255635821
Flag: EXEMPT refactor
Test: presubmit
Change-Id: I40d73e79075893826492b85c27e35eed59b4b289
parent fc94b41a
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -424,8 +424,12 @@ void Scheduler::onHdcpLevelsChanged(Cycle cycle, PhysicalDisplayId displayId,
    eventThreadFor(cycle).onHdcpLevelsChanged(displayId, connectedLevel, maxLevel);
}

void Scheduler::onPrimaryDisplayModeChanged(const FrameRateMode& mode) {
    {
bool Scheduler::onDisplayModeChanged(PhysicalDisplayId displayId, const FrameRateMode& mode) {
    const bool isPacesetter =
            FTL_FAKE_GUARD(kMainThreadContext,
                           (std::scoped_lock(mDisplayLock), displayId == mPacesetterDisplayId));

    if (isPacesetter) {
        std::lock_guard<std::mutex> lock(mPolicyLock);
        mPolicy.emittedModeOpt = mode;

@@ -433,7 +437,12 @@ void Scheduler::onPrimaryDisplayModeChanged(const FrameRateMode& mode) {
        // again for the new refresh rate.
        mPolicy.contentRequirements.clear();
    }
    onNonPrimaryDisplayModeChanged(mode);

    if (hasEventThreads()) {
        eventThreadFor(Cycle::Render).onModeChanged(mode);
    }

    return isPacesetter;
}

void Scheduler::emitModeChangeIfNeeded() {
@@ -455,10 +464,7 @@ void Scheduler::emitModeChangeIfNeeded() {
    }

    mPolicy.emittedModeOpt = mode;
    onNonPrimaryDisplayModeChanged(mode);
}

void Scheduler::onNonPrimaryDisplayModeChanged(const FrameRateMode& mode) {
    if (hasEventThreads()) {
        eventThreadFor(Cycle::Render).onModeChanged(mode);
    }
+2 −2
Original line number Diff line number Diff line
@@ -154,8 +154,8 @@ public:

    void dispatchHotplugError(int32_t errorCode);

    void onPrimaryDisplayModeChanged(const FrameRateMode&) EXCLUDES(mPolicyLock);
    void onNonPrimaryDisplayModeChanged(const FrameRateMode&);
    // Returns true if the PhysicalDisplayId is the pacesetter.
    bool onDisplayModeChanged(PhysicalDisplayId, const FrameRateMode&) EXCLUDES(mPolicyLock);

    void enableSyntheticVsync(bool = true) REQUIRES(kMainThreadContext);

+4 −18
Original line number Diff line number Diff line
@@ -1358,7 +1358,7 @@ void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) {
            }

            if (emitEvent) {
                dispatchDisplayModeChangeEvent(displayId, mode);
                mScheduler->onDisplayModeChanged(displayId, mode);
            }
            break;
        case DesiredModeAction::None:
@@ -1455,7 +1455,7 @@ void SurfaceFlinger::finalizeDisplayModeChange(PhysicalDisplayId displayId) {
    }

    if (pendingModeOpt->emitEvent) {
        dispatchDisplayModeChangeEvent(displayId, activeMode);
        mScheduler->onDisplayModeChanged(displayId, activeMode);
    }
}

@@ -3589,16 +3589,6 @@ void SurfaceFlinger::processHotplugDisconnect(PhysicalDisplayId displayId,
    mPhysicalDisplays.erase(displayId);
}

void SurfaceFlinger::dispatchDisplayModeChangeEvent(PhysicalDisplayId displayId,
                                                    const scheduler::FrameRateMode& mode) {
    // TODO(b/255635821): Merge code paths and move to Scheduler.
    const auto onDisplayModeChanged = displayId == mActiveDisplayId
            ? &scheduler::Scheduler::onPrimaryDisplayModeChanged
            : &scheduler::Scheduler::onNonPrimaryDisplayModeChanged;

    ((*mScheduler).*onDisplayModeChanged)(mode);
}

sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
        const wp<IBinder>& displayToken,
        std::shared_ptr<compositionengine::Display> compositionDisplay,
@@ -7959,13 +7949,9 @@ status_t SurfaceFlinger::applyRefreshRateSelectorPolicy(
    const scheduler::RefreshRateSelector::Policy currentPolicy = selector.getCurrentPolicy();
    ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str());

    // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might
    // be depending in this callback.
    if (const auto activeMode = selector.getActiveMode(); displayId == mActiveDisplayId) {
        mScheduler->onPrimaryDisplayModeChanged(activeMode);
    if (const bool isPacesetter =
                mScheduler->onDisplayModeChanged(displayId, selector.getActiveMode())) {
        toggleKernelIdleTimer();
    } else {
        mScheduler->onNonPrimaryDisplayModeChanged(activeMode);
    }

    auto preferredModeOpt = getPreferredDisplayMode(displayId, currentPolicy.defaultMode);
+0 −2
Original line number Diff line number Diff line
@@ -1067,8 +1067,6 @@ private:
                               const DisplayDeviceState& drawingState)
            REQUIRES(mStateLock, kMainThreadContext);

    void dispatchDisplayModeChangeEvent(PhysicalDisplayId, const scheduler::FrameRateMode&);

    /*
     * VSYNC
     */
+2 −2
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ TEST_F(SchedulerTest, emitModeChangeEvent) {
    const auto selectorPtr =
            std::make_shared<RefreshRateSelector>(kDisplay1Modes, kDisplay1Mode120->getId());
    mScheduler->registerDisplay(kDisplayId1, selectorPtr);
    mScheduler->onPrimaryDisplayModeChanged(kDisplay1Mode120_120);
    mScheduler->onDisplayModeChanged(kDisplayId1, kDisplay1Mode120_120);

    mScheduler->setContentRequirements({kLayer});

@@ -231,7 +231,7 @@ TEST_F(SchedulerTest, emitModeChangeEvent) {
    EXPECT_CALL(*mEventThread, onModeChanged(kDisplay1Mode120_120)).Times(1);

    mScheduler->touchTimerCallback(TimerState::Reset);
    mScheduler->onPrimaryDisplayModeChanged(kDisplay1Mode120_120);
    mScheduler->onDisplayModeChanged(kDisplayId1, kDisplay1Mode120_120);
}

TEST_F(SchedulerTest, calculateMaxAcquiredBufferCount) {
Loading