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

Commit 56e538fd authored by Alec Mouri's avatar Alec Mouri
Browse files

Remove extra glFlush from handleMessageRefresh().

For BufferQueueLayers, the GL flush fence was already passed to
BufferLayerConsumer::addReleaseFence during post composition for buffer
synchronization when releasing a buffer, so passing the same fence isn't
necessary.

For BufferStateLayers, this fence shouldn't be necessary for merging
with the buffer's acquire fence in latchBuffer, since buffer readiness
for the current buffer shouldn't depend on whether the prior buffer was
finished being used in gpu composition.

So, the fence returned by the extra glFlush call isn't necessary, so we
can just remove the call + plumbing entirely.

Bug: 117103118
Change-Id: Iafeb33dab46213f711ee2ecb59731d003263a551
Test: apct tests, go/wm-smoke, cts
Test: chrome debug apk
parent b2069eba
Loading
Loading
Loading
Loading
+2 −3
Original line number Original line Diff line number Diff line
@@ -380,8 +380,7 @@ bool BufferLayer::onPostComposition(const std::optional<DisplayId>& displayId,
    return true;
    return true;
}
}


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


    bool refreshRequired = latchSidebandStream(recomputeVisibleRegions);
    bool refreshRequired = latchSidebandStream(recomputeVisibleRegions);
@@ -420,7 +419,7 @@ bool BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
        return false;
        return false;
    }
    }


    status_t err = updateTexImage(recomputeVisibleRegions, latchTime, releaseFence);
    status_t err = updateTexImage(recomputeVisibleRegions, latchTime);
    if (err != NO_ERROR) {
    if (err != NO_ERROR) {
        return false;
        return false;
    }
    }
+2 −7
Original line number Original line Diff line number Diff line
@@ -93,11 +93,7 @@ public:
    // the visible regions need to be recomputed (this is a fairly heavy
    // the visible regions need to be recomputed (this is a fairly heavy
    // operation, so this should be set only if needed). Typically this is used
    // operation, so this should be set only if needed). Typically this is used
    // to figure out if the content or size of a surface has changed.
    // to figure out if the content or size of a surface has changed.
    // If there was a GL composition step rendering the previous frame, then
    bool latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime) override;
    // releaseFence will be populated with a native fence that fires when
    // composition has completed.
    bool latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime,
                     const sp<Fence>& releaseFence) override;


    bool isBufferLatched() const override { return mRefreshPending; }
    bool isBufferLatched() const override { return mRefreshPending; }


@@ -142,8 +138,7 @@ private:
    virtual void setFilteringEnabled(bool enabled) = 0;
    virtual void setFilteringEnabled(bool enabled) = 0;


    virtual status_t bindTextureImage() = 0;
    virtual status_t bindTextureImage() = 0;
    virtual status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime,
    virtual status_t updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) = 0;
                                    const sp<Fence>& flushFence) = 0;


    virtual status_t updateActiveBuffer() = 0;
    virtual status_t updateActiveBuffer() = 0;
    virtual status_t updateFrameNumber(nsecs_t latchTime) = 0;
    virtual status_t updateFrameNumber(nsecs_t latchTime) = 0;
