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

Commit 5d689bd0 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira
Browse files

SurfaceTexture: dequeueBuffer hack for older EGL blobs

If MISSING_GRALLOC_BUFFERS is defined (i.e., we're already hacking
around the lack of native buffers), allow retrying buffer dequeues
when the operation returns an error.
Based on work by "rapmv78" at xda-developers
(http://forum.xda-developers.com/showpost.php?p=20342919&postcount=1)

Change-Id: I2b672aabc8b2bf7b76d11c9a8e4bd65f0b4a40cf
parent bec96948
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -293,6 +293,9 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
        int foundSync = -1;
        int dequeuedCount = 0;
        bool tryAgain = true;
#ifdef MISSING_GRALLOC_BUFFERS
        int dequeueRetries = 5;
#endif
        while (tryAgain) {
            if (mAbandoned) {
                ST_LOGE("dequeueBuffer: SurfaceTexture has been abandoned!");
@@ -382,8 +385,22 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
            // clients are not allowed to dequeue more than one buffer
            // if they didn't set a buffer count.
            if (!mClientBufferCount && dequeuedCount) {
#ifdef MISSING_GRALLOC_BUFFERS
                if (--dequeueRetries) {
                    LOGD("SurfaceTexture::dequeue: Not allowed to dequeue more "
                            "than a buffer SLEEPING\n");
                    usleep(10000);
                } else {
                    mClientBufferCount = mServerBufferCount;
                    LOGD("SurfaceTexture::dequeue: Not allowed to dequeue more "
                            "than a buffer RETRY mBufferCount:%d mServerBufferCount:%d\n",
                            mBufferCount, mServerBufferCount);
                }
                continue;
#else
                ST_LOGE("dequeueBuffer: can't dequeue multiple buffers without "
                        "setting the buffer count");
#endif
                return -EINVAL;
            }

@@ -396,6 +413,15 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
                // than allowed.
                const int avail = mBufferCount - (dequeuedCount+1);
                if (avail < (MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode))) {
#ifdef MISSING_GRALLOC_BUFFERS
                    if (mClientBufferCount != 0) {
                        mBufferCount++;
                        mClientBufferCount = mServerBufferCount = mBufferCount;
                        LOGD("SurfaceTexture::dequeuebuffer: MIN EXCEEDED "
                                "mBuffer:%d bumped\n", mBufferCount);
                        continue;
                    }
#endif
                    ST_LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded "
                            "(dequeued=%d)",
                            MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode),