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

Commit 6aff69be authored by Chia-I Wu's avatar Chia-I Wu
Browse files

surfaceflinger: remove BufferLayerConsumer::mUseFenceSync

BufferLayerConsumer::mUseFenceSync is always false.  As a result, we
can remove EGLSyncKHR from EglSlot and PendingRelease.

Test: boots
Change-Id: I0fec2137a6548335303e990232637b2da00fa3c6
parent c91077c9
Loading
Loading
Loading
Loading
+5 −51
Original line number Diff line number Diff line
@@ -106,8 +106,7 @@ static bool isEglImageCroppable(const Rect& crop) {
}

BufferLayerConsumer::BufferLayerConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t tex,
                                         uint32_t texTarget, bool useFenceSync,
                                         bool isControlledByApp)
                                         uint32_t texTarget, bool isControlledByApp)
      : ConsumerBase(bq, isControlledByApp),
        mCurrentCrop(Rect::EMPTY_RECT),
        mCurrentTransform(0),
@@ -120,7 +119,6 @@ BufferLayerConsumer::BufferLayerConsumer(const sp<IGraphicBufferConsumer>& bq, u
        mDefaultHeight(1),
        mFilteringEnabled(true),
        mTexName(tex),
        mUseFenceSync(useFenceSync),
        mTexTarget(texTarget),
        mEglDisplay(EGL_NO_DISPLAY),
        mEglContext(EGL_NO_CONTEXT),
@@ -207,17 +205,6 @@ status_t BufferLayerConsumer::acquireBufferLocked(BufferItem* item, nsecs_t pres
    return NO_ERROR;
}

status_t BufferLayerConsumer::releaseBufferLocked(int buf, sp<GraphicBuffer> graphicBuffer,
                                                  EGLDisplay display, EGLSyncKHR eglFence) {
    // release the buffer if it hasn't already been discarded by the
    // BufferQueue. This can happen, for example, when the producer of this
    // buffer has reallocated the original buffer slot after this buffer
    // was acquired.
    status_t err = ConsumerBase::releaseBufferLocked(buf, graphicBuffer, display, eglFence);
    mEglSlots[buf].mEglFence = EGL_NO_SYNC_KHR;
    return err;
}

status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
                                                     PendingRelease* pendingRelease) {
    status_t err = NO_ERROR;
@@ -227,7 +214,7 @@ status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
    // Confirm state.
    err = checkAndUpdateEglStateLocked();
    if (err != NO_ERROR) {
        releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer, mEglDisplay, EGL_NO_SYNC_KHR);
        releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
        return err;
    }

@@ -240,7 +227,7 @@ status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
    if (err != NO_ERROR) {
        BLC_LOGW("updateAndRelease: unable to createImage on display=%p slot=%d", mEglDisplay,
                 slot);
        releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer, mEglDisplay, EGL_NO_SYNC_KHR);
        releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
        return UNKNOWN_ERROR;
    }

@@ -252,7 +239,7 @@ status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
            // 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, mEglDisplay, EGL_NO_SYNC_KHR);
            releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
            return err;
        }
    }
@@ -270,8 +257,7 @@ status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
    if (mCurrentTexture != BufferQueue::INVALID_BUFFER_SLOT) {
        if (pendingRelease == nullptr) {
            status_t status =
                    releaseBufferLocked(mCurrentTexture, mCurrentTextureImage->graphicBuffer(),
                                        mEglDisplay, mEglSlots[mCurrentTexture].mEglFence);
                    releaseBufferLocked(mCurrentTexture, mCurrentTextureImage->graphicBuffer());
            if (status < NO_ERROR) {
                BLC_LOGE("updateAndRelease: failed to release buffer: %s (%d)", strerror(-status),
                         status);
@@ -281,8 +267,6 @@ status_t BufferLayerConsumer::updateAndReleaseLocked(const BufferItem& item,
        } else {
            pendingRelease->currentTexture = mCurrentTexture;
            pendingRelease->graphicBuffer = mCurrentTextureImage->graphicBuffer();
            pendingRelease->display = mEglDisplay;
            pendingRelease->fence = mEglSlots[mCurrentTexture].mEglFence;
            pendingRelease->isPending = true;
        }
    }
@@ -397,36 +381,6 @@ status_t BufferLayerConsumer::syncForReleaseLocked(EGLDisplay dpy) {
                         strerror(-err), err);
                return err;
            }
        } else if (mUseFenceSync && SyncFeatures::getInstance().useFenceSync()) {
            EGLSyncKHR fence = mEglSlots[mCurrentTexture].mEglFence;
            if (fence != EGL_NO_SYNC_KHR) {
                // There is already a fence for the current slot.  We need to
                // wait on that before replacing it with another fence to
                // ensure that all outstanding buffer accesses have completed
                // before the producer accesses it.
                EGLint result = eglClientWaitSyncKHR(dpy, fence, 0, 1000000000);
                if (result == EGL_FALSE) {
                    BLC_LOGE("syncForReleaseLocked: error waiting for previous "
                             "fence: %#x",
                             eglGetError());
                    return UNKNOWN_ERROR;
                } else if (result == EGL_TIMEOUT_EXPIRED_KHR) {
                    BLC_LOGE("syncForReleaseLocked: timeout waiting for previous "
                             "fence");
                    return TIMED_OUT;
                }
                eglDestroySyncKHR(dpy, fence);
            }

            // Create a fence for the outstanding accesses in the current
            // OpenGL ES context.
            fence = eglCreateSyncKHR(dpy, EGL_SYNC_FENCE_KHR, NULL);
            if (fence == EGL_NO_SYNC_KHR) {
                BLC_LOGE("syncForReleaseLocked: error creating fence: %#x", eglGetError());
                return UNKNOWN_ERROR;
            }
            glFlush();
            mEglSlots[mCurrentTexture].mEglFence = fence;
        }
    }