+3 −42
Original line number Original line Diff line number Diff line
@@ -100,8 +100,7 @@ void BufferLayerConsumer::setContentsChangedListener(const wp<ContentsChangedLis


status_t BufferLayerConsumer::updateTexImage(BufferRejecter* rejecter, nsecs_t expectedPresentTime,
status_t BufferLayerConsumer::updateTexImage(BufferRejecter* rejecter, nsecs_t expectedPresentTime,
                                             bool* autoRefresh, bool* queuedBuffer,
                                             bool* autoRefresh, bool* queuedBuffer,
                                             uint64_t maxFrameNumber,
                                             uint64_t maxFrameNumber) {
                                             const sp<Fence>& releaseFence) {
    ATRACE_CALL();
    ATRACE_CALL();
    BLC_LOGV("updateTexImage");
    BLC_LOGV("updateTexImage");
    Mutex::Autolock lock(mMutex);
    Mutex::Autolock lock(mMutex);
@@ -146,7 +145,7 @@ status_t BufferLayerConsumer::updateTexImage(BufferRejecter* rejecter, nsecs_t e
    }
    }


    // Release the previous buffer.
    // Release the previous buffer.
    err = updateAndReleaseLocked(item, &mPendingRelease, releaseFence);
    err = updateAndReleaseLocked(item, &mPendingRelease);
    if (err != NO_ERROR) {
    if (err != NO_ERROR) {
        return err;
        return err;
    }
    }
@@ -224,25 +223,11 @@ status_t BufferLayerConsumer::acquireBufferLocked(BufferItem* item, nsecs_t pres
}
}


status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
                                                     PendingRelease* pendingRelease,
                                                     PendingRelease* pendingRelease) {
                                                     const sp<Fence>& releaseFence) {
    status_t err = NO_ERROR;
    status_t err = NO_ERROR;


    int slot = item.mSlot;
    int slot = item.mSlot;


    // Do whatever sync ops we need to do before releasing the old slot.
    if (slot != mCurrentTexture) {
        err = syncForReleaseLocked(releaseFence);
        if (err != NO_ERROR) {
            // Release the buffer we just acquired.  It's not safe to
            // release the old buffer, so instead we just drop the new frame.
            // As we are still under lock since acquireBuffer, it is safe to
            // release by slot.
            releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
            return err;
        }
    }

    BLC_LOGV("updateAndRelease: (slot=%d buf=%p) -> (slot=%d buf=%p)", mCurrentTexture,
    BLC_LOGV("updateAndRelease: (slot=%d buf=%p) -> (slot=%d buf=%p)", mCurrentTexture,
             mCurrentTextureBuffer != nullptr ? mCurrentTextureBuffer->handle : 0, slot,
             mCurrentTextureBuffer != nullptr ? mCurrentTextureBuffer->handle : 0, slot,
             mSlots[slot].mGraphicBuffer->handle);
             mSlots[slot].mGraphicBuffer->handle);
@@ -298,30 +283,6 @@ status_t BufferLayerConsumer::bindTextureImageLocked() {
    return mRE.bindExternalTextureBuffer(mTexName, mCurrentTextureBuffer, mCurrentFence, false);
    return mRE.bindExternalTextureBuffer(mTexName, mCurrentTextureBuffer, mCurrentFence, false);
}
}


status_t BufferLayerConsumer::syncForReleaseLocked(const sp<Fence>& releaseFence) {
    BLC_LOGV("syncForReleaseLocked");

    if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
        if (mRE.useNativeFenceSync() && releaseFence != Fence::NO_FENCE) {
            // TODO(alecmouri): fail further upstream if the fence is invalid
            if (!releaseFence->isValid()) {
                BLC_LOGE("syncForReleaseLocked: failed to flush RenderEngine");
                return UNKNOWN_ERROR;
            }
            status_t err =
                    addReleaseFenceLocked(mCurrentTexture, mCurrentTextureBuffer, releaseFence);
            if (err != OK) {
                BLC_LOGE("syncForReleaseLocked: error adding release fence: "
                         "%s (%d)",
                         strerror(-err), err);
                return err;
            }
        }
    }

    return OK;
}

void BufferLayerConsumer::getTransformMatrix(float mtx[16]) {
void BufferLayerConsumer::getTransformMatrix(float mtx[16]) {
    Mutex::Autolock lock(mMutex);
    Mutex::Autolock lock(mMutex);
    memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix));
    memcpy(mtx, mCurrentTransformMatrix, sizeof(mCurrentTransformMatrix));
+2 −10
Original line number Original line Diff line number Diff line
@@ -92,8 +92,7 @@ public:
    // used to reject the newly acquired buffer.  It also does not bind the
    // used to reject the newly acquired buffer.  It also does not bind the
    // RenderEngine texture until bindTextureImage is called.
    // RenderEngine texture until bindTextureImage is called.
    status_t updateTexImage(BufferRejecter* rejecter, nsecs_t expectedPresentTime,
    status_t updateTexImage(BufferRejecter* rejecter, nsecs_t expectedPresentTime,
                            bool* autoRefresh, bool* queuedBuffer, uint64_t maxFrameNumber,
                            bool* autoRefresh, bool* queuedBuffer, uint64_t maxFrameNumber);
                            const sp<Fence>& releaseFence);


    // See BufferLayerConsumer::bindTextureImageLocked().
    // See BufferLayerConsumer::bindTextureImageLocked().
    status_t bindTextureImage();
    status_t bindTextureImage();
