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

Commit 3efa3942 authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: move RefreshRateConfigs to DisplayDevice

Move RefreshRateConfigs to DisplayDevice to be able to maintain
a per-display refresh rate switching policy.

Test: SF unit tests
Test: refresh rate switching is working on device with
more than one display
Bug: 187539899

Change-Id: Ica6a955e8ad0e563a0740f6579b61fc592eb982c
parent 7825c68e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -421,7 +421,7 @@ bool BufferLayer::onPostComposition(const DisplayDevice* display,
        mFrameTracker.setFrameReadyTime(desiredPresentTime);
    }

    const Fps refreshRate = mFlinger->mRefreshRateConfigs->getCurrentRefreshRate().getFps();
    const Fps refreshRate = display->refreshRateConfigs().getCurrentRefreshRate().getFps();
    const std::optional<Fps> renderRate = mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());
    if (presentFence->isValid()) {
        mFlinger->mTimeStats->setPresentFence(layerId, mCurrentFrameNumber, presentFence,
+9 −1
Original line number Diff line number Diff line
@@ -67,7 +67,8 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs& args)
        mCompositionDisplay{args.compositionDisplay},
        mPhysicalOrientation(args.physicalOrientation),
        mSupportedModes(std::move(args.supportedModes)),
        mIsPrimary(args.isPrimary) {
        mIsPrimary(args.isPrimary),
        mRefreshRateConfigs(std::move(args.refreshRateConfigs)) {
    mCompositionDisplay->editState().isSecure = args.isSecure;
    mCompositionDisplay->createRenderSurface(
            compositionengine::RenderSurfaceCreationArgsBuilder()
@@ -155,6 +156,9 @@ void DisplayDevice::setActiveMode(DisplayModeId id) {
    const auto mode = getMode(id);
    LOG_FATAL_IF(!mode, "Cannot set active mode which is not supported.");
    mActiveMode = mode;
    if (mRefreshRateConfigs) {
        mRefreshRateConfigs->setCurrentModeId(mActiveMode->getId());
    }
}

status_t DisplayDevice::initiateModeChange(DisplayModeId modeId,
@@ -296,6 +300,10 @@ void DisplayDevice::dump(std::string& result) const {
    }
    result.append("\n");
    getCompositionDisplay()->dump(result);

    if (mRefreshRateConfigs) {
        mRefreshRateConfigs->dump(result);
    }
}

bool DisplayDevice::hasRenderIntent(ui::RenderIntent intent) const {
+16 −0
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@
#include "DisplayHardware/Hal.h"
#include "DisplayHardware/PowerAdvisor.h"

#include "Scheduler/RefreshRateConfigs.h"

namespace android {

class Fence;
@@ -193,6 +195,16 @@ public:
    // set-top boxes after a hotplug reconnect.
    DisplayModePtr getMode(DisplayModeId) const;

    // Returns the refresh rate configs for this display.
    scheduler::RefreshRateConfigs& refreshRateConfigs() const { return *mRefreshRateConfigs; }

    // Returns a shared pointer to the refresh rate configs for this display.
    // Clients can store this refresh rate configs and use it even if the DisplayDevice
    // is destroyed.
    std::shared_ptr<scheduler::RefreshRateConfigs> holdRefreshRateConfigs() const {
        return mRefreshRateConfigs;
    }

    void onVsync(nsecs_t timestamp);
    nsecs_t getVsyncPeriodFromHWC() const;
    nsecs_t getRefreshTimestamp() const;
@@ -238,6 +250,8 @@ private:
    std::optional<DeviceProductInfo> mDeviceProductInfo;

    std::vector<ui::Hdr> mOverrideHdrTypes;

    std::shared_ptr<scheduler::RefreshRateConfigs> mRefreshRateConfigs;
};

struct DisplayDeviceState {
@@ -283,6 +297,7 @@ struct DisplayDeviceCreationArgs {
    HWComposer& hwComposer;
    const wp<IBinder> displayToken;
    const std::shared_ptr<compositionengine::Display> compositionDisplay;
    std::shared_ptr<scheduler::RefreshRateConfigs> refreshRateConfigs;

    int32_t sequenceId{0};
    std::optional<ui::DisplayConnectionType> connectionType;
@@ -298,6 +313,7 @@ struct DisplayDeviceCreationArgs {
            hardware::graphics::composer::hal::PowerMode::ON};
    bool isPrimary{false};
    DisplayModes supportedModes;
    DisplayModeId activeModeId;
};

// Predicates for display lookup.
+10 −1
Original line number Diff line number Diff line
@@ -283,7 +283,16 @@ void RefreshRateOverlay::onInvalidate() {

void RefreshRateOverlay::reset() {
    mBufferCache.clear();
    const auto range = mFlinger.mRefreshRateConfigs->getSupportedRefreshRateRange();
    // TODO: this is a temp hack that would be removed in the next CL
    const auto range = [&]() NO_THREAD_SAFETY_ANALYSIS {
        constexpr auto defaultFps = Fps(60);
        const auto display = mFlinger.getDefaultDisplayDeviceLocked();
        if (display) {
            return display->refreshRateConfigs().getSupportedRefreshRateRange();
        }
        ALOGW("%s: default display is null", __func__);
        return scheduler::RefreshRateConfigs::FpsRange{defaultFps, defaultFps};
    }();
    mLowFps = range.min.getIntValue();
    mHighFps = range.max.getIntValue();
}
+4 −4
Original line number Diff line number Diff line
@@ -75,10 +75,9 @@ void trace(const LayerInfo& info, LayerHistory::LayerVoteType type, int fps) {
}
} // namespace

LayerHistory::LayerHistory(const RefreshRateConfigs& refreshRateConfigs)
LayerHistory::LayerHistory()
      : mTraceEnabled(traceEnabled()), mUseFrameRatePriority(useFrameRatePriority()) {
    LayerInfo::setTraceEnabled(mTraceEnabled);
    LayerInfo::setRefreshRateConfigs(refreshRateConfigs);
}

LayerHistory::~LayerHistory() = default;
@@ -138,7 +137,8 @@ void LayerHistory::record(Layer* layer, nsecs_t presentTime, nsecs_t now,
    }
}

LayerHistory::Summary LayerHistory::summarize(nsecs_t now) {
LayerHistory::Summary LayerHistory::summarize(const RefreshRateConfigs& refreshRateConfigs,
                                              nsecs_t now) {
    LayerHistory::Summary summary;

    std::lock_guard lock(mLock);
@@ -151,7 +151,7 @@ LayerHistory::Summary LayerHistory::summarize(nsecs_t now) {
        ALOGV("%s has priority: %d %s focused", info->getName().c_str(), frameRateSelectionPriority,
              layerFocused ? "" : "not");

        const auto vote = info->getRefreshRateVote(now);
        const auto vote = info->getRefreshRateVote(refreshRateConfigs, now);
        // Skip NoVote layer as those don't have any requirements
        if (vote.type == LayerHistory::LayerVoteType::NoVote) {
            continue;
Loading