From d53e052322c658ce7c67b046caaeee4babc0a657 Mon Sep 17 00:00:00 2001 From: Riley Andrews Date: Mon, 18 Aug 2014 16:57:11 -0700 Subject: [PATCH] Within CpuConsumer, use gralloc lockAsync/unlockAsync Change-Id: I6b2cd195e111c3c7bf94c8052af4db92e09649a5 --- libs/gui/CpuConsumer.cpp | 87 ++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/libs/gui/CpuConsumer.cpp b/libs/gui/CpuConsumer.cpp index bff55d1b0..cefd7f1f5 100644 --- a/libs/gui/CpuConsumer.cpp +++ b/libs/gui/CpuConsumer.cpp @@ -93,41 +93,62 @@ status_t CpuConsumer::lockNextBuffer(LockedBuffer *nativeBuffer) { int buf = b.mBuf; - if (b.mFence.get()) { - err = b.mFence->waitForever("CpuConsumer::lockNextBuffer"); - if (err != OK) { - CC_LOGE("Failed to wait for fence of acquired buffer: %s (%d)", - strerror(-err), err); - return err; - } - } - void *bufferPointer = NULL; android_ycbcr ycbcr = android_ycbcr(); - if (mSlots[buf].mGraphicBuffer->getPixelFormat() == - HAL_PIXEL_FORMAT_YCbCr_420_888) { - err = mSlots[buf].mGraphicBuffer->lockYCbCr( - GraphicBuffer::USAGE_SW_READ_OFTEN, - b.mCrop, - &ycbcr); + if (b.mFence.get()) { + if (mSlots[buf].mGraphicBuffer->getPixelFormat() == + HAL_PIXEL_FORMAT_YCbCr_420_888) { + err = mSlots[buf].mGraphicBuffer->lockAsyncYCbCr( + GraphicBuffer::USAGE_SW_READ_OFTEN, + b.mCrop, + &ycbcr, + b.mFence->dup()); - if (err != OK) { - CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)", - strerror(-err), err); - return err; + if (err != OK) { + CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)", + strerror(-err), err); + return err; + } + bufferPointer = ycbcr.y; + } else { + err = mSlots[buf].mGraphicBuffer->lockAsync( + GraphicBuffer::USAGE_SW_READ_OFTEN, + b.mCrop, + &bufferPointer, + b.mFence->dup()); + + if (err != OK) { + CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)", + strerror(-err), err); + return err; + } } - bufferPointer = ycbcr.y; } else { - err = mSlots[buf].mGraphicBuffer->lock( - GraphicBuffer::USAGE_SW_READ_OFTEN, - b.mCrop, - &bufferPointer); + if (mSlots[buf].mGraphicBuffer->getPixelFormat() == + HAL_PIXEL_FORMAT_YCbCr_420_888) { + err = mSlots[buf].mGraphicBuffer->lockYCbCr( + GraphicBuffer::USAGE_SW_READ_OFTEN, + b.mCrop, + &ycbcr); - if (err != OK) { - CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)", - strerror(-err), err); - return err; + if (err != OK) { + CC_LOGE("Unable to lock YCbCr buffer for CPU reading: %s (%d)", + strerror(-err), err); + return err; + } + bufferPointer = ycbcr.y; + } else { + err = mSlots[buf].mGraphicBuffer->lock( + GraphicBuffer::USAGE_SW_READ_OFTEN, + b.mCrop, + &bufferPointer); + + if (err != OK) { + CC_LOGE("Unable to lock buffer for CPU reading: %s (%d)", + strerror(-err), err); + return err; + } } } @@ -189,14 +210,22 @@ status_t CpuConsumer::unlockBuffer(const LockedBuffer &nativeBuffer) { status_t CpuConsumer::releaseAcquiredBufferLocked(int lockedIdx) { status_t err; + int fd = -1; - err = mAcquiredBuffers[lockedIdx].mGraphicBuffer->unlock(); + err = mAcquiredBuffers[lockedIdx].mGraphicBuffer->unlockAsync(&fd); if (err != OK) { CC_LOGE("%s: Unable to unlock graphic buffer %d", __FUNCTION__, lockedIdx); return err; } int buf = mAcquiredBuffers[lockedIdx].mSlot; + if (CC_LIKELY(fd != -1)) { + sp fence(new Fence(fd)); + addReleaseFenceLocked( + mAcquiredBuffers[lockedIdx].mSlot, + mSlots[buf].mGraphicBuffer, + fence); + } // release the buffer if it hasn't already been freed by the BufferQueue. // This can happen, for example, when the producer of this buffer