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

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

Merge changes I92d42042,I4f8bac4a,If264742a,I4b2ce528 into udc-dev

* changes:
  SF: Inline SurfaceFlinger::initializeDisplays
  SF: Commit initial DisplayState under lock
  SF: Reset VsyncModulator on active display change
  SF: Avoid forcing modeset during boot
parents b722e2d5 b5f40e59
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public:
    void setDuration(ConnectionHandle, std::chrono::nanoseconds workDuration,
                     std::chrono::nanoseconds readyDuration);

    const VsyncModulator& vsyncModulator() const { return *mVsyncModulator; }
    VsyncModulator& vsyncModulator() { return *mVsyncModulator; }

    // In some cases, we should only modulate for the pacesetter display. In those
    // cases, the caller should pass in the relevant display, and the method
+2 −2
Original line number Diff line number Diff line
@@ -187,9 +187,9 @@ void VsyncModulator::binderDied(const wp<IBinder>& who) {
    static_cast<void>(updateVsyncConfigLocked());
}

bool VsyncModulator::isVsyncConfigDefault() const {
bool VsyncModulator::isVsyncConfigEarly() const {
    std::lock_guard<std::mutex> lock(mMutex);
    return getNextVsyncConfigType() == VsyncConfigType::Late;
    return getNextVsyncConfigType() != VsyncConfigType::Late;
}

} // namespace android::scheduler
+4 −2
Original line number Diff line number Diff line
@@ -53,8 +53,12 @@ public:

    explicit VsyncModulator(const VsyncConfigSet&, Now = Clock::now);

    bool isVsyncConfigEarly() const EXCLUDES(mMutex);

    VsyncConfig getVsyncConfig() const EXCLUDES(mMutex);

    void cancelRefreshRateChange() { mRefreshRateChangePending = false; }

    [[nodiscard]] VsyncConfig setVsyncConfigSet(const VsyncConfigSet&) EXCLUDES(mMutex);

    // Changes offsets in response to transaction flags or commit.
@@ -72,8 +76,6 @@ public:

    [[nodiscard]] VsyncConfigOpt onDisplayRefresh(bool usedGpuComposition);

    [[nodiscard]] bool isVsyncConfigDefault() const;

protected:
    // Called from unit tests as well
    void binderDied(const wp<IBinder>&) override EXCLUDES(mMutex);
+35 −32
Original line number Diff line number Diff line
@@ -504,14 +504,13 @@ void SurfaceFlinger::binderDied(const wp<IBinder>&) {
    // the window manager died on us. prepare its eulogy.
    mBootFinished = false;

    static_cast<void>(mScheduler->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) {
        // Sever the link to inputflinger since it's gone as well.
    static_cast<void>(mScheduler->schedule(
            [this] { mInputFlinger.clear(); }));
        mInputFlinger.clear();

    // restore initial conditions (default device unblank, etc)
        initializeDisplays();
    }));

    // restart the boot-animation
    startBootAnim();
}

@@ -880,7 +879,9 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) {
    mDrawingState = mCurrentState;

    onActiveDisplayChangedLocked(nullptr, *display);
    initializeDisplays();

    static_cast<void>(mScheduler->schedule(
            [this]() FTL_FAKE_GUARD(kMainThreadContext) { initializeDisplays(); }));

    mPowerAdvisor->init();

@@ -3492,7 +3493,7 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken,

            // TODO(b/175678251) Call a listener instead.
            if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) {
                updateActiveDisplayVsyncLocked(*display);
                resetPhaseConfiguration(display->getActiveMode().fps);
            }
        }
        return;
@@ -3526,9 +3527,11 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken,
    }
}

