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

Commit 321680d7 authored by Naomi Luis's avatar Naomi Luis Committed by Giulio Cervera
Browse files

SurfaceFlinger: Remove the old GraphicBuffer reference

Whenever we are allocating a new buffer, we delete the reference to
the previous buffer at that buffer slot. The newly allocated Graphic
Buffer is also added at the correct buffer slot in the
GraphicBufferAllocator.

Change-Id: Ie91e61e39b18759893c773ebda9ce7d7654d4144
parent c8e3afba
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ public:
     * the server is referencing, then all buffers are freed.
     */
    virtual void freeAllGraphicBuffersExcept(int bufIndex) = 0;

    /* Free the GraphicBuffer at the specified index */
    virtual void freeGraphicBufferAtIndex(int bufIndex) = 0;
#endif
};

+15 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ enum {
    CREATE_GRAPHIC_BUFFER = IBinder::FIRST_CALL_TRANSACTION,
#ifdef QCOM_HARDWARE
    FREE_ALL_GRAPHIC_BUFFERS_EXCEPT,
    FREE_GRAPHIC_BUFFER_AT_INDEX,
#endif
};

@@ -75,6 +76,14 @@ public:
        data.writeInt32(bufIdx);
        remote()->transact(FREE_ALL_GRAPHIC_BUFFERS_EXCEPT, data, &reply);
    }

    virtual void freeGraphicBufferAtIndex(int bufIdx) {
        Parcel data, reply;
        data.writeInterfaceToken(
                IGraphicBufferAlloc::getInterfaceDescriptor());
        data.writeInt32(bufIdx);
        remote()->transact(FREE_GRAPHIC_BUFFER_AT_INDEX, data, &reply);
    }
#endif
};

@@ -128,6 +137,12 @@ status_t BnGraphicBufferAlloc::onTransact(
            freeAllGraphicBuffersExcept(bufIdx);
            return NO_ERROR;
        } break;
        case FREE_GRAPHIC_BUFFER_AT_INDEX: {
            CHECK_INTERFACE(IGraphicBufferAlloc, data, reply);
            int bufIdx = data.readInt32();
            freeGraphicBufferAtIndex(bufIdx);
            return NO_ERROR;
        } break;
#endif
        default:
            return BBinder::onTransact(code, data, reply, flags);
+5 −0
Original line number Diff line number Diff line
@@ -506,6 +506,11 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
#endif
	   ((uint32_t(buffer->usage) & usage) != usage))
	{
#ifdef QCOM_HARDWARE
            if (buffer != NULL) {
                mGraphicBufferAlloc->freeGraphicBufferAtIndex(buf);
            }
#endif
            usage |= GraphicBuffer::USAGE_HW_TEXTURE;
            status_t error;
            sp<GraphicBuffer> graphicBuffer(
+23 −1
Original line number Diff line number Diff line
@@ -2706,7 +2706,13 @@ status_t Client::destroySurface(SurfaceID sid) {

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

#ifdef QCOM_HARDWARE
GraphicBufferAlloc::GraphicBufferAlloc() {
    mFreedIndex = -1;
}
#else
GraphicBufferAlloc::GraphicBufferAlloc() {}
#endif

GraphicBufferAlloc::~GraphicBufferAlloc() {}

@@ -2726,7 +2732,12 @@ sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h
    }
#ifdef QCOM_HARDWARE
    Mutex::Autolock _l(mLock);
    if (-1 != mFreedIndex) {
        mBuffers.insertAt(graphicBuffer, mFreedIndex);
        mFreedIndex = -1;
    } else {
        mBuffers.add(graphicBuffer);
    }
#endif
    return graphicBuffer;
}
@@ -2741,6 +2752,17 @@ void GraphicBufferAlloc::freeAllGraphicBuffersExcept(int bufIdx) {
    } else {
        mBuffers.clear();
    }
    mFreedIndex = -1;
}

void GraphicBufferAlloc::freeGraphicBufferAtIndex(int bufIdx) {
     Mutex::Autolock _l(mLock);
     if (0 <= bufIdx && bufIdx < mBuffers.size()) {
        mBuffers.removeItemsAt(bufIdx);
        mFreedIndex = bufIdx;
     } else {
        mFreedIndex = -1;
     }
}
#endif
// ---------------------------------------------------------------------------
+2 −0
Original line number Diff line number Diff line
@@ -99,9 +99,11 @@ public:
        PixelFormat format, uint32_t usage, status_t* error);
#ifdef QCOM_HARDWARE
    virtual void freeAllGraphicBuffersExcept(int bufIdx);
    virtual void freeGraphicBufferAtIndex(int bufIdx);
private:
    Vector<sp<GraphicBuffer> > mBuffers;
    Mutex mLock;
    int mFreedIndex;
#endif
};