@@ -212,8 +211,7 @@ protected:
    // completion of the method will instead be returned to the caller, so that
    // completion of the method will instead be returned to the caller, so that
    // it may call releaseBufferLocked itself later.
    // it may call releaseBufferLocked itself later.
    status_t updateAndReleaseLocked(const BufferItem& item,
    status_t updateAndReleaseLocked(const BufferItem& item,
                                    PendingRelease* pendingRelease = nullptr,
                                    PendingRelease* pendingRelease = nullptr);
                                    const sp<Fence>& releaseFence = Fence::NO_FENCE);


    // Binds mTexName and the current buffer to TEXTURE_EXTERNAL target.
    // Binds mTexName and the current buffer to TEXTURE_EXTERNAL target.
    // If the bind succeeds, this calls doFenceWait.
    // If the bind succeeds, this calls doFenceWait.
@@ -244,12 +242,6 @@ private:
    // access the current texture buffer.
    // access the current texture buffer.
    status_t doFenceWaitLocked() const;
    status_t doFenceWaitLocked() const;


    // syncForReleaseLocked performs the synchronization needed to release the
    // current slot from RenderEngine.  If needed it will set the current
    // slot's fence to guard against a producer accessing the buffer before
    // the outstanding accesses have completed.
    status_t syncForReleaseLocked(const sp<Fence>& releaseFence);

    // The default consumer usage flags that BufferLayerConsumer always sets on its
    // The default consumer usage flags that BufferLayerConsumer always sets on its
    // BufferQueue instance; these will be OR:d with any additional flags passed
    // BufferQueue instance; these will be OR:d with any additional flags passed
    // from the BufferLayerConsumer user. In particular, BufferLayerConsumer will always
    // from the BufferLayerConsumer user. In particular, BufferLayerConsumer will always
+4 −6
Original line number Original line Diff line number Diff line
@@ -225,8 +225,7 @@ status_t BufferQueueLayer::bindTextureImage() {
    return mConsumer->bindTextureImage();
    return mConsumer->bindTextureImage();
}
}


status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime,
status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) {
                                          const sp<Fence>& releaseFence) {
    // This boolean is used to make sure that SurfaceFlinger's shadow copy
    // This boolean is used to make sure that SurfaceFlinger's shadow copy
    // of the buffer queue isn't modified when the buffer queue is returning
    // of the buffer queue isn't modified when the buffer queue is returning
    // BufferItem's that weren't actually queued. This can happen in shared
    // BufferItem's that weren't actually queued. This can happen in shared
@@ -264,9 +263,8 @@ status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t
    const uint64_t maxFrameNumberToAcquire =
    const uint64_t maxFrameNumberToAcquire =
            std::min(mLastFrameNumberReceived.load(), lastSignaledFrameNumber);
            std::min(mLastFrameNumberReceived.load(), lastSignaledFrameNumber);


    status_t updateResult =
    status_t updateResult = mConsumer->updateTexImage(&r, expectedPresentTime, &mAutoRefresh,
            mConsumer->updateTexImage(&r, expectedPresentTime, &mAutoRefresh, &queuedBuffer,
                                                      &queuedBuffer, maxFrameNumberToAcquire);
                                      maxFrameNumberToAcquire, releaseFence);
    if (updateResult == BufferQueue::PRESENT_LATER) {
    if (updateResult == BufferQueue::PRESENT_LATER) {
        // Producer doesn't want buffer to be displayed yet.  Signal a
        // Producer doesn't want buffer to be displayed yet.  Signal a
        // layer update so we check again at the next opportunity.
        // layer update so we check again at the next opportunity.
@@ -393,7 +391,7 @@ void BufferQueueLayer::setHwcLayerBuffer(const sp<const DisplayDevice>& display)
void BufferQueueLayer::fakeVsync() {
void BufferQueueLayer::fakeVsync() {
    mRefreshPending = false;
    mRefreshPending = false;
    bool ignored = false;
    bool ignored = false;
    latchBuffer(ignored, systemTime(), Fence::NO_FENCE);
    latchBuffer(ignored, systemTime());
    usleep(16000);
    usleep(16000);
    releasePendingBuffer(systemTime());
    releasePendingBuffer(systemTime());
}
}
Loading