void SurfaceFlinger::updateActiveDisplayVsyncLocked(const DisplayDevice& activeDisplay) {
void SurfaceFlinger::resetPhaseConfiguration(Fps refreshRate) {
    // Cancel the pending refresh rate change, if any, before updating the phase configuration.
    mScheduler->vsyncModulator().cancelRefreshRateChange();

    mVsyncConfiguration->reset();
    const Fps refreshRate = activeDisplay.getActiveMode().fps;
    updatePhaseConfiguration(refreshRate);
    mRefreshRateStats->setRefreshRate(refreshRate);
}
@@ -4270,7 +4273,7 @@ bool SurfaceFlinger::flushTransactionQueues(VsyncId vsyncId) {

bool SurfaceFlinger::applyTransactions(std::vector<TransactionState>& transactions,
                                       VsyncId vsyncId) {
    Mutex::Autolock _l(mStateLock);
    Mutex::Autolock lock(mStateLock);
    return applyTransactionsLocked(transactions, vsyncId);
}

@@ -4351,9 +4354,8 @@ bool SurfaceFlinger::shouldLatchUnsignaled(const sp<Layer>& layer, const layer_s
        // We don't want to latch unsignaled if are in early / client composition
        // as it leads to jank due to RenderEngine waiting for unsignaled buffer
        // or window animations being slow.
        const auto isDefaultVsyncConfig = mScheduler->vsyncModulator().isVsyncConfigDefault();
        if (!isDefaultVsyncConfig) {
            ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; !isDefaultVsyncConfig)",
        if (mScheduler->vsyncModulator().isVsyncConfigEarly()) {
            ALOGV("%s: false (LatchUnsignaledConfig::AutoSingleLayer; isVsyncConfigEarly)",
                  __func__);
            return false;
        }
@@ -4571,7 +4573,7 @@ bool SurfaceFlinger::applyTransactionState(const FrameTimelineInfo& frameTimelin

bool SurfaceFlinger::applyAndCommitDisplayTransactionStates(
        std::vector<TransactionState>& transactions) {
    Mutex::Autolock _l(mStateLock);
    Mutex::Autolock lock(mStateLock);
    bool needsTraversal = false;
    uint32_t transactionFlags = 0;
    for (auto& transaction : transactions) {
@@ -5309,8 +5311,8 @@ void SurfaceFlinger::onHandleDestroyed(BBinder* handle, sp<Layer>& layer, uint32
    setTransactionFlags(eTransactionFlushNeeded);
}

void SurfaceFlinger::onInitializeDisplays() {
    const auto display = getDefaultDisplayDeviceLocked();
void SurfaceFlinger::initializeDisplays() {
    const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked());
    if (!display) return;

    const sp<IBinder> token = display->getDisplayToken().promote();
@@ -5318,13 +5320,13 @@ void SurfaceFlinger::onInitializeDisplays() {

    TransactionState state;
    state.inputWindowCommands = mInputWindowCommands;
    nsecs_t now = systemTime();
    const nsecs_t now = systemTime();
    state.desiredPresentTime = now;
    state.postTime = now;
    state.permissions = layer_state_t::ACCESS_SURFACE_FLINGER;
    state.originPid = mPid;
    state.originUid = static_cast<int>(getuid());
    uint64_t transactionId = (((uint64_t)mPid) << 32) | mUniqueTransactionId++;
    const uint64_t transactionId = (static_cast<uint64_t>(mPid) << 32) | mUniqueTransactionId++;
    state.id = transactionId;

    // reset screen orientation and use primary layer stack
@@ -5344,21 +5346,16 @@ void SurfaceFlinger::onInitializeDisplays() {
    std::vector<TransactionState> transactions;
    transactions.emplace_back(state);

    // It should be on the main thread, apply it directly.
    if (mLegacyFrontEndEnabled) {
        applyTransactionsLocked(transactions, /*vsyncId=*/{0});
        applyTransactions(transactions, VsyncId{0});
    } else {
        applyAndCommitDisplayTransactionStates(transactions);
    }

    {
        ftl::FakeGuard guard(mStateLock);
        setPowerModeInternal(display, hal::PowerMode::ON);
    }

void SurfaceFlinger::initializeDisplays() {
    // Async since we may be called from the main thread.
    static_cast<void>(mScheduler->schedule(
            [this]() FTL_FAKE_GUARD(mStateLock)
                    FTL_FAKE_GUARD(kMainThreadContext) { onInitializeDisplays(); }));
}

void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal::PowerMode mode) {
@@ -7745,14 +7742,20 @@ void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveD
                                                  const DisplayDevice& activeDisplay) {
    ATRACE_CALL();

    // For the first display activated during boot, there is no need to force setDesiredActiveMode,
    // because DM is about to send its policy via setDesiredDisplayModeSpecs.
    bool forceApplyPolicy = false;

    if (inactiveDisplayPtr) {
        inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false);
        forceApplyPolicy = true;
    }

    mActiveDisplayId = activeDisplay.getPhysicalId();
    activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true);

    updateActiveDisplayVsyncLocked(activeDisplay);
    resetPhaseConfiguration(activeDisplay.getActiveMode().fps);

    mScheduler->setModeChangePending(false);
    mScheduler->setPacesetterDisplay(mActiveDisplayId);

@@ -7763,8 +7766,8 @@ void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveD
    // that case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In
    // either case, the Scheduler's cachedModeChangedParams must be initialized to the newly active
    // mode, and the kernel idle timer of the newly active display must be toggled.
    constexpr bool kForce = true;
    applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), kForce);
    applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(),
                                   forceApplyPolicy);
}

status_t SurfaceFlinger::addWindowInfosListener(
+3 −5
Original line number Diff line number Diff line
@@ -737,6 +737,8 @@ private:
    void updateCursorAsync();

    void initScheduler(const sp<const DisplayDevice>&) REQUIRES(kMainThreadContext, mStateLock);

    void resetPhaseConfiguration(Fps) REQUIRES(mStateLock, kMainThreadContext);
    void updatePhaseConfiguration(Fps) REQUIRES(mStateLock);

    /*
@@ -855,8 +857,7 @@ private:
     */

    // Called during boot, and restart after system_server death.
    void initializeDisplays();
    void onInitializeDisplays() REQUIRES(mStateLock, kMainThreadContext);
    void initializeDisplays() REQUIRES(kMainThreadContext);

    sp<const DisplayDevice> getDisplayDeviceLocked(const wp<IBinder>& displayToken) const
            REQUIRES(mStateLock) {
@@ -1121,9 +1122,6 @@ private:
                                               std::chrono::nanoseconds presentLatency);
    int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const;

    void updateActiveDisplayVsyncLocked(const DisplayDevice& activeDisplay)
            REQUIRES(mStateLock, kMainThreadContext);

    bool isHdrLayer(const frontend::LayerSnapshot& snapshot) const;

    ui::Rotation getPhysicalDisplayOrientation(DisplayId, bool isPrimary) const
Loading