+3 −36
Original line number Diff line number Diff line
@@ -60,11 +60,9 @@ public:
    // The tex parameter indicates the name of the OpenGL ES
    // texture to which images are to be streamed. texTarget specifies the
    // OpenGL ES texture target to which the texture will be bound in
    // updateTexImage. useFenceSync specifies whether fences should be used to
    // synchronize access to buffers if that behavior is enabled at
    // compile-time.
    // updateTexImage.
    BufferLayerConsumer(const sp<IGraphicBufferConsumer>& bq, uint32_t tex, uint32_t texureTarget,
                        bool useFenceSync, bool isControlledByApp);
                        bool isControlledByApp);

    // updateTexImage acquires the most recently queued buffer, and sets the
    // image contents of the target texture to it.
@@ -188,29 +186,12 @@ protected:
    virtual status_t acquireBufferLocked(BufferItem* item, nsecs_t presentWhen,
                                         uint64_t maxFrameNumber = 0) override;

    // releaseBufferLocked overrides the ConsumerBase method to update the
    // mEglSlots array in addition to the ConsumerBase.
    virtual status_t releaseBufferLocked(int slot, const sp<GraphicBuffer> graphicBuffer,
                                         EGLDisplay display, EGLSyncKHR eglFence) override;

    status_t releaseBufferLocked(int slot, const sp<GraphicBuffer> graphicBuffer,
                                 EGLSyncKHR eglFence) {
        return releaseBufferLocked(slot, graphicBuffer, mEglDisplay, eglFence);
    }

    struct PendingRelease {
        PendingRelease()
              : isPending(false),
                currentTexture(-1),
                graphicBuffer(),
                display(nullptr),
                fence(nullptr) {}
        PendingRelease() : isPending(false), currentTexture(-1), graphicBuffer() {}

        bool isPending;
        int currentTexture;
        sp<GraphicBuffer> graphicBuffer;
        EGLDisplay display;
        EGLSyncKHR fence;
    };

    // This releases the buffer in the slot referenced by mCurrentTexture,
@@ -364,12 +345,6 @@ private:
    // be bound when updateTexImage is called. It is set at construction time.
    const uint32_t mTexName;

    // mUseFenceSync indicates whether creation of the EGL_KHR_fence_sync
    // extension should be used to prevent buffers from being dequeued before
    // it's safe for them to be written. It gets set at construction time and
    // never changes.
    const bool mUseFenceSync;

    // mTexTarget is the GL texture target with which the GL texture object is
    // associated.  It is set in the constructor and never changed.  It is
    // almost always GL_TEXTURE_EXTERNAL_OES except for one use case in Android
@@ -382,16 +357,8 @@ private:
    // EGLSlot contains the information and object references that
    // BufferLayerConsumer maintains about a BufferQueue buffer slot.
    struct EglSlot {
        EglSlot() : mEglFence(EGL_NO_SYNC_KHR) {}

        // mEglImage is the EGLImage created from mGraphicBuffer.
        sp<EglImage> mEglImage;

        // mFence is the EGL sync object that must signal before the buffer
        // associated with this buffer slot may be dequeued. It is initialized
        // to EGL_NO_SYNC_KHR when the buffer is created and (optionally, based
        // on a compile-time option) set to a new sync object in updateTexImage.
        EGLSyncKHR mEglFence;
    };

    // mEglDisplay is the EGLDisplay with which this BufferLayerConsumer is currently
+2 −3
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ status_t SurfaceFlingerConsumer::updateTexImage(BufferRejecter* rejecter,
    // reject buffers which have the wrong size
    int slot = item.mSlot;
    if (rejecter && rejecter->reject(mSlots[slot].mGraphicBuffer, item)) {
        releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer, EGL_NO_SYNC_KHR);
        releaseBufferLocked(slot, mSlots[slot].mGraphicBuffer);
        return BUFFER_REJECTED;
    }

@@ -212,8 +212,7 @@ bool SurfaceFlingerConsumer::releasePendingBuffer()
    ALOGV("Releasing pending buffer");
    Mutex::Autolock lock(mMutex);
    status_t result = releaseBufferLocked(mPendingRelease.currentTexture,
            mPendingRelease.graphicBuffer, mPendingRelease.display,
            mPendingRelease.fence);
            mPendingRelease.graphicBuffer);
    ALOGE_IF(result < NO_ERROR, "releasePendingBuffer failed: %s (%d)",
            strerror(-result), result);
    mPendingRelease = PendingRelease();
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public:

    SurfaceFlingerConsumer(const sp<IGraphicBufferConsumer>& consumer,
            uint32_t tex, Layer* layer)
        : BufferLayerConsumer(consumer, tex, BufferLayerConsumer::TEXTURE_EXTERNAL, false, false),
        : BufferLayerConsumer(consumer, tex, BufferLayerConsumer::TEXTURE_EXTERNAL, false),
          mTransformToDisplayInverse(false), mSurfaceDamage(), mLayer(layer)
    {}