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

Commit 71c437dc authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: add support for FrameRateCompatibilityType

Bug: 147516364
Test: adb shell /data/nativetest64/SurfaceFlinger_test/SurfaceFlinger_test --gtest_filter='SetFrameRateTest.*'
Test: adb shell /data/nativetest64/libsurfaceflinger_unittest/libsurfaceflinger_unittest --gtest_filter=*RefreshRateConfigs*
Test: adb shell /data/nativetest64/libsurfaceflinger_unittest/libsurfaceflinger_unittest --gtest_filter=*LayerHistory*
Change-Id: I49272804e25f04e1d7a148a0008551cbc5428011
parent ce172aac
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -125,21 +125,16 @@ bool BufferQueueLayer::shouldPresentNow(nsecs_t expectedPresentTime) const {
    return isDue || !isPlausible;
}

bool BufferQueueLayer::setFrameRate(float frameRate) {
bool BufferQueueLayer::setFrameRate(FrameRate frameRate) {
    float oldFrameRate = 0.f;
    status_t result = mConsumer->getFrameRate(&oldFrameRate);
    bool frameRateChanged = result < 0 || frameRate != oldFrameRate;
    mConsumer->setFrameRate(frameRate);
    bool frameRateChanged = result < 0 || frameRate.rate != oldFrameRate;
    mConsumer->setFrameRate(frameRate.rate);
    return frameRateChanged;
}

std::optional<float> BufferQueueLayer::getFrameRate() const {
    const auto frameRate = mLatchedFrameRate.load();
    if (frameRate > 0.f || frameRate == FRAME_RATE_NO_VOTE) {
        return frameRate;
    }

    return {};
Layer::FrameRate BufferQueueLayer::getFrameRate() const {
    return FrameRate(mLatchedFrameRate, Layer::FrameRateCompatibility::Default);
}

// -----------------------------------------------------------------------
+2 −2
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@ public:

    bool shouldPresentNow(nsecs_t expectedPresentTime) const override;

    bool setFrameRate(float frameRate) override;
    std::optional<float> getFrameRate() const override;
    bool setFrameRate(FrameRate frameRate) override;
    FrameRate getFrameRate() const override;

    // -----------------------------------------------------------------------

+3 −7
Original line number Diff line number Diff line
@@ -117,7 +117,6 @@ Layer::Layer(const LayerCreationArgs& args)
    mCurrentState.frameRateSelectionPriority = PRIORITY_UNSET;
    mCurrentState.metadata = args.metadata;
    mCurrentState.shadowRadius = 0.f;
    mCurrentState.frameRate = 0.f;

    // drawing state & current state are identical
    mDrawingState = mCurrentState;
@@ -1245,7 +1244,7 @@ bool Layer::setShadowRadius(float shadowRadius) {
    return true;
}

bool Layer::setFrameRate(float frameRate) {
bool Layer::setFrameRate(FrameRate frameRate) {
    if (mCurrentState.frameRate == frameRate) {
        return false;
    }
@@ -1257,11 +1256,8 @@ bool Layer::setFrameRate(float frameRate) {
    return true;
}

std::optional<float> Layer::getFrameRate() const {
    const auto frameRate = getDrawingState().frameRate;
    if (frameRate > 0.f || frameRate == FRAME_RATE_NO_VOTE) return frameRate;

    return {};
Layer::FrameRate Layer::getFrameRate() const {
    return getDrawingState().frameRate;
}

void Layer::deferTransactionUntil_legacy(const sp<Layer>& barrierLayer, uint64_t frameNumber) {
+31 −4
Original line number Diff line number Diff line
@@ -136,6 +136,34 @@ public:
        float radius = 0.0f;
    };

    // FrameRateCompatibility specifies how we should interpret the frame rate associated with
    // the layer.
    enum class FrameRateCompatibility {
        Default, // Layer didn't specify any specific handling strategy

        ExactOrMultiple, // Layer needs the exact frame rate (or a multiple of it) to present the
                         // content properly. Any other value will result in a pull down.

        NoVote, // Layer doesn't have any requirements for the refresh rate and
                // should not be considered when the display refresh rate is determined.
    };

    // Encapsulates the frame rate and compatibility of the layer. This information will be used
    // when the display refresh rate is determined.
    struct FrameRate {
        float rate;
        FrameRateCompatibility type;

        FrameRate() : rate(0), type(FrameRateCompatibility::Default) {}
        FrameRate(float rate, FrameRateCompatibility type) : rate(rate), type(type) {}

        bool operator==(const FrameRate& other) const {
            return rate == other.rate && type == other.type;
        }

        bool operator!=(const FrameRate& other) const { return !(*this == other); }
    };

    struct State {
        Geometry active_legacy;
        Geometry requested_legacy;
@@ -227,7 +255,7 @@ public:
        // Priority of the layer assigned by Window Manager.
        int32_t frameRateSelectionPriority;

        float frameRate;
        FrameRate frameRate;
    };

    explicit Layer(const LayerCreationArgs& args);
@@ -754,9 +782,8 @@ public:
     */
    Rect getCroppedBufferSize(const Layer::State& s) const;

    constexpr static auto FRAME_RATE_NO_VOTE = -1.0f;
    virtual bool setFrameRate(float frameRate);
    virtual std::optional<float> getFrameRate() const;
    virtual bool setFrameRate(FrameRate frameRate);
    virtual FrameRate getFrameRate() const;

protected:
    // constant
+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ bool RefreshRateOverlay::createLayer() {

    Mutex::Autolock _l(mFlinger.mStateLock);
    mLayer = mClient->getLayerUser(mIBinder);
    mLayer->setFrameRate(Layer::FRAME_RATE_NO_VOTE);
    mLayer->setFrameRate(Layer::FrameRate(0, Layer::FrameRateCompatibility::NoVote));

    // setting Layer's Z requires resorting layersSortedByZ
    ssize_t idx = mFlinger.mCurrentState.layersSortedByZ.indexOf(mLayer);
Loading