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

Commit 41376b6f authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Update LayerHistory layer properties when they change

Previously we would only update LayerHistory when framerate
changed or there was a buffer update. This occasionally lead to
an incorrect frame rate being calculated with stale data. Fix this
by updating layer properties when ever they change.

Fixes: 306710286, 306716374
Test: presubmit
Test: atest CtsSurfaceControlTests CtsSurfaceControlTestsStaging
Test: displays runs at 60fps when maps is running after screenrotation
Change-Id: I14388ca69eb6f940c436f88d55cff689e51bc238
parent 2ae4e980
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -167,6 +167,27 @@ void LayerHistory::setDefaultFrameRateCompatibility(int32_t id,
    info->setDefaultLayerVote(getVoteType(frameRateCompatibility, contentDetectionEnabled));
}

void LayerHistory::setLayerProperties(int32_t id, const LayerProps& properties) {
    std::lock_guard lock(mLock);

    auto [found, layerPair] = findLayer(id);
    if (found == LayerStatus::NotFound) {
        // Offscreen layer
        ALOGV("%s: %d not registered", __func__, id);
        return;
    }

    const auto& info = layerPair->second;
    info->setProperties(properties);

    // Activate layer if inactive and visible.
    if (found == LayerStatus::LayerInInactiveMap && info->isVisible()) {
        mActiveLayerInfos.insert(
                {id, std::make_pair(layerPair->first, std::move(layerPair->second))});
        mInactiveLayerInfos.erase(id);
    }
}

auto LayerHistory::summarize(const RefreshRateSelector& selector, nsecs_t now) -> Summary {
    ATRACE_CALL();
    Summary summary;
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public:
    // does not set a preference for refresh rate.
    void setDefaultFrameRateCompatibility(int32_t id, FrameRateCompatibility frameRateCompatibility,
                                          bool contentDetectionEnabled);

    void setLayerProperties(int32_t id, const LayerProps&);
    using Summary = std::vector<RefreshRateSelector::LayerRequirement>;

    // Rebuilds sets of active/inactive layers, and accumulates stats for active layers.
+4 −0
Original line number Diff line number Diff line
@@ -75,6 +75,10 @@ void LayerInfo::setLastPresentTime(nsecs_t lastPresentTime, nsecs_t now, LayerUp
    }
}

void LayerInfo::setProperties(const android::scheduler::LayerProps& properties) {
    *mLayerProps = properties;
}

bool LayerInfo::isFrameTimeValid(const FrameTimeData& frameTime) const {
    return frameTime.queueTime >= std::chrono::duration_cast<std::chrono::nanoseconds>(
                                          mFrameTimeValidSince.time_since_epoch())
+2 −0
Original line number Diff line number Diff line
@@ -182,6 +182,8 @@ public:
    // layer can go back to whatever vote it had before the app voted for it.
    void setDefaultLayerVote(LayerHistory::LayerVoteType type) { mDefaultVote = type; }

    void setProperties(const LayerProps&);

    // Resets the layer vote to its default.
    void resetLayerVote() {
        mLayerVote = {mDefaultVote, Fps(), Seamlessness::Default, FrameRateCategory::Default};
+4 −0
Original line number Diff line number Diff line
@@ -654,6 +654,10 @@ void Scheduler::setDefaultFrameRateCompatibility(
                                                   mFeatures.test(Feature::kContentDetection));
}

void Scheduler::setLayerProperties(int32_t id, const android::scheduler::LayerProps& properties) {
    mLayerHistory.setLayerProperties(id, properties);
}

void Scheduler::chooseRefreshRateForContent(
        const surfaceflinger::frontend::LayerHierarchy* hierarchy,
        bool updateAttachedChoreographer) {
Loading