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

Commit 8d3e4f32 authored by Ana Krulec's avatar Ana Krulec
Browse files

SF: Rename callbacks from SF to Scheduler to more generic name

Scheduler is going to call in SF to request configs on more occasions
than just through idle timer. This CL changes the callback into a more
direct request to either switch to DEFAULT or PERFORMANCE config.

Test: manual
Bug: 127365162
Change-Id: I67c37b6679671a9d998fde3fcfd189d572c784b4
parent 7d171b07
Loading
Loading
Loading
Loading
+9 −11
Original line number Original line Diff line number Diff line
@@ -308,14 +308,10 @@ void Scheduler::incrementFrameCounter() {
    mLayerHistory.incrementCounter();
    mLayerHistory.incrementCounter();
}
}


void Scheduler::setExpiredIdleTimerCallback(const ExpiredIdleTimerCallback& expiredTimerCallback) {
void Scheduler::setChangeRefreshRateCallback(
        const ChangeRefreshRateCallback& changeRefreshRateCallback) {
    std::lock_guard<std::mutex> lock(mCallbackLock);
    std::lock_guard<std::mutex> lock(mCallbackLock);
    mExpiredTimerCallback = expiredTimerCallback;
    mChangeRefreshRateCallback = changeRefreshRateCallback;
}

void Scheduler::setResetIdleTimerCallback(const ResetIdleTimerCallback& resetTimerCallback) {
    std::lock_guard<std::mutex> lock(mCallbackLock);
    mResetTimerCallback = resetTimerCallback;
}
}


