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

Commit 6194e2eb authored by Vishnu Nair's avatar Vishnu Nair
Browse files

SF Bounds caching 1/3: Defer calls that use layer bounds until the cached bounds are available.

End goal is to calculate the bounds once in the surface flinger loop. The bounds are invalidated
if the visible region changes. The first step is to defer any functions that use the cache to after
the bounds is calculated.

- Defer updating display dirty region when latching buffers.
- Defer updating cursor and input flinger until all the buffers have been latched.
- Recompute visible regions if transformToDisplayInverse flag changes

Test: go/wm-smoke
Test: atest -a libinput_tests inputflinger_tests SurfaceFlinger_test libsurfaceflinger_unittest SurfaceParcelable_test libgui_test
Change-Id: Ife6e0f06939d9f4fb051b68cb2b1c9f5bd180b57
parent aa8756d2
Loading
Loading
Loading
Loading
+17 −18
Original line number Diff line number Diff line
@@ -365,20 +365,18 @@ bool BufferLayer::onPostComposition(const std::optional<DisplayId>& displayId,
    return true;
}

Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
bool BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
                              const sp<Fence>& releaseFence) {
    ATRACE_CALL();

    std::optional<Region> sidebandStreamDirtyRegion = latchSidebandStream(recomputeVisibleRegions);
    bool refreshRequired = latchSidebandStream(recomputeVisibleRegions);

    if (sidebandStreamDirtyRegion) {
        return *sidebandStreamDirtyRegion;
    if (refreshRequired) {
        return refreshRequired;
    }

    Region dirtyRegion;

    if (!hasReadyFrame()) {
        return dirtyRegion;
        return false;
    }

    // if we've already called updateTexImage() without going through
@@ -387,14 +385,14 @@ Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime
    // compositionComplete() call.
    // we'll trigger an update in onPreComposition().
    if (mRefreshPending) {
        return dirtyRegion;
        return false;
    }

    // If the head buffer's acquire fence hasn't signaled yet, return and
    // try again later
    if (!fenceHasSignaled()) {
        mFlinger->signalLayerUpdate();
        return dirtyRegion;
        return false;
    }

    // Capture the old state of the layer for comparisons later
@@ -404,24 +402,24 @@ Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime

    if (!allTransactionsSignaled()) {
        mFlinger->signalLayerUpdate();
        return dirtyRegion;
        return false;
    }

    status_t err = updateTexImage(recomputeVisibleRegions, latchTime, releaseFence);
    if (err != NO_ERROR) {
        return dirtyRegion;
        return false;
    }

    err = updateActiveBuffer();
    if (err != NO_ERROR) {
        return dirtyRegion;
        return false;
    }

    mBufferLatched = true;

    err = updateFrameNumber(latchTime);
    if (err != NO_ERROR) {
        return dirtyRegion;
        return false;
    }

    mRefreshPending = true;
@@ -461,11 +459,14 @@ Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime
    Rect crop(getDrawingCrop());
    const uint32_t transform(getDrawingTransform());
    const uint32_t scalingMode(getDrawingScalingMode());
    const bool transformToDisplayInverse(getTransformToDisplayInverse());
    if ((crop != mCurrentCrop) || (transform != mCurrentTransform) ||
        (scalingMode != mCurrentScalingMode)) {
        (scalingMode != mCurrentScalingMode) ||
        (transformToDisplayInverse != mTransformToDisplayInverse)) {
        mCurrentCrop = crop;
        mCurrentTransform = transform;
        mCurrentScalingMode = scalingMode;
        mTransformToDisplayInverse = transformToDisplayInverse;
        recomputeVisibleRegions = true;
    }

@@ -502,9 +503,7 @@ Region BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime
        }
    }

    // FIXME: postedRegion should be dirty & bounds
    // transform the dirty region to window-manager space
    return getTransform().transform(Region(getBufferSize(s)));
    return true;
}

// transaction
+6 −3
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ public:
    // If there was a GL composition step rendering the previous frame, then
    // releaseFence will be populated with a native fence that fires when
    // composition has completed.
    Region latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
    bool latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
                     const sp<Fence>& releaseFence) override;

    bool isBufferLatched() const override { return mRefreshPending; }
@@ -137,7 +137,8 @@ private:
    virtual bool getAutoRefresh() const = 0;
    virtual bool getSidebandStreamChanged() const = 0;

    virtual std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) = 0;
    // Latch sideband stream and returns true if the dirty region should be updated.
    virtual bool latchSidebandStream(bool& recomputeVisibleRegions) = 0;

    virtual bool hasFrameUpdate() const = 0;

@@ -179,6 +180,8 @@ private:

    uint32_t mCurrentScalingMode{NATIVE_WINDOW_SCALING_MODE_FREEZE};

    bool mTransformToDisplayInverse{false};

    // main thread.
    bool mBufferLatched{false}; // TODO: Use mActiveBuffer?

+3 −4
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ bool BufferQueueLayer::getSidebandStreamChanged() const {
    return mSidebandStreamChanged;
}

std::optional<Region> BufferQueueLayer::latchSidebandStream(bool& recomputeVisibleRegions) {
bool BufferQueueLayer::latchSidebandStream(bool& recomputeVisibleRegions) {
    bool sidebandStreamChanged = true;
    if (mSidebandStreamChanged.compare_exchange_strong(sidebandStreamChanged, false)) {
        // mSidebandStreamChanged was changed to false
@@ -202,10 +202,9 @@ std::optional<Region> BufferQueueLayer::latchSidebandStream(bool& recomputeVisib
        }
        recomputeVisibleRegions = true;

        const State& s(getDrawingState());
        return getTransform().transform(Region(Rect(s.active_legacy.w, s.active_legacy.h)));
        return true;
    }
    return {};
    return false;
}

bool BufferQueueLayer::hasFrameUpdate() const {
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ private:
    bool getAutoRefresh() const override;
    bool getSidebandStreamChanged() const override;

    std::optional<Region> latchSidebandStream(bool& recomputeVisibleRegions) override;
    bool latchSidebandStream(bool& recomputeVisibleRegions) override;

    bool hasFrameUpdate() const override;

+3 −3
Original line number Diff line number Diff line
@@ -420,7 +420,7 @@ bool BufferStateLayer::getSidebandStreamChanged() const {
    return mSidebandStreamChanged.load();
}

std::optional<Region> BufferStateLayer::latchSidebandStream(bool& recomputeVisibleRegions) {
bool BufferStateLayer::latchSidebandStream(bool& recomputeVisibleRegions) {
    if (mSidebandStreamChanged.exchange(false)) {
        const State& s(getDrawingState());
        // mSidebandStreamChanged was true
@@ -432,9 +432,9 @@ std::optional<Region> BufferStateLayer::latchSidebandStream(bool& recomputeVisib
        }
        recomputeVisibleRegions = true;

        return getTransform().transform(Region(Rect(s.active.w, s.active.h)));
        return true;
    }
    return {};
    return false;
}

bool BufferStateLayer::hasFrameUpdate() const {
Loading