void Scheduler::updateFrameSkipping(const int64_t skipCount) {
void Scheduler::updateFrameSkipping(const int64_t skipCount) {
@@ -414,16 +410,18 @@ void Scheduler::resetIdleTimer() {


void Scheduler::resetTimerCallback() {
void Scheduler::resetTimerCallback() {
    std::lock_guard<std::mutex> lock(mCallbackLock);
    std::lock_guard<std::mutex> lock(mCallbackLock);
    if (mResetTimerCallback) {
    if (mChangeRefreshRateCallback) {
        mResetTimerCallback();
        // We do not notify the applications about config changes when idle timer is reset.
        mChangeRefreshRateCallback(RefreshRateType::PERFORMANCE, ConfigEvent::None);
        ATRACE_INT("ExpiredIdleTimer", 0);
        ATRACE_INT("ExpiredIdleTimer", 0);
    }
    }
}
}


void Scheduler::expiredTimerCallback() {
void Scheduler::expiredTimerCallback() {
    std::lock_guard<std::mutex> lock(mCallbackLock);
    std::lock_guard<std::mutex> lock(mCallbackLock);
    if (mExpiredTimerCallback) {
    if (mChangeRefreshRateCallback) {
        mExpiredTimerCallback();
        // We do not notify the applications about config changes when idle timer expires.
        mChangeRefreshRateCallback(RefreshRateType::DEFAULT, ConfigEvent::None);
        ATRACE_INT("ExpiredIdleTimer", 1);
        ATRACE_INT("ExpiredIdleTimer", 1);
    }
    }
}
}
+16 −8
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@
#include "IdleTimer.h"
#include "IdleTimer.h"
#include "InjectVSyncSource.h"
#include "InjectVSyncSource.h"
#include "LayerHistory.h"
#include "LayerHistory.h"
#include "RefreshRateConfigs.h"
#include "SchedulerUtils.h"
#include "SchedulerUtils.h"


namespace android {
namespace android {
@@ -36,9 +37,19 @@ class EventControlThread;


class Scheduler {
class Scheduler {
public:
public:
    using ExpiredIdleTimerCallback = std::function<void()>;
    // Enum to keep track of whether we trigger event to notify choreographer of config changes.
    enum class ConfigEvent { None, Changed };

    // logical or operator with the semantics of at least one of the events is Changed
    friend ConfigEvent operator|(const ConfigEvent& first, const ConfigEvent& second) {
        if (first == ConfigEvent::Changed) return ConfigEvent::Changed;
        if (second == ConfigEvent::Changed) return ConfigEvent::Changed;
        return ConfigEvent::None;
    }

    using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType;
    using ChangeRefreshRateCallback = std::function<void(RefreshRateType, ConfigEvent)>;
    using GetVsyncPeriod = std::function<nsecs_t()>;
    using GetVsyncPeriod = std::function<nsecs_t()>;
    using ResetIdleTimerCallback = std::function<void()>;


    // Enum to indicate whether to start the transaction early, or at vsync time.
    // Enum to indicate whether to start the transaction early, or at vsync time.
    enum class TransactionStart { EARLY, NORMAL };
    enum class TransactionStart { EARLY, NORMAL };
@@ -135,10 +146,8 @@ public:
                                     const std::string layerName);
                                     const std::string layerName);
    // Increments counter in the layer history to indicate that SF has started a new frame.
    // Increments counter in the layer history to indicate that SF has started a new frame.
    void incrementFrameCounter();
    void incrementFrameCounter();
    // Callback that gets invoked once the idle timer expires.
    // Callback that gets invoked when Scheduler wants to change the refresh rate.
    void setExpiredIdleTimerCallback(const ExpiredIdleTimerCallback& expiredTimerCallback);
    void setChangeRefreshRateCallback(const ChangeRefreshRateCallback& changeRefreshRateCallback);
    // Callback that gets invoked once the idle timer is reset.
    void setResetIdleTimerCallback(const ResetIdleTimerCallback& resetTimerCallback);
    // Returns relevant information about Scheduler for dumpsys purposes.
    // Returns relevant information about Scheduler for dumpsys purposes.
    std::string doDump();
    std::string doDump();


@@ -216,8 +225,7 @@ private:
    std::unique_ptr<scheduler::IdleTimer> mIdleTimer;
    std::unique_ptr<scheduler::IdleTimer> mIdleTimer;


    std::mutex mCallbackLock;
    std::mutex mCallbackLock;
    ExpiredIdleTimerCallback mExpiredTimerCallback GUARDED_BY(mCallbackLock);
    ChangeRefreshRateCallback mChangeRefreshRateCallback GUARDED_BY(mCallbackLock);
    ExpiredIdleTimerCallback mResetTimerCallback GUARDED_BY(mCallbackLock);
};
};


} // namespace android
} // namespace android
+13 −16
Original line number Original line Diff line number Diff line
@@ -571,11 +571,11 @@ void SurfaceFlinger::bootFinished()
        if (mUse90Hz) {
        if (mUse90Hz) {
            mPhaseOffsets->setRefreshRateType(
            mPhaseOffsets->setRefreshRateType(
                    scheduler::RefreshRateConfigs::RefreshRateType::PERFORMANCE);
                    scheduler::RefreshRateConfigs::RefreshRateType::PERFORMANCE);
            setRefreshRateTo(RefreshRateType::PERFORMANCE, ConfigEvent::None);
            setRefreshRateTo(RefreshRateType::PERFORMANCE, Scheduler::ConfigEvent::None);
        } else {
        } else {
            mPhaseOffsets->setRefreshRateType(
            mPhaseOffsets->setRefreshRateType(
                    scheduler::RefreshRateConfigs::RefreshRateType::DEFAULT);
                    scheduler::RefreshRateConfigs::RefreshRateType::DEFAULT);
            setRefreshRateTo(RefreshRateType::DEFAULT, ConfigEvent::None);
            setRefreshRateTo(RefreshRateType::DEFAULT, Scheduler::ConfigEvent::None);
        }
        }
    }));
    }));
}
}
@@ -700,13 +700,10 @@ void SurfaceFlinger::init() {
    }
    }


    if (mUse90Hz) {
    if (mUse90Hz) {
        mScheduler->setExpiredIdleTimerCallback([this] {
        mScheduler->setChangeRefreshRateCallback(
                [this](RefreshRateType type, Scheduler::ConfigEvent event) {
                    Mutex::Autolock lock(mStateLock);
                    Mutex::Autolock lock(mStateLock);
            setRefreshRateTo(RefreshRateType::DEFAULT, ConfigEvent::None);
                    setRefreshRateTo(type, event);
        });
        mScheduler->setResetIdleTimerCallback([this] {
            Mutex::Autolock lock(mStateLock);
            setRefreshRateTo(RefreshRateType::PERFORMANCE, ConfigEvent::None);
                });
                });
    }
    }
    mRefreshRateConfigs[*display->getId()] = std::make_shared<scheduler::RefreshRateConfigs>(
    mRefreshRateConfigs[*display->getId()] = std::make_shared<scheduler::RefreshRateConfigs>(
@@ -917,7 +914,7 @@ int SurfaceFlinger::getActiveConfig(const sp<IBinder>& displayToken) {
}
}


void SurfaceFlinger::setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode,
void SurfaceFlinger::setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode,
                                            ConfigEvent event) {
                                            Scheduler::ConfigEvent event) {
    ATRACE_CALL();
    ATRACE_CALL();


    // Lock is acquired by setRefreshRateTo.
    // Lock is acquired by setRefreshRateTo.
@@ -941,7 +938,7 @@ void SurfaceFlinger::setDesiredActiveConfig(const sp<IBinder>& displayToken, int
    // config twice. However event generation config might have changed so we need to update it
    // config twice. However event generation config might have changed so we need to update it
    // accordingly
    // accordingly
    std::lock_guard<std::mutex> lock(mActiveConfigLock);
    std::lock_guard<std::mutex> lock(mActiveConfigLock);
    const ConfigEvent desiredConfig = mDesiredActiveConfig.event | event;
    const Scheduler::ConfigEvent desiredConfig = mDesiredActiveConfig.event | event;
    mDesiredActiveConfig = ActiveConfigInfo{mode, displayToken, desiredConfig};
    mDesiredActiveConfig = ActiveConfigInfo{mode, displayToken, desiredConfig};


    if (!mDesiredActiveConfigChanged) {
    if (!mDesiredActiveConfigChanged) {
@@ -975,7 +972,7 @@ void SurfaceFlinger::setActiveConfigInternal() {


    mScheduler->resyncToHardwareVsync(true, getVsyncPeriod());
    mScheduler->resyncToHardwareVsync(true, getVsyncPeriod());
    ATRACE_INT("ActiveConfigMode", mUpcomingActiveConfig.configId);
    ATRACE_INT("ActiveConfigMode", mUpcomingActiveConfig.configId);
    if (mUpcomingActiveConfig.event != ConfigEvent::None) {
    if (mUpcomingActiveConfig.event != Scheduler::ConfigEvent::None) {
        mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value,
        mScheduler->onConfigChanged(mAppConnectionHandle, display->getId()->value,
                                    mUpcomingActiveConfig.configId);
                                    mUpcomingActiveConfig.configId);
    }
    }
@@ -1416,9 +1413,8 @@ bool SurfaceFlinger::isConfigAllowed(const DisplayId& displayId, int32_t config)
    return mAllowedConfigs[displayId]->isConfigAllowed(config);
    return mAllowedConfigs[displayId]->isConfigAllowed(config);
}
}


void SurfaceFlinger::setRefreshRateTo(RefreshRateType refreshRate, ConfigEvent event) {
void SurfaceFlinger::setRefreshRateTo(RefreshRateType refreshRate, Scheduler::ConfigEvent event) {
    ATRACE_CALL();
    ATRACE_CALL();

    mPhaseOffsets->setRefreshRateType(refreshRate);
    mPhaseOffsets->setRefreshRateType(refreshRate);


    const auto [early, gl, late] = mPhaseOffsets->getCurrentOffsets();
    const auto [early, gl, late] = mPhaseOffsets->getCurrentOffsets();
@@ -5652,7 +5648,8 @@ void SurfaceFlinger::setAllowedDisplayConfigsInternal(
                // we may want to enhance this logic to pick a similar config
                // we may want to enhance this logic to pick a similar config
                // to the current one
                // to the current one
                ALOGV("Old config is not allowed - switching to config %d", config.configId);
                ALOGV("Old config is not allowed - switching to config %d", config.configId);
                setDesiredActiveConfig(displayToken, config.configId, ConfigEvent::Changed);
                setDesiredActiveConfig(displayToken, config.configId,
                                       Scheduler::ConfigEvent::Changed);
                break;
                break;
            }
            }
        }
        }
+5 −14
Original line number Original line Diff line number Diff line
@@ -522,20 +522,11 @@ private:
    void signalLayerUpdate();
    void signalLayerUpdate();
    void signalRefresh();
    void signalRefresh();


    enum class ConfigEvent { None, Changed };

    // logical or operator with the semantics of at least one of the events is Changed
    friend ConfigEvent operator|(const ConfigEvent& first, const ConfigEvent& second) {
        if (first == ConfigEvent::Changed) return ConfigEvent::Changed;
        if (second == ConfigEvent::Changed) return ConfigEvent::Changed;
        return ConfigEvent::None;
    }

    // called on the main thread in response to initializeDisplays()
    // called on the main thread in response to initializeDisplays()
    void onInitializeDisplays() REQUIRES(mStateLock);
    void onInitializeDisplays() REQUIRES(mStateLock);
    // Sets the desired active config bit. It obtains the lock, and sets mDesiredActiveConfig.
    // Sets the desired active config bit. It obtains the lock, and sets mDesiredActiveConfig.
    void setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode, ConfigEvent event)
    void setDesiredActiveConfig(const sp<IBinder>& displayToken, int mode,
            REQUIRES(mStateLock);
                                Scheduler::ConfigEvent event) REQUIRES(mStateLock);
    // Once HWC has returned the present fence, this sets the active config and a new refresh
    // Once HWC has returned the present fence, this sets the active config and a new refresh
    // rate in SF. It also triggers HWC vsync.
    // rate in SF. It also triggers HWC vsync.
    void setActiveConfigInternal() REQUIRES(mStateLock);
    void setActiveConfigInternal() REQUIRES(mStateLock);
@@ -816,8 +807,8 @@ private:


    // Sets the refresh rate by switching active configs, if they are available for
    // Sets the refresh rate by switching active configs, if they are available for
    // the desired refresh rate.
    // the desired refresh rate.
    void setRefreshRateTo(scheduler::RefreshRateConfigs::RefreshRateType, ConfigEvent event)
    void setRefreshRateTo(scheduler::RefreshRateConfigs::RefreshRateType,
            REQUIRES(mStateLock);
                          Scheduler::ConfigEvent event) REQUIRES(mStateLock);


    bool isConfigAllowed(const DisplayId& displayId, int32_t config);
    bool isConfigAllowed(const DisplayId& displayId, int32_t config);


@@ -1126,7 +1117,7 @@ private:
    struct ActiveConfigInfo {
    struct ActiveConfigInfo {
        int configId;
        int configId;
        sp<IBinder> displayToken;
        sp<IBinder> displayToken;
        ConfigEvent event;
        Scheduler::ConfigEvent event;


        bool operator!=(const ActiveConfigInfo& other) const {
        bool operator!=(const ActiveConfigInfo& other) const {
            if (configId != other.configId) {
            if (configId != other.